Skip to content
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
2 changes: 2 additions & 0 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .core.sessions import register_plugin
from .core.sessions import Session
from .core.sessions import SessionBufferProtocol
from .core.sessions import SessionViewProtocol
from .core.sessions import unregister_plugin
from .core.types import ClientConfig
from .core.types import DebouncerNonThreadSafe
Expand Down Expand Up @@ -53,6 +54,7 @@
'Response',
'Session',
'SessionBufferProtocol',
'SessionViewProtocol',
'unregister_plugin',
'uri_from_view',
'uri_to_filename', # deprecated
Expand Down
10 changes: 10 additions & 0 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,12 @@ def on_session_buffer_changed_async(self, session_buffer: SessionBufferProtocol)
"""
pass

def on_selection_modified_async(self, session_view: SessionViewProtocol) -> None:
"""
Called after the selection has been modified in a view (debounced).
"""
pass

def on_session_end_async(self, exit_code: int | None, exception: Exception | None) -> None:
"""
Notifies about the session ending (also if the session has crashed). Provides an opportunity to clean up
Expand Down Expand Up @@ -1336,6 +1342,10 @@ def get_workspace_folders(self) -> list[WorkspaceFolder]:
def uses_plugin(self) -> bool:
return self._plugin is not None

@property
def plugin(self) -> AbstractPlugin | None:
return self._plugin

# --- session view management --------------------------------------------------------------------------------------

def register_session_view_async(self, sv: SessionViewProtocol) -> None:
Expand Down
8 changes: 5 additions & 3 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,8 @@ def on_selection_modified_async(self) -> None:
if not self._is_in_higlighted_region(first_region.b):
self._clear_highlight_regions()
self._clear_code_actions_annotation()
if userprefs().document_highlight_style or userprefs().show_code_actions:
Copy link
Member Author

@jwortmann jwortmann Oct 7, 2025

Choose a reason for hiding this comment

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

Note that I removed this if-condition here for simplicity (otherwise we would need to check beforehand whether there is at least one session with a plugin). Iirc I added this condition a while ago to reduce unnecessary debouncing calls if neither highlights nor code actions are enabled in the user settings. But I assume that typically at least one of those features is enabled, so probably this condition was relatively useless in almost all cases anyway.

self._when_selection_remains_stable_async(
self._on_selection_modified_debounced_async, first_region, after_ms=self.debounce_time)
self._when_selection_remains_stable_async(
self._on_selection_modified_debounced_async, first_region, after_ms=self.debounce_time)
self._update_diagnostic_in_status_bar_async()
self._resolve_visible_code_lenses_async()

Expand All @@ -433,6 +432,9 @@ def _on_selection_modified_debounced_async(self) -> None:
self._do_highlights_async()
if userprefs().show_code_actions:
self._do_code_actions_async()
for sv in self.session_views_async():
if plugin := sv.session.plugin:
plugin.on_selection_modified_async(sv)

def on_post_save_async(self) -> None:
# Re-determine the URI; this time it's guaranteed to be a file because ST can only save files to a real
Expand Down