zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
50.77k stars 3.15k forks source link

Deno refactor code actions are not available #20312

Open alexd6631 opened 3 weeks ago

alexd6631 commented 3 weeks ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Context

Let's assume we have configured a Deno project and enabled LSP

Reproduction

If you select a type expression under vscode, a few code refactor actions such as "extract to constant" / "extract to function" will be available.

However if you do the same with zed, unfortunately no code action are available.

Zed should support LSP code action, and Deno should implement LSP so in theory it should work.

Quick analysis

Out of curiosity I investigated a bit (using deno.internalDebug LSP flag):

Here is the VS code trace when we select an expression :

{"type":"mark","name":"tsc.request.getApplicableRefactors"},
{"type":"mark","name":"tsc.host.getApplicableRefactors","count":30,"args":{"GetApplicableRefactors":["file:///Users/alexandre/Dev/Tests/TestDeno3/main_test.ts",{"pos":394,"end":417},{"quotePreference":"double","includeCompletionsForModuleExports":true,"includeCompletionsForImportStatements":true,"includeCompletionsWithSnippetText":true, ...},"implicit",""]}},
{"type":"measure","name":"tsc.host.getApplicableRefactors","count":30,"duration":1.083},
{"type":"measure","name":"tsc.request.getApplicableRefactors","count":30,"duration":2.1},
{"type":"measure","name":"lsp.code_action","count":30,"duration":3.254},

Here is the similar trace with zed :

stderr: {"type":"mark","name":"lsp.code_action","count":27,"args":{"textDocument":{"uri":"file:///Users/alexandre/Dev/Tests/TestDeno3/main_test.ts"},"range":{"start":{"line":16,"character":2},"end":{"line":16,"character":25}},"context":{"diagnostics":[],"only": ["quickfix","refactor","refactor.extract.function","refactor.extract.constant","refactor.extract.type","refactor.extract.interface","refactor.move.newFile","refactor.rewrite.import","refactor.rewrite.export","refactor.rewrite.arrow.braces","refactor.rewrite.parameters.toDestructured","refactor.rewrite.property.generateAccessors"]}}}, <=== only is provided

stderr: {"type":"mark","name":"tsc.request.getApplicableRefactors"},
stderr: {"type":"mark","name":"tsc.host.getApplicableRefactors","count":27,"args":{"GetApplicableRefactors":["file:///Users/alexandre/Dev/Tests/TestDeno3/main_test.ts",{"pos":394,"end":417},{"quotePreference":"double","includeCompletionsForModuleExports":true,"includeCompletionsForImportStatements":true,"includeCompletionsWithSnippetText":true,"includeAutomaticOptionalChainCompletions":true,"includeCompletionsWithInsertText":true,"includeCompletionsWithClassMemberSnippets":true,"includeCompletionsWithObjectLiteralMethodSnippets":true,"useLabelDetailsInCompletionEntries":true,"allowIncompleteCompletions":true,"importModuleSpecifierPreference":"shortest","importModuleSpecifierEnding":"index","allowTextChangesInNewFiles":true,"providePrefixAndSuffixTextForRename":true,"provideRefactorNotApplicableReason":true, ...},null,
"quickfix"]}}, <=== "Quickfix" here

stderr: {"type":"measure","name":"tsc.host.getApplicableRefactors","count":27,"duration":0.229},
stderr: {"type":"measure","name":"tsc.request.getApplicableRefactors","count":27,"duration":0.893},
stderr: {"type":"measure","name":"lsp.code_action","count":27,"duration":1.507},

We can see that only is provided, and "quickfix" is passed to the tsc.host.getApplicableRefactors method.

https://github.com/denoland/deno/blob/b3a3d84ce249ff126f92e7a0849ec0a6ce26e973/cli/lsp/language_server.rs#L1739

We can see in the Deno LSP CLI that the first item of only vector is passed to the get_applicable_refactors If you follow the call chain, it will eventually be passed as a kind parameter. https://github.com/denoland/deno/blob/72c276d61a8b43abd3dbcf4f1440a2bf133fe0d2/cli/tsc/dts/typescript.d.ts#L6274

Environment

Zed: v0.159.10 (Zed) OS: macOS 15.0.1 Memory: 32 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log ``` ```
alexd6631 commented 3 weeks ago

I just did a quick & dirty test, if I do not provide the only parameter, by commenting this line :

https://github.com/zed-industries/zed/blob/36427e0a873bbcd79548d5c9eb531da64a263607/crates/project/src/lsp_command.rs#L2079C17-L2079C21

The code actions are properly retrieved from the LSP :

image