Skip to content

Commit

Permalink
Allow plugins to ignore certain views (#2410)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann authored Mar 10, 2024
1 parent 57c01e7 commit 1a22893
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,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]:
"""
Expand Down Expand Up @@ -1383,6 +1392,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:
Expand Down
6 changes: 5 additions & 1 deletion plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1a22893

Please sign in to comment.