Say I have an LSP that responsds to 'textDocument/codeAction'
like this:
Result: [
{
"title": "Extract method",
"command": {
"title": "Extract method",
"command": "xxx.extractMethodWithRename",
"arguments": [ <filename>, <range> ]
},
"kind": "refactor.extract"
},
{
"title": "Extract variable",
"command": {
"title": "Extract variable",
"command": "xxx.extractVariableWithRename",
"arguments": [ <filename>, <range> ]
},
"kind": "refactor.extract"
}
]
However, this is the actual 'workspace/executeCommand'
request that triggers a response:
Params: {
"command": "xxx.extractVariable",
"arguments": [ <filename>, <range> ]
}
I’ve managed to write a working custom command like this:
local function extract_variable()
local pos_params = vim.lsp.util.make_given_range_params()
local params = {
command = "xxx.extractVariable",
arguments = {
vim.api.nvim_buf_get_name(0),
pos_params.range,
},
}
vim.lsp.buf.execute_command(params)
end
Since there’s no ['textDocument/codeAction']
handler I’m wondering what’s the best way to intercept that in a server-specific way. (besides overriding vim.ui.select
or vim.lsp.buf.range_code_actions
directly)
Thanks
EDIT:
solved
on_attach = function(client, bufnr)
client.commands['xxx.extractVariableWithRename'] = function(command, enriched_ctx)
command.command = 'xxx.extractVariable'
vim.lsp.buf.execute_command(command)
end
...
end