diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index ab493525a..5925c2550 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -936,6 +936,15 @@ def on_post_start(cls, window: sublime.Window, initiating_view: sublime.View, """ pass + @classmethod + def should_ignore(cls, view: sublime.View) -> bool: + """ + Exclude a view from being handled by the language server, even if it matches the URI scheme(s) and selector from + the configuration. This can be used to, for example, ignore certain file patterns which are listed in a + configuration file (e.g. .gitignore). + """ + return False + @classmethod def markdown_language_id_to_st_syntax_map(cls) -> Optional[MarkdownLangMap]: """ @@ -1382,6 +1391,9 @@ def compare_by_string(sb: Optional[SessionBufferProtocol]) -> bool: def can_handle(self, view: sublime.View, scheme: str, capability: Optional[str], inside_workspace: bool) -> bool: if not self.state == ClientStates.READY: return False + if self._plugin and self._plugin.should_ignore(view): + debug(view, "ignored by plugin", self._plugin.__class__.__name__) + return False if scheme == "file": file_name = view.file_name() if not file_name: diff --git a/plugin/core/windows.py b/plugin/core/windows.py index 1c4cb43f9..80978f601 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -232,7 +232,11 @@ def _needed_config(self, view: sublime.View) -> Optional[ClientConfig]: handled = True break if not handled: - return config + plugin = get_plugin(config.name) + if plugin and plugin.should_ignore(view): + debug(view, "ignored by plugin", plugin.__name__) + else: + return config return None def start_async(self, config: ClientConfig, initiating_view: sublime.View) -> None: