-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(ts_ls): provide command to run source actions #3780
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
Conversation
Thanks for confirming that :) |
lsp/ts_ls.lua
Outdated
-- ts_ls provides code actions that have a prefix `source.` that apply to the whole file. These are not discoverable | ||
-- via the normal `vim.lsp.buf.code_action()` so add a command that allows access to them. | ||
local function get_source_actions() | ||
local codeActionKinds = client.server_capabilities.codeActionProvider.codeActionKinds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't these discoverable via code_action()
? Can we enhance code_action()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typescript language server only returns these code actions if they're specified in context.only
.
So there's nothing to fix on the nvim side. The command implementation actually does use code_action()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typescript language server only returns these code actions if they're specified in
context.only
.
But why? Is it because code_action()
is sending position info, or diagnostics info? Do we need a way to tell code_action()
not to send that info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is really just how they've implemented it. You can see the code checks it here where kinds
is populated from context.only. The refactor and quickfix actions on the other hand have an extra !kinds
check which means they're always returned if context.only
is not provided.
Source actions are code actions that apply to the whole file. They are not exposed via `vim.lsp.buf.code_action()` and must be requested explicitly.
1e80dd9
to
9a33015
Compare
local source_actions = vim.tbl_filter(function(action) | ||
return vim.startswith(action, 'source.') | ||
end, client.server_capabilities.codeActionProvider.codeActionKinds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if code_action()
should have a parameter that does something like this (except without the source.
constraint) by default? That would Nvim core to provide a default mapping (gra
or something else) so that these are always discoverable for all servers.
Meanwhile, this is a good change, thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't actually know how common this pattern is. I think in other language servers these would be workspace commands instead. That said, if other language servers do it, it might be nice to have.
Source actions are code actions that apply to the whole file. They are not exposed via
vim.lsp.buf.code_action()
and must be requested explicitly.