Skip to content

Commit

Permalink
Add AbstractPlugin.on_session_buffer_changed API (#1873)
Browse files Browse the repository at this point in the history
So that plugins can do background/implicit requests when the buffer changes.
  • Loading branch information
rchl authored Oct 16, 2021
1 parent 1c9eb15 commit 027333e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,12 @@ def on_open_uri_async(self, uri: DocumentUri, callback: Callable[[str, str, str]
"""
return False

def on_session_buffer_changed_async(self, session_buffer: SessionBufferProtocol) -> None:
"""
Called when the context of the session buffer has changed or a new buffer was opened.
"""
pass

def on_session_end_async(self) -> None:
"""
Notifies about the session ending (also if the session has crashed). Provides an opportunity to clean up
Expand Down Expand Up @@ -1253,6 +1259,10 @@ def open_location_async(self, location: Union[Location, LocationLink], flags: in
uri, r = get_uri_and_range_from_location(location)
return self.open_uri_async(uri, r, flags, group)

def notify_plugin_on_session_buffer_change(self, session_buffer: SessionBufferProtocol) -> None:
if self._plugin:
self._plugin.on_session_buffer_changed_async(session_buffer)

def _maybe_resolve_code_action(self, code_action: CodeAction) -> Promise[Union[CodeAction, Error]]:
if "edit" not in code_action and self.has_capability("codeActionProvider.resolveProvider"):
# TODO: Should we accept a SessionBuffer? What if this capability is registered with a documentSelector?
Expand Down
2 changes: 2 additions & 0 deletions plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def _check_did_open(self, view: sublime.View) -> None:
return
self.session.send_notification(did_open(view, language_id))
self.opened = True
self.session.notify_plugin_on_session_buffer_change(self)

def _check_did_close(self) -> None:
if self.opened and self.should_notify_did_close():
Expand Down Expand Up @@ -238,6 +239,7 @@ def purge_changes_async(self, view: sublime.View) -> None:
except MissingUriError:
pass # we're closing
self.pending_changes = None
self.session.notify_plugin_on_session_buffer_change(self)

def on_pre_save_async(self, view: sublime.View) -> None:
if self.should_notify_will_save():
Expand Down

0 comments on commit 027333e

Please sign in to comment.