Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to ignore certain views #2410

Merged
merged 4 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand Down Expand Up @@ -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
Comment on lines +1394 to +1396
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the best place here for this check, because the can_handle methods sounds like it might be called more often than necessary. Though the only other reference is in WindowManager.sessions, but that seems to be an unused method (?)

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