Closed mikez closed 1 month ago
I think the readme is a bit outdated. The source.sortImports.ts
code action is also supported - https://github.com/typescript-language-server/typescript-language-server/blob/master/README.md#code-actions-on-save
👍 confirm that lsp_code_actions_on_save
works.
Should lsp_execute
with _typescript.sortImports
also work? Can't make it work yet.
No, this is a newer functionality that doesn't have legacy _typescript.*
command exposed since it should be redundant. It should be possible to invoke code action through the editor.
In the README.md, you have this example listed:
{ "keys": ["ctrl+k"], "command": "lsp_execute",
"args": {
"session_name": "LSP-typescript",
"command_name": "_typescript.organizeImports",
"command_args": ["${file}"]
}
}
How would I setup a keyboard shortcut otherwise?
Actually maybe there is no direct equivalent to that.
You could do this:
{
"keys": ["alt+c"],
"command": "lsp_code_actions",
"args": {"only_kinds": ["source.sortImports.ts"]},
"context": [{"key": "lsp.session_with_capability", "operand": "codeActionProvider.codeActionKinds"}]
}
but that would still pop up a menu that you would have to confirm.
How does VsCode do sortImports, is this not using typescript language server?
The issue with organizeImports is that it removes "unused" classes which sometimes are used in JavaScript JSDoc annotations; I want to keep those imports. The sortImports command only sorts and doesn't remove.