Inline `assign_linters_to_view`
@@ -231,37 +231,13 @@ class SublimeLinter(sublime_plugin.EventListener, Listener):
If the syntax has changed, a new linter is assigned.
"""
- if not view:
- return
-
vid = view.id()
- old_linters = persist.view_linters.get(vid, [])
- changed = assign_linters_to_view(view)
- if changed:
- bid = view.buffer_id()
- persist.errors[bid].clear()
- for linter in old_linters:
- events.broadcast(events.LINT_RESULT, {
- 'buffer_id': bid,
- 'linter_name': linter.name,
- 'errors': []
- })
-
- self.linted_views.discard(vid)
- return True
- else:
- return False
-
-
-def assign_linters_to_view(view):
- """Assign linters to a view."""
- vid = view.id()
- old_classes = {
+ old_linters = {
linter.__class__
for linter in persist.view_linters.get(vid, set())
}
- new_classes = {
+ wanted_linters = {
linter_class
for linter_class in persist.linter_classes.values()
if (
@@ -271,13 +247,24 @@ def assign_linters_to_view(view):
)
}
- if old_classes != new_classes:
+ if old_linters != wanted_linters:
+ bid = view.buffer_id()
+ persist.errors[bid].clear()
+ for linter in old_linters:
+ events.broadcast(events.LINT_RESULT, {
+ 'buffer_id': bid,
+ 'linter_name': linter.name,
+ 'errors': []
+ })
+
+ self.linted_views.discard(vid)
+
syntax = util.get_syntax(view)
logger.info("detected syntax: {}".format(syntax))
persist.view_linters[vid] = {
linter_class(view, syntax)
- for linter_class in new_classes
+ for linter_class in wanted_linters
}
return True
