def check(view=None): """Perform a linter check on the view """ if view is None: view = get_current_active_view() if not get_setting('python_linting', view, True): return filename = file_or_buffer_name(view) proxy = proxy_for(view) if not proxy: return lint_settings = { 'pep8': get_setting('pep8', view, default_value=True), 'pep8_ignore': get_setting('pep8_ignore', view, default_value=[]), 'pep8_max_line_length': get_setting('pep8_max_line_length', view, default_value=None), 'pyflakes_ignore': get_setting('pyflakes_ignore', view, default_value=[]), } code = view.substr(sublime.Region(0, view.size())) encoding = view.encoding() if encoding.lower() == "undefined": encoding = "utf-8" errors = proxy.check_syntax(code, encoding, lint_settings, filename) try: errors = pickle.loads(errors.data) vid = view.id() lines = set() # leave this here for compatibility with original plugin error_underlines[vid] = [] error_messages[vid] = {} violation_underlines[vid] = [] violation_messages[vid] = {} warning_underlines[vid] = [] warning_messages[vid] = {} parse_errors(view, errors, lines, vid) # the result can be a list of errors, or single syntax exception try: _update_lint_marks(view, lines) except Exception as e: print('SublimePythonIDE: Add lint marks failed\n{0}'.format(e)) update_statusbar(view) except Exception as error: print("SublimePythonIDE: No server respose\n{0}".format(error))
def check(view=None): """Perform a linter check on the view """ if view is None: view = get_current_active_view() if not get_setting('python_linting', view, True): return filename = file_or_buffer_name(view) proxy = proxy_for(view) if not proxy: return lint_settings = { 'pep8': get_setting('pep8', view, default_value=True), 'pep8_ignore': get_setting('pep8_ignore', view, default_value=[]), 'pep8_max_line_length': get_setting( 'pep8_max_line_length', view, default_value=None), 'pyflakes_ignore': get_setting( 'pyflakes_ignore', view, default_value=[]), } code = view.substr(sublime.Region(0, view.size())) encoding = view.encoding() if encoding.lower() == "undefined": encoding = "utf-8" errors = proxy.check_syntax(code, encoding, lint_settings, filename) try: errors = pickle.loads(errors.data) vid = view.id() lines = set() # leave this here for compatibility with original plugin error_underlines[vid] = [] error_messages[vid] = {} violation_underlines[vid] = [] violation_messages[vid] = {} warning_underlines[vid] = [] warning_messages[vid] = {} parse_errors(view, errors, lines, vid) # the result can be a list of errors, or single syntax exception try: _update_lint_marks(view, lines) except Exception as e: print('SublimePythonIDE: Add lint marks failed\n{0}'.format(e)) update_statusbar(view) except Exception as error: print("SublimePythonIDE: No server respose\n{0}".format(error))
def check(self, view): """Perform a linter check on the view """ if not get_setting('python_linting', view, True): return filename = view.file_name() proxy = proxy_for(view) if not proxy: return lint_settings = { 'pep8': get_setting('pep8', view, default_value=True), 'pep8_ignore': get_setting('pep8_ignore', view, default_value=[]), 'pep8_max_line_length': get_setting('pep8_max_line_length', view, default_value=None), 'pyflakes_ignore': get_setting('pyflakes_ignore', view, default_value=[]), } errors = proxy.check_syntax( view.substr(sublime.Region(0, view.size())), lint_settings, filename) try: errors = pickle.loads(errors.data) vid = view.id() lines = set() # leave this here for compatibility with original plugin self.error_underlines[vid] = [] self.error_messages[vid] = {} self.violation_underlines[vid] = [] self.violation_messages[vid] = {} self.warning_underlines[vid] = [] self.warning_messages[vid] = {} self.parse_errors(view, errors, lines, vid) # the result can be a list of errors, or single syntax exception try: self.add_lint_marks(view, lines) except Exception as e: print('SublimePythonIDE: Add lint marks failed\n{0}'.format(e)) self.on_selection_modified_async(view) except Exception as error: print("SublimePythonIDE: No server respose\n{0}".format(error))
def check(self, view): """Perform a linter check on the view """ if not get_setting('python_linting', view, True): return filename = view.file_name() proxy = proxy_for(view) if not proxy: return lint_settings = { 'pep8': get_setting('pep8', view, default_value=True), 'pep8_ignore': get_setting('pep8_ignore', view, default_value=[]), 'pep8_max_line_length': get_setting( 'pep8_max_line_length', view, default_value=None), 'pyflakes_ignore': get_setting( 'pyflakes_ignore', view, default_value=[]), } errors = proxy.check_syntax(view.substr( sublime.Region(0, view.size())), lint_settings, filename) try: errors = pickle.loads(errors.data) vid = view.id() lines = set() # leave this here for compatibility with original plugin self.error_underlines[vid] = [] self.error_messages[vid] = {} self.violation_underlines[vid] = [] self.violation_messages[vid] = {} self.warning_underlines[vid] = [] self.warning_messages[vid] = {} self.parse_errors(view, errors, lines, vid) # the result can be a list of errors, or single syntax exception try: self.add_lint_marks(view, lines) except Exception as e: print('SublimePythonIDE: Add lint marks failed\n{0}'.format(e)) self.on_selection_modified_async(view) except Exception as error: print("SublimePythonIDE: No server respose\n{0}".format(error))
def add_lint_marks(self, view, lines): """Adds lint marks to view on the given lines. """ style = get_setting('python_linter_mark_style', view, 'outline') outline_style = {'none': sublime.HIDDEN} self._erase_lint_marks(view) for name, underlines in self._get_types(view).items(): if len(underlines) > 0: view.add_regions( 'lint-underline-{name}'.format(name=name), underlines, 'python_linter.underline.{name}'.format(name=name), flags=sublime.DRAW_EMPTY_AS_OVERWRITE ) if len(lines) > 0: outlines = self._get_outlines(view) for lint_type, lints in outlines.items(): args = [ 'lint-outlines-{0}'.format(lint_type), outlines[lint_type], 'python_linter.outline.{0}'.format(lint_type), self._get_gutter_mark_theme(view, lint_type), outline_style.get(style, sublime.DRAW_OUTLINED) ] view.add_regions(*args)
def _update_lint_marks(view, lines): """Update lint marks to view on the given lines. """ style = get_setting('python_linter_mark_style', view, 'outline') outline_style = {'none': sublime.HIDDEN} _erase_lint_marks(view) for name, underlines in _get_types(view).items(): if len(underlines) > 0: view.add_regions( 'lint-underline-{name}'.format(name=name), underlines, 'python_linter.underline.{name}'.format(name=name), flags=sublime.DRAW_EMPTY_AS_OVERWRITE) if len(lines) > 0: outlines = _get_outlines(view) for lint_type, lints in outlines.items(): args = [ 'lint-outlines-{0}'.format(lint_type), outlines[lint_type], 'python_linter.outline.{0}'.format(lint_type), _get_gutter_mark_theme(view, lint_type), outline_style.get(style, sublime.DRAW_OUTLINED) ] view.add_regions(*args)
def _get_gutter_mark_theme(view, lint_type): """Return the right gutter mark theme icons """ image = '' if get_setting('python_linter_gutter_marks', view, True): theme = get_setting('python_linter_gutter_marks_theme', view, 'simple') image = '{0}-{1}.png'.format(theme, lint_type) if theme == 'original': image = ORIGINAL_MARK_THEME[lint_type] elif theme in MARK_THEMES: # this API does not expect OS-specific paths, but only forward-slashes image = MARK_THEMES_PATH + '/' + '{0}-{1}.png'.format( theme, lint_type) return image
def _get_gutter_mark_theme(self, view, lint_type): """Return the right gutter mark theme icons """ image = '' if get_setting('python_linter_gutter_marks', view, True): theme = get_setting( 'python_linter_gutter_marks_theme', view, 'simple' ) image = '{0}-{1}.png'.format(theme, lint_type) if theme == 'original': image = self.ORIGINAL_MARK_THEME[lint_type] elif theme in self.MARK_THEMES: # this API does not expect OS-specific paths, but only forward-slashes image = self.MARK_THEMES_PATH + '/' + '{0}-{1}.png'.format( theme, lint_type) return image
def update_statusbar(view): """Updates the view status bar """ if (_is_python_syntax(view) and get_setting('python_linting', view, True)): lineno = view.rowcol(view.sel()[0].end())[0] + 0 errors_msg = _get_lineno_msgs(view, lineno) if len(errors_msg) > 0: view.set_status('Linter', '; '.join(errors_msg)) else: view.erase_status('Linter')
def on_selection_modified_async(self, view): if (self.is_python_syntax(view) and get_setting('python_linting', view, True)): self.update_statusbar(view)
def update_statusbar(view): if (_is_python_syntax(view) and get_setting('python_linting', view, True)): _update_statusbar(view)