Factor `extract_lintable_regions`
@@ -92,13 +92,18 @@ def get_lint_tasks(
view, # type: sublime.View
view_has_changed, # type: Callable[[], bool]
): # type: (...) -> Iterator[Tuple[Linter, List[Task[LintResult]]]]
- for (linter, regions) in get_lint_regions(linters, view):
- tasks = _make_tasks(linter, regions, view, view_has_changed)
+ for linter in linters:
+ tasks = _make_tasks(linter, view, view_has_changed)
yield linter, tasks
-def _make_tasks(linter_, regions, view, view_has_changed):
- # type: (Linter, List[sublime.Region], sublime.View, Callable[[], bool]) -> List[Task[LintResult]]
+def _make_tasks(linter_, view, view_has_changed):
+ # type: (Linter, sublime.View, Callable[[], bool]) -> List[Task[LintResult]]
+ selector = linter_.settings.get('selector')
+ if selector is None:
+ return []
+
+ regions = extract_lintable_regions(view, selector)
independent_linters = create_n_independent_linters(linter_, len(regions))
tasks = [] # type: List[Task[LintResult]]
for linter, region in zip(independent_linters, regions):
@@ -116,6 +121,15 @@ def _make_tasks(linter_, regions, view, view_has_changed):
return tasks
+def extract_lintable_regions(view, selector):
+ # type: (sublime.View, str) -> List[sublime.Region]
+ # Inspecting just the first char is faster
+ if view.score_selector(0, selector):
+ return [sublime.Region(0, view.size())]
+ else:
+ return [region for region in view.find_by_selector(selector)]
+
+
def create_n_independent_linters(linter, n):
return (
[linter]
@@ -240,21 +254,6 @@ def finalize_errors(linter, errors, offsets):
})
-def get_lint_regions(linters, view):
- # type: (List[Linter], sublime.View) -> Iterator[Tuple[Linter, List[sublime.Region]]]
- for linter in linters:
- settings = linter.get_view_settings()
- selector = settings.get('selector', None)
- if selector is not None:
- # Inspecting just the first char is faster
- if view.score_selector(0, selector):
- yield linter, [sublime.Region(0, view.size())]
- else:
- yield linter, [
- region for region in view.find_by_selector(selector)
- ]
-
-
def run_concurrently(tasks, executor):
# type: (List[Task[T]], ThreadPoolExecutor) -> Optional[List[T]]
work = [executor.submit(task) for task in tasks]
