Skip to content

Commit

Permalink
Merge pull request #1457 from SublimeLinter/ignore-orphaned-files
Browse files Browse the repository at this point in the history
Ignore orphaned files
  • Loading branch information
kaste committed Jun 22, 2018
2 parents c798799 + f811f3a commit 7dae0eb
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions sublime_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from collections import defaultdict, deque
from contextlib import contextmanager
from functools import partial
from functools import lru_cache, partial
import logging
import os
import time
import threading

Expand Down Expand Up @@ -346,11 +347,22 @@ def get_linters_for_view(view):
bid = view.buffer_id()
current_linters = persist.view_linters.get(bid, [])

wanted_linters = []
for linter_class in persist.linter_classes.values():
settings = linter_module.get_linter_settings(linter_class, view)
if linter_class.can_lint_view(view, settings):
wanted_linters.append(linter_class(view, settings))
filename = view.file_name()
# Unassign all linters from orphaned views
if filename and not os.path.exists(filename):
logger.info(
"Skipping buffer {}; '{}' is unreachable".format(bid, filename))
flash_once(
none_for_none(lambda: view.window().id()),
"{} has become unreachable".format(filename)
)
wanted_linters = []
else:
wanted_linters = []
for linter_class in persist.linter_classes.values():
settings = linter_module.get_linter_settings(linter_class, view)
if linter_class.can_lint_view(view, settings):
wanted_linters.append(linter_class(view, settings))

# It is possible that the user closes the view during debounce time,
# in that case `window` will get None and we will just abort. We check
Expand Down Expand Up @@ -433,3 +445,20 @@ def remember_runtime(bid):

with global_lock:
elapsed_runtimes.append(runtime)


def none_for_none(fn):
try:
return fn()
except Exception as exc:
if 'NoneType' in str(exc):
return None
else:
raise


@lru_cache()
def flash_once(wid, message):
if wid is not None:
window = sublime.Window(wid)
window.status_message(message)

0 comments on commit 7dae0eb

Please sign in to comment.