Exemplo n.º 1
0
class ErrorMarker(object):

    def __init__(self, window, error_report, settings):
        self._error_report = error_report
        self._highlighter = CodeHighlighter(settings, self._current_error_in_view)
        self._window = window
        settings.add_on_change(self.mark_errors)

    @delayed(0)
    def mark_errors(self):
        for view in self._window.views():
            errors = self._error_report.sorted_errors_in(view.file_name())
            self._mark_errors_in_view(view, errors)

    @delayed(0)
    def mark_errors_in(self, filename):
        errors = self._error_report.sorted_errors_in(filename)
        for view in self._file_views(filename):
            self._mark_errors_in_view(view, errors)

    @delayed(0)
    def hide_errors_in(self, filename):
        for view in self._file_views(filename):
            self._highlighter.clear(view)

    @delayed(0)
    def mark_error(self, error):
        for view in self._file_views(error.filename):
            self._highlighter.highlight(view, [error])

    @delayed(0)
    def clear(self):
        for view in self._window.views():
            self._highlighter.clear(view)

    @delayed(0)
    def update_status(self):
        self.update_status_now()

    def update_status_now(self):
        for view in maybe(self._window.active_view()):
            self._highlighter.set_status_message(view, self._status_message(view))

    def _mark_errors_in_view(self, view, errors):
        if errors and not view.is_dirty():
            self._highlighter.highlight(view, errors, replace=True)
        else:
            self._highlighter.clear(view)

    def _status_message(self, view):
        for errors in maybe(self._line_errors(view)):
            return '(%s)' % ')('.join([e.message for e in errors])

    def _file_views(self, filename):
        for view in self._window.views():
            if filename == view.file_name():
                yield view

    def _line_errors(self, view):
        row, _ = view.rowcol(view.sel()[0].begin())
        return self._error_report.errors_at(view.file_name(), row + 1)

    def _current_error_in_view(self, view):
        return self._error_report.current_error_in(view.file_name())
Exemplo n.º 2
0
 def _highlighter(self):
     if self.__highlighter is None:
         self.__highlighter = CodeHighlighter(self.__settings,
                                              self._current_error_in_view)
     return self.__highlighter
Exemplo n.º 3
0
 def __init__(self, window, error_report, settings):
     self._error_report = error_report
     self._highlighter = CodeHighlighter(settings, self._current_error_in_view)
     self._window = window
     settings.add_on_change(self.mark_errors)
Exemplo n.º 4
0
class ErrorMarker(object):

    def __init__(self, window, error_report, settings):
        self._error_report = error_report
        self._highlighter = CodeHighlighter(settings)
        self._window = window
        settings.add_on_change(self.mark_errors)

    @delayed(0)
    def mark_errors(self):
        for view in self._window.views():
            lines = self._error_report.error_lines_in(view.file_name())
            if lines is not None:
                self._highlighter.highlight(view, lines, replace=True)
            else:
                self._highlighter.clear(view)

    @delayed(0)
    def mark_errors_in(self, filename):
        for lines in maybe(self._error_report.error_lines_in(filename)):
            for view in self._file_views(filename):
                if view.is_dirty():
                    self._highlighter.clear(view)
                else:
                    self._highlighter.highlight(view, lines, replace=True)

    @delayed(0)
    def hide_errors_in(self, filename):
        for view in self._file_views(filename):
            self._highlighter.clear(view)

    @delayed(0)
    def mark_line(self, filename, line):
        for view in self._file_views(filename):
            self._highlighter.highlight(view, [line])

    @delayed(0)
    def clear(self):
        for view in self._window.views():
            self._highlighter.clear(view)

    @delayed(0)
    def update_status(self):
        for view in maybe(self._window.active_view()):
            error = self._line_error(self._window.active_view())
            self._highlighter.set_status_message(view, error)

    def _file_views(self, filename):
        for view in self._window.views():
            if filename == view.file_name():
                yield view

    def _line_error(self, view):
        row, _ = view.rowcol(view.sel()[0].begin())
        return self._error_report.error_at(view.file_name(), row + 1)