Skip to content

Commit

Permalink
fix: check codeAction/resolve capability against session buffer (#2343
Browse files Browse the repository at this point in the history
)
  • Loading branch information
suiyuex authored Oct 19, 2023
1 parent e7cd48f commit 5c4ea1b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,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 +1704,19 @@ 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]]:
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

0 comments on commit 5c4ea1b

Please sign in to comment.