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

Add AbstractPlugin.on_session_buffer_changed API #1873

Merged
merged 3 commits into from
Oct 16, 2021
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
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