Skip to content

Commit

Permalink
Successful lint report with gutter marks blink (enabled by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Rudnyh committed Jan 30, 2015
1 parent 7afddd9 commit c05541a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 40 deletions.
108 changes: 70 additions & 38 deletions Flake8Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -428,6 +438,7 @@ class LintReport(object):
regions = {}

gutter_mark = ''
gutter_mark_success = ''
select = []
ignore = []
is_highlight = False
Expand All @@ -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 []
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -1337,8 +1371,6 @@ def plugin_loaded():

settings = Flake8LintSettings()

print('===', settings.debug)

log("plugin was loaded")

update_color_scheme(settings)
Expand Down
5 changes: 5 additions & 0 deletions Flake8Lint.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ Default "Python Flake8 Lint" plugin config: <kbd>Preferences</kbd>-><kbd>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)
Expand Down
Binary file added gutter-themes/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ def lint_external(lines, settings, interpreter, linter):

# parse STDOUT for warnings and errors
for line in result.splitlines():
print(line)

line = line.decode('utf-8').strip()
warning = line.split(':', 2)
if len(warning) == 3:
Expand Down

0 comments on commit c05541a

Please sign in to comment.