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

Deno refactor code actions are not available #20312

Open
1 task done
alexd6631 opened this issue Nov 6, 2024 · 1 comment
Open
1 task done

Deno refactor code actions are not available #20312

alexd6631 opened this issue Nov 6, 2024 · 1 comment
Labels
admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue

Comments

@alexd6631
Copy link

Check for existing issues

  • Completed

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 alexd6631 added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Nov 6, 2024
@alexd6631
Copy link
Author

alexd6631 commented Nov 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue
Projects
None yet
Development

No branches or pull requests

1 participant