diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index b8710db12..3dec33eeb 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -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 @@ -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? diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index b08e84ebb..29ca21b8e 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -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(): @@ -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():