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

fix: check codeAction/resolve capability against session buffer #2343

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 15 additions & 7 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ def get_language_id(self) -> Optional[str]:
def get_view_in_group(self, group: int) -> sublime.View:
...

def is_self(self, buffer_id: int) -> bool:
...
suiyuex marked this conversation as resolved.
Show resolved Hide resolved

def register_capability_async(
self,
registration_id: str,
Expand Down Expand Up @@ -1619,7 +1622,7 @@ def run_code_action_async(
# A code action can have an edit and/or command. Note that it can have *both*. In case both are present, we
# must apply the edits before running the command.
code_action = cast(CodeAction, code_action)
return self._maybe_resolve_code_action(code_action) \
return self._maybe_resolve_code_action(code_action, view) \
.then(lambda code_action: self._apply_code_action_async(code_action, view))

def open_uri_async(
Expand Down Expand Up @@ -1704,12 +1707,17 @@ def notify_plugin_on_session_buffer_change(self, session_buffer: SessionBufferPr
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?
# We must first resolve the command and edit properties, because they can potentially be absent.
request = Request("codeAction/resolve", code_action)
return self.send_request_task(request)
def _maybe_resolve_code_action(self, code_action: CodeAction, view: Optional[sublime.View]) -> Promise[Union[CodeAction, Error]]:
rwols marked this conversation as resolved.
Show resolved Hide resolved
if "edit" not in code_action:
has_capability = self.has_capability("codeActionProvider.resolveProvider")
if not has_capability and view:
session_view = self.session_view_for_view_async(view)
if session_view:
has_capability = session_view.has_capability_async("codeActionProvider.resolveProvider")
if has_capability:
# We must first resolve the command and edit properties, because they can potentially be absent.
request = Request("codeAction/resolve", code_action)
return self.send_request_task(request)
return Promise.resolve(code_action)

def _apply_code_action_async(
Expand Down
3 changes: 3 additions & 0 deletions plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def get_view_in_group(self, group: int) -> sublime.View:
return view
return next(iter(self.session_views)).view

def is_self(self, id: int) -> bool:
return self._id == id;

@property
def language_id(self) -> str:
"""
Expand Down
Loading