Skip to content

Commit

Permalink
Fix issue #1045, execute_command need pass "arguments" (not only "com…
Browse files Browse the repository at this point in the history
…mand"), otherwise code action will select first one if actions have same "command" name.
  • Loading branch information
manateelazycat committed Sep 22, 2024
1 parent d0ac8c6 commit 226fc1b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
5 changes: 4 additions & 1 deletion core/fileaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ def call(self, method, *args, **kwargs):
if self.single_server:
self.send_request(self.single_server, method, handler, *args, **kwargs)
else:
if method in ["completion", "completion_item_resolve", "diagnostics", "code_action", "execute_command"]:
if method in ["completion", "completion_item_resolve", "diagnostics", "code_action"]:
method_server_names = self.multi_servers_info[method]
elif method in ["execute_command"]:
# "execute_command" is trigger by code action, one time only need send request to *ONE* LSP server.
method_server_names = [args[0]] # first arguments if server name.
else:
method_server_names = [self.multi_servers_info[method]]

Expand Down
16 changes: 1 addition & 15 deletions core/handler/execute_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@ class ExecuteCommand(Handler):
method = "workspace/executeCommand"
send_document_uri = False

def process_request(self, server_name, command) -> dict:
arguments = []

if server_name in self.file_action.code_actions and self.file_action.code_actions[server_name] is not None:
for action in self.file_action.code_actions[server_name]: # type: ignore
try:
if action["command"] == command:
arguments = action["arguments"]
break
elif action["command"]["command"] == command:
arguments = action["command"]["arguments"]
break
except:
pass

def process_request(self, server_name, command, arguments) -> dict:
return dict(command=command, arguments=arguments)

def process_response(self, response) -> None:
Expand Down
10 changes: 5 additions & 5 deletions lsp-bridge-code-action.el
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ Please read https://microsoft.github.io/language-server-protocol/specifications/
;; Command is string, send `workspace/executeCommand' request to LSP server. arguments are cached in Python side.
((stringp command)
;; Execute command with temp-buffer.
(lsp-bridge-call-file-api "execute_command" server_name command))
(lsp-bridge-call-file-api "execute_command" server_name command arguments))
;; Parse command argument if command is plist, and call `lsp-bridge-code-action--fix-do' again.
((lsp-bridge-plistp command)
;; We need add server-name in `command', otherwise `lsp-bridge-code-action--fix-do' will send empty server name to Python.
(let ((server-command command))
(plist-put server-command :server-name server_name)
(lsp-bridge-code-action--fix-do command temp-buffer))))
;; We need add server-name in `next-action', otherwise `lsp-bridge-code-action--fix-do' will send empty server name to Python.
(let ((next-action command))
(plist-put next-action :server-name server_name)
(lsp-bridge-code-action--fix-do next-action temp-buffer))))
(unless temp-buffer
(message "[LSP-BRIDGE] Execute code action '%s'" (plist-get action :title)))

Expand Down

0 comments on commit 226fc1b

Please sign in to comment.