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

LSP code actions not working #1373

Closed
ericdallo opened this issue Nov 2, 2021 · 7 comments
Closed

LSP code actions not working #1373

ericdallo opened this issue Nov 2, 2021 · 7 comments
Labels
bug Something isn't working lsp

Comments

@ericdallo
Copy link
Contributor

It seems that after #1336 which bumped vscode-language-client from 6.1.3 -> 7.0.0, code actions stopped working. It's possible to list and show the code actions popup, but when clicking in any of then nothing happens or is logged anywhere.

Repro:

  1. Move cursor to a function name
  2. ctrl/command + .
  3. select cycle-privacy
  4. Confirm nothing happens...

This is an example of another famous LSP extension that uses the same version and code actions work: https://github.com/Dart-Code/Dart-Code/blob/master/package.json#L2715

@mchughs
Copy link
Contributor

mchughs commented Nov 24, 2021

Peek 2021-11-24 19-11
Some code actions do seem to work, but others don't. I'm using the last release of Calva from 11/10/2021, 12:56:39

@bpringe
Copy link
Member

bpringe commented Nov 28, 2021

@ericdallo It seems with version 6.1.3 of vscode-languageclient, when a code action is selected from the editor menu, a workspace/executeCommand request is sent for the code action command by the client library or VS Code (Calva is not sending it manually).

In version 7.0.0 of the client library, when a code action is selected from the editor menu, a codeAction/resolve request is sent and a corresponding response is received with the command to be run and the arguments, but the command is not run (a workspace/executeCommand request is not sent).

I'm guessing Calva needs to manually send the command returned in the codeAction/resolve response with this latest version of the library (which uses 3.16 of the LSP, vs 3.15 which was used by 6.1.3, I think). I'm working on this now, but just wanted to post some findings here.

@ericdallo
Copy link
Contributor Author

@bpringe good debugging, but I wonder how Dart-Code vscode extension does the same of calva and it works, I didn't find anything showing that they are sending the request manually.

Anyway, if that fixes the problem would be nice

@bpringe
Copy link
Member

bpringe commented Nov 28, 2021

When running the cycle-privacy code action from the editor menu with version 6.1.3 of the client lib, I see this in the message logs, and the edit is applied in the editor:

[Trace - 1:38:56 PM] Sending request 'workspace/executeCommand - (41)'.
Params: {
    "command": "cycle-privacy",
    "arguments": [
        "file:///Users/brandon/development/clojure-test/src/core.clj",
        3,
        5
    ]
}


[Trace - 1:38:56 PM] Received response 'workspace/executeCommand - (41)' in 1ms.
No result returned.

When doing the same with version 7.0.0 of the client lib, I see this in the message logs, and the edit is not applied in the editor:

[Trace - 1:43:22 PM] Sending request 'codeAction/resolve - (14)'.
Params: {
    "title": "Cycle privacy",
    "data": {
        "id": "refactor-cycle-privacy",
        "uri": "file:///Users/brandon/development/clojure-test/src/core.clj",
        "line": 3,
        "character": 5
    },
    "kind": "refactor.rewrite"
}


[Trace - 1:43:23 PM] Received response 'codeAction/resolve - (14)' in 17ms.
Result: {
    "title": "Cycle privacy",
    "kind": "refactor.rewrite",
    "command": {
        "title": "Cycle privacy",
        "command": "cycle-privacy",
        "arguments": [
            "file:///Users/brandon/development/clojure-test/src/core.clj",
            3,
            5
        ]
    }
}

codeAction/resolve was added in 3.16 of the LSP, it seems.

I wonder how Dart-Code vscode extension does the same of calva and it works, I didn't find anything showing that they are sending the request manually

I may look into that extension's code then. I just don't know for sure how a client is supposed to handle the resolve response. It didn't seem very obvious in the protocol specification.

@bpringe
Copy link
Member

bpringe commented Nov 28, 2021

A CodeAction must set either edit and/or a command. If both are supplied, the edit is applied first, then the command is executed.

It says the command is executed, but that doesn't seem to be the case.

@ericdallo
Copy link
Contributor Author

Yeah, really weird, I suspect it's a bug on vscode.
Maybe calva could set that it doesn't support resolveCodeAction and the old flow maybe would be applied and work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lsp
Projects
None yet
Development

No branches or pull requests

3 participants