From a1188f3152f36d5a5f688b1317d9f27b716dca85 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 16 Oct 2021 21:23:28 +0200 Subject: [PATCH 1/3] Add AbstractPlugin.on_session_buffer_changed API --- plugin/core/sessions.py | 10 ++++++++++ plugin/session_buffer.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index b8710db12..a8321a294 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(self, session_buffer: SessionBufferProtocol) -> None: + """ + Called when the context of the session buffer is changed or a new buffer is 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(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(): From 864fcab498495ff246042a60c294bf43918eb3e1 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 16 Oct 2021 22:25:43 +0200 Subject: [PATCH 2/3] _async --- plugin/core/sessions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index a8321a294..d1afb6b7c 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -672,7 +672,7 @@ def on_open_uri_async(self, uri: DocumentUri, callback: Callable[[str, str, str] """ return False - def on_session_buffer_changed(self, session_buffer: SessionBufferProtocol) -> None: + def on_session_buffer_changed_async(self, session_buffer: SessionBufferProtocol) -> None: """ Called when the context of the session buffer is changed or a new buffer is opened. """ @@ -1261,7 +1261,7 @@ def open_location_async(self, location: Union[Location, LocationLink], flags: in def notify_plugin_on_session_buffer_change(self, session_buffer: SessionBufferProtocol) -> None: if self._plugin: - self._plugin.on_session_buffer_changed(session_buffer) + 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"): From 1efe5c196260b796428711619254983c180c1f8e Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 16 Oct 2021 22:26:50 +0200 Subject: [PATCH 3/3] has/was --- plugin/core/sessions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index d1afb6b7c..3dec33eeb 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -674,7 +674,7 @@ def on_open_uri_async(self, uri: DocumentUri, callback: Callable[[str, str, str] def on_session_buffer_changed_async(self, session_buffer: SessionBufferProtocol) -> None: """ - Called when the context of the session buffer is changed or a new buffer is opened. + Called when the context of the session buffer has changed or a new buffer was opened. """ pass