From c05541ae93a11257d3a9aa53655377add055d878 Mon Sep 17 00:00:00 2001 From: Vladimir Rudnyh Date: Fri, 30 Jan 2015 22:55:41 +0300 Subject: [PATCH] Successful lint report with gutter marks blink (enabled by default) --- Flake8Lint.py | 108 +++++++++++++++++++++++------------- Flake8Lint.sublime-settings | 5 ++ README.md | 5 ++ gutter-themes/success.png | Bin 0 -> 568 bytes lint.py | 2 - 5 files changed, 80 insertions(+), 40 deletions(-) create mode 100644 gutter-themes/success.png diff --git a/Flake8Lint.py b/Flake8Lint.py index 71d10a9..360239f 100644 --- a/Flake8Lint.py +++ b/Flake8Lint.py @@ -65,8 +65,6 @@ def __init__(self): """ Initialize settings. """ - print("--- settings init") - editor_settings = sublime.load_settings('Preferences.sublime-settings') editor_settings.clear_on_change('flake8lint-color-scheme') editor_settings.add_on_change('flake8lint-color-scheme', @@ -82,8 +80,6 @@ def setup(self): """ Update settings. """ - print("--- settings setup") - # debug mode (verbose output to ST python console) self.debug = bool(self.settings.get('debug', False)) @@ -147,11 +143,25 @@ def setup(self): if self.gutter_marks not in all_gutter_marks: self.gutter_marks = 'theme-simple' + mark_themes_paths = [ + 'Packages', os.path.basename(PLUGIN_DIR), 'gutter-themes' + ] + if int(sublime.version()) < 3014: + mark_themes_paths = ( + [os.path.pardir, os.path.pardir] + mark_themes_paths + ) + self.mark_themes_dir = '/'.join(mark_themes_paths) + # report successfull (passed) lint self.report_on_success = bool( self.settings.get('report_on_success', False) ) + # blink gutter marks on success + self.blink_gutter_marks_on_success = bool( + self.settings.get('blink_gutter_marks_on_success', True) + ) + # load global flake8 config ("~/.config/flake8") self.use_flake8_global_config = bool( self.settings.get('use_flake8_global_config', True) @@ -428,6 +438,7 @@ class LintReport(object): regions = {} gutter_mark = '' + gutter_mark_success = '' select = [] ignore = [] is_highlight = False @@ -441,47 +452,48 @@ def __init__(self, view, errors_list, view_settings, quiet=False): self.prepare_settings(view_settings) self.prepare_errors(errors_list) - self.show_errors(quiet=quiet) + + if self.errors_list: + self.show_errors(quiet=quiet) + else: + self.report_success(quiet=quiet) def get_gutter_mark(self): """ Returns gutter mark icon or empty string if marks are disabled. """ - mark_type = settings.gutter_marks + # ST does not expect platform specific paths here, but only + # forward-slash separated paths relative to "Packages" + self.gutter_mark_success = '/'.join( + [settings.mark_themes_dir, 'success'] + ) + if int(sublime.version()) >= 3014: + self.gutter_mark_success += '.png' - if mark_type in ('dot', 'circle', 'bookmark', 'cross'): - return mark_type + self.gutter_mark = '' - if mark_type.startswith('theme-'): + mark_type = settings.gutter_marks + if mark_type in ('dot', 'circle', 'bookmark', 'cross'): + self.gutter_mark = mark_type + elif mark_type.startswith('theme-'): theme = mark_type[6:] - if theme in ('alpha', 'bright', 'dark', 'hard', 'simple'): - mark_themes_paths = [ - 'Packages', os.path.basename(PLUGIN_DIR), 'gutter-themes' - ] - if int(sublime.version()) < 3014: - mark_themes_paths = ( - [os.path.pardir, os.path.pardir] + mark_themes_paths - ) - - # ST does not expect platform specific paths here, but only - # forward-slash separated paths relative to "Packages" - mark_themes_dir = '/'.join(mark_themes_paths) - mark = '/'.join([mark_themes_dir, '{0}-{{0}}'.format(theme)]) - - if int(sublime.version()) >= 3014: - mark += '.png' - - return mark - else: + if theme not in ('alpha', 'bright', 'dark', 'hard', 'simple'): log("unknown gutter mark theme: '{0}'".format(mark_type)) + return - return '' + # ST does not expect platform specific paths here, but only + # forward-slash separated paths relative to "Packages" + self.gutter_mark = '/'.join( + [settings.mark_themes_dir, '{0}-{{0}}'.format(theme)] + ) + if int(sublime.version()) >= 3014: + self.gutter_mark += '.png' def prepare_settings(self, view_settings): """ Get view lint settings. """ - self.gutter_mark = self.get_gutter_mark() + self.get_gutter_mark() self.select = view_settings.get('select') or [] self.ignore = view_settings.get('ignore') or [] @@ -965,6 +977,31 @@ def error_selected(self, item_selected): SublimeStatusBar.update(self.view) + def report_success(self, quiet=False): + """ + Blink with gutter marks (success report). + """ + if quiet: + return + + if settings.report_on_success: + log("Report about lint success") + sublime.message_dialog('Flake8 Lint: SUCCESS') + + if settings.blink_gutter_marks_on_success: + log("Blink gutter marks about lint success") + self.view.add_regions( + 'flake8lint-success', + self.view.lines(sublime.Region(0, self.view.size())), + 'flake8lint.mark.gutter', + self.gutter_mark_success, + sublime.HIDDEN + ) + sublime.set_timeout( + lambda: self.view.erase_regions('flake8lint-success'), + 300 + ) + class Flake8Lint(object): """ @@ -1188,13 +1225,10 @@ def async_lint(view, view_settings, quiet=False): log("lint time: {0:.3f}ms".format(lint_time)) log("lint errors found: {0}".format(len(errors_list))) - Flake8Lint.cleanup(view) # clean regions and statusbar - + # clean regions and statusbar + Flake8Lint.cleanup(view) # show errors - if errors_list: - LintReport(view, errors_list, view_settings, quiet=quiet) - elif settings.report_on_success: - sublime.message_dialog('Flake8 Lint: SUCCESS') + LintReport(view, errors_list, view_settings, quiet=quiet) class Flake8NextErrorCommand(sublime_plugin.TextCommand): @@ -1337,8 +1371,6 @@ def plugin_loaded(): settings = Flake8LintSettings() - print('===', settings.debug) - log("plugin was loaded") update_color_scheme(settings) diff --git a/Flake8Lint.sublime-settings b/Flake8Lint.sublime-settings index 8082d19..c881f15 100644 --- a/Flake8Lint.sublime-settings +++ b/Flake8Lint.sublime-settings @@ -40,6 +40,11 @@ // report successfull (passed) lint "report_on_success": false, + // blink gutter marks on success (will not blink with live mode check) + // this icon is not depends on 'gutter_marks' settings + // please, be careful: this may cause performance issues on ST2 + "blink_gutter_marks_on_success": true, + // load global flake8 config ("~/.config/flake8") "use_flake8_global_config": true, // load per-project config (i.e. "tox.ini", "setup.cfg" and ".pep8" files) diff --git a/README.md b/README.md index dff9f77..9aed678 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,11 @@ Default "Python Flake8 Lint" plugin config: Preferences->Package // report successfull (passed) lint "report_on_success": false, + // blink gutter marks on success (will not blink with live mode check) + // this icon is not depends on 'gutter_marks' settings + // please, be careful: this may cause performance issues on ST2 + "blink_gutter_marks_on_success": true, + // load global flake8 config ("~/.config/flake8") "use_flake8_global_config": true, // load per-project config (i.e. "tox.ini", "setup.cfg" and ".pep8" files) diff --git a/gutter-themes/success.png b/gutter-themes/success.png new file mode 100644 index 0000000000000000000000000000000000000000..0729929917f73673906c523c8b2d7960befdd01e GIT binary patch literal 568 zcmV-80>}M{P)+$erynCH3|%BMXX?ubPIx{ zIv7GhM3HM*BqoNCM4^UF+x9K@x(g#IV)8wnULh7UKF3-dd~Nj*}kV7EM|AbFK~KM4mH%AQ4BM^i6jqtJ}^}B zfWDzU7SCX_?SJz2=K5~Aa_V9%&iLFcw{Vj#X+X~-;|6P$>e;keczFBe_QrqZ9lLg( zH5ey)<4F>c5Ld1pWu_Q;K>=n{vU5rQ>By4qjboi9eaG``ht2Lr?%2K8rI@GA$Nppt z@fiIVZt%QVIe?IFpy5DnT9&90By55dv{o9cYWHnvaVQnzrxsH|<6@NI>7Td)*HOz7 zFg$?ja55r`IP?A=VYD!-GO(+uN^woAgE=OKa0DymhNNp?cC5c7^tg&=Z zmrRfg&*QyxpME}*D{BBi;0X(LZH(!4wCHqL)G+>UUvZ6kh%Q%NQ~o6DP@J z>%zad?CWB5CGw&J00P^x-`7WZ@oJK>&