yegappan / lsp

Language Server Protocol (LSP) plugin for Vim9
MIT License
458 stars 49 forks source link

CodeAction fails because lsp is incorrectly passing `title` to `workspace/executeCommand` #470

Open lieryan opened 5 months ago

lieryan commented 5 months ago

Hi, I was test driving the new lsp client, I had encountered a few problems with code action.

To reproduce:

  1. Setup and activate virtualenv

  2. Install python-lsp-server and a plugin with code action, for example, pylsp-rope:

    pip install python-lsp-server pylsp-rope
  3. Create this file:

    # moda.py
    one = 1
  4. Visually select the line and run :LspCodeAction

Expected this to work and apply the code action change, but instead got this error message:

Error: request workspace/executeCommand failed (TypeError: PythonLSPServer.m_workspace__execute_command() got an unexpected keyword argument 'title', error = InvalidParams, data = {'traceback': ['  File "/
pylsp-venv/lib/python3.11/site-packages/pylsp_jsonrpc/endpoint.py", line 117, in consume^@    self._handle_request(message[''id''], message[''method''], message.get(''params''))^@', '  File "/pylsp-venv/li
b/python3.11/site-packages/pylsp_jsonrpc/endpoint.py", line 197, in _handle_request^@    handler_result = handler(params)^@                     ^^^^^^^^^^^^^^^^@', '  File "/pylsp-venv/lib/python3.11/site-
packages/pylsp_jsonrpc/dispatchers.py", line 25, in handler^@    return method(**(params or {}))^@           ^^^^^^^^^^^^^^^^^^^^^^^^^@']})
lieryan commented 5 months ago

Ok, nevermind, I think I found the issue. It's because pylsp-rope is generating executeCommand with some non-standard arguments title. I can fix that.

Other vim lsp clients seems to tolerate extra arguments there, but this isn't an LSP client issue.

Apologies for the noise.

lieryan commented 5 months ago

Reopening this. Actually, apologies again for the noise, I was completely confused.

pylsp-rope was actually correct in emitting the title as required by LSP. There are two titles for the CodeAction.title and the CodeAction.command.title. Both are required attributes by the spec.

However, for some reason, title is not a parameter for the workspace/executeCommand. It seems that yegappan/lsp is incorrectly passing off the title into the executeCommand() and pylsp doesn't allow title to be passed in.

yegappan commented 5 months ago

I have committed 9111948aa541df98c66da57ab34e3f9914f44d01 to not send the title field in the workspace/executeCommand requests. Note that this will not fully resolve the issue that you have raised. The Vim LSP channel support currently supports only numbers as identifiers in LSP messages. But in this case, the language server uses a string (UUID) for the identifier. The Vim LSP channel support currently cannot handle this.