Ejemplo n.º 1
0
    def show_errors(self):
        """
        Show all errors.
        """
        errors_to_show = []

        # get select and ignore settings
        select = settings.get('select') or []
        ignore = settings.get('ignore') or []

        errors_list_filtered = []
        for e in self.errors_list:
            # get error line
            line = self.view.full_line(self.view.text_point(e[0] - 1, 0))
            line_text = self.view.substr(line).strip()

            # skip line if 'noqa' defined
            if skip_line(line_text):
                continue

            # parse error line to get error code
            code, _ = e[2].split(' ', 1)

            # check if user has a setting for select only errors to show
            if select and filter(lambda err: not code.startswith(err), select):
                continue

            # check if user has a setting for ignore some errors
            if ignore and filter(lambda err: code.startswith(err), ignore):
                continue

            # build line error message
            error = [e[2], u'{0}: {1}'.format(e[0], line_text)]
            if error not in errors_to_show:
                errors_list_filtered.append(e)
                errors_to_show.append(
                    [e[2], u'{0}: {1}'.format(e[0], line_text)]
                )

        # renew errors list with selected and ignored errors
        self.errors_list = errors_list_filtered

        # view errors window
        self.view.window().show_quick_panel(errors_to_show,
                                            self.error_selected)
Ejemplo n.º 2
0
    def show_errors(self):
        """
        Show all errors.
        """
        errors_to_show = []

        # get select and ignore settings
        select = settings.get("select") or []
        ignore = settings.get("ignore") or []
        is_highlight = settings.get("highlight", False)
        is_popup = settings.get("popup", True)

        regions = []
        view_errors = {}
        errors_list_filtered = []

        for e in self.errors_list:
            current_line = e[0] - 1
            error_text = e[2]

            # get error line
            text_point = self.view.text_point(current_line, 0)
            line = self.view.full_line(text_point)
            full_line_text = self.view.substr(line)
            line_text = full_line_text.strip()

            # skip line if 'noqa' defined
            if skip_line(line_text):
                continue

            # parse error line to get error code
            code, _ = error_text.split(" ", 1)

            # check if user has a setting for select only errors to show
            if select and filter(lambda err: not code.startswith(err), select):
                continue

            # check if user has a setting for ignore some errors
            if ignore and filter(lambda err: code.startswith(err), ignore):
                continue

            # build error text
            error = [error_text, u"{0}: {1}".format(current_line + 1, line_text)]
            # skip if this error is already found (with pep8 or flake8)
            if error in errors_to_show:
                continue
            errors_to_show.append(error)

            # build line error message
            if is_popup:
                errors_list_filtered.append(e)

            # prepare errors regions
            if is_highlight:
                # prepare line
                line_text = full_line_text.rstrip("\r\n")
                line_length = len(line_text)

                # calculate error highlight start and end positions
                start = text_point + line_length - len(line_text.lstrip())
                end = text_point + line_length

                # small tricks
                if code == "E501":
                    # too long lines: highlight only the rest of line
                    start = text_point + e[1]
                # TODO: add another tricks like 'E303 too many blank lines'

                regions.append(sublime.Region(start, end))

            # save errors for each line in view to special dict
            view_errors.setdefault(current_line, []).append(error_text)

        # renew errors list with selected and ignored errors
        self.errors_list = errors_list_filtered
        # save errors dict
        ERRORS_IN_VIEWS[self.view.id()] = view_errors

        # highlight error regions if defined
        if is_highlight:
            self.view.add_regions("flake8-errors", regions, "invalid.deprecated", "", sublime.DRAW_OUTLINED)

        if is_popup:
            # view errors window
            self.view.window().show_quick_panel(errors_to_show, self.error_selected)
Ejemplo n.º 3
0
    def show_errors(self):
        """
        Show all errors.
        """
        errors_to_show = []

        # get select and ignore settings
        select = settings.get('select') or []
        ignore = settings.get('ignore') or []
        is_highlight = settings.get('highlight', False)
        is_popup = settings.get('popup', True)

        regions = []
        view_errors = {}
        errors_list_filtered = []

        for e in self.errors_list:
            current_line = e[0] - 1
            error_text = e[2]

            # get error line
            text_point = self.view.text_point(current_line, 0)
            line = self.view.full_line(text_point)
            full_line_text = self.view.substr(line)
            line_text = full_line_text.strip()

            # skip line if 'noqa' defined
            if skip_line(line_text):
                continue

            # parse error line to get error code
            code, _ = error_text.split(' ', 1)

            # check if user has a setting for select only errors to show
            if select and filter(lambda err: not code.startswith(err), select):
                continue

            # check if user has a setting for ignore some errors
            if ignore and filter(lambda err: code.startswith(err), ignore):
                continue

            # build error text
            error = [error_text, u'{0}: {1}'.format(current_line + 1,
                                                    line_text)]
            # skip if this error is already found (with pep8 or flake8)
            if error in errors_to_show:
                continue
            errors_to_show.append(error)

            # build line error message
            if is_popup:
                errors_list_filtered.append(e)

            # prepare errors regions
            if is_highlight:
                # prepare line
                line_text = full_line_text.rstrip('\r\n')
                line_length = len(line_text)

                # calculate error highlight start and end positions
                start = text_point + line_length - len(line_text.lstrip())
                end = text_point + line_length

                # small tricks
                if code == 'E501':
                    # too long lines: highlight only the rest of line
                    start = text_point + e[1]
                # TODO: add another tricks like 'E303 too many blank lines'

                regions.append(sublime.Region(start, end))

            # save errors for each line in view to special dict
            view_errors.setdefault(current_line, []).append(error_text)

        # renew errors list with selected and ignored errors
        self.errors_list = errors_list_filtered
        # save errors dict
        ERRORS_IN_VIEWS[self.view.id()] = view_errors

        # highlight error regions if defined
        if is_highlight:
            self.view.add_regions('flake8-errors', regions,
                                  'invalid.deprecated', '',
                                  sublime.DRAW_OUTLINED)

        if is_popup:
            # view errors window
            self.view.window().show_quick_panel(errors_to_show,
                                                self.error_selected)
Ejemplo n.º 4
0
    def show_errors(self):
        """
        Show all errors.
        """
        errors_to_show = []

        # get select and ignore settings
        select = settings.get('select') or []
        ignore = settings.get('ignore') or []

        errors = []
        warnings = []
        viewStorage = viewToRegionToErrors[self.view.id()] = {}

        errors_list_filtered = []
        for e in self.errors_list:
            # get error line
            text_point = self.view.text_point(e[0] - 1, e[1] + 1)
            line_text = self.view.substr(self.view.line(text_point))

            # skip line if 'noqa' defined
            if skip_line(line_text):
                continue

            # parse error line to get error code
            code, _ = e[2].split(' ', 1)

            # check if user has a setting for select only errors to show
            if select and filter(lambda err: not code.startswith(err), select):
                continue

            # check if user has a setting for ignore some errors
            if ignore and filter(lambda err: code.startswith(err), ignore):
                continue

            # build line error message
            error = [e[2], u'{0}: {1}'.format(e[0], line_text)]
            if error not in errors_to_show:
                errors_list_filtered.append(e)
                errors_to_show.append(error)

            if e[1]:
                region = self.view.word(text_point)
            else:
                region = self.view.line(text_point)
            viewStorage[region.a] = { 'error': error[0] }
            # a warning if the code is from pep8, unless the user has specified
            # it as an error.  Everything without a code (just syntax errror?)
            # are always errors
            if ((code.startswith('W') or code.startswith('E'))
                    and code not in settings.get('errors', [])):
                warnings.append(region)
            else:
                errors.append(region)

        mark = 'circle' if settings.get('gutter_marks') else ''
        style = self.FILL_STYLES.get(
                settings.get('highlight_style')) or self.FILL_STYLES['fill']

        if settings.get('highlight'):
            # It may not make much sense, but string is the best coloration,
            # as far as I can tell.
            self.view.add_regions('flake8_errors', errors,
                    "flake8lint.error", mark, style)
            # add_regions called in rapid succession can cause issues.
            time.sleep(0.01)
            self.view.add_regions('flake8_warnings', warnings,
                "flake8lint.warning", mark, style)


        # renew errors list with selected and ignored errors
        self.errors_list = errors_list_filtered

        if settings.get('popup'):
            # view errors window
            self.view.window().show_quick_panel(errors_to_show,
                                                self.error_selected)

        if settings.get('results_pane'):
            resultsPane = self._getResultsPane()
            
            edit = resultsPane.begin_edit()
            try:
                resultsPane.erase(edit, sublime.Region(0, resultsPane.size()))
                problems = sorted(errors + warnings, key = lambda r: r.begin())
                resultsPane.insert(edit, 0, self.view.file_name() + ':')
                resultsPane.insert(edit, resultsPane.size(), '\n')
                resultsPane.insert(edit, resultsPane.size(), '\n')
                for problem in problems:
                    line = self.view.line(problem.begin())
                    lineNumber, col = self.view.rowcol(problem.begin())
                    messages = getMessage(self.view, line)
                    resultsPane.insert(edit, resultsPane.size(), 
                            self._formatMessage(lineNumber, 
                                self.view.substr(line), messages))

                if not problems:
                    resultsPane.insert(edit, resultsPane.size(), 
                        '--    pass    --')
            finally:
                resultsPane.end_edit(edit)