feat(lsp): simpler API to deal with code actions
This commit is contained in:
@ -53,15 +53,7 @@ return {
|
||||
keys = {
|
||||
{
|
||||
"<leader>co",
|
||||
function()
|
||||
vim.lsp.buf.code_action({
|
||||
apply = true,
|
||||
context = {
|
||||
only = { "source.organizeImports" },
|
||||
diagnostics = {},
|
||||
},
|
||||
})
|
||||
end,
|
||||
LazyVim.lsp.action["source.organizeImports"],
|
||||
desc = "Organize Imports",
|
||||
},
|
||||
},
|
||||
|
@ -31,15 +31,7 @@ return {
|
||||
keys = {
|
||||
{
|
||||
"<leader>co",
|
||||
function()
|
||||
vim.lsp.buf.code_action({
|
||||
apply = true,
|
||||
context = {
|
||||
only = { "source.organizeImports" },
|
||||
diagnostics = {},
|
||||
},
|
||||
})
|
||||
end,
|
||||
LazyVim.lsp.action["source.organizeImports"],
|
||||
desc = "Organize Imports",
|
||||
},
|
||||
},
|
||||
|
@ -85,30 +85,22 @@ return {
|
||||
},
|
||||
{
|
||||
"<leader>co",
|
||||
function()
|
||||
require("vtsls").commands.organize_imports(0)
|
||||
end,
|
||||
LazyVim.lsp.action["source.organizeImports"],
|
||||
desc = "Organize Imports",
|
||||
},
|
||||
{
|
||||
"<leader>cM",
|
||||
function()
|
||||
require("vtsls").commands.add_missing_imports(0)
|
||||
end,
|
||||
LazyVim.lsp.action["source.addMissingImports.ts"],
|
||||
desc = "Add missing imports",
|
||||
},
|
||||
{
|
||||
"<leader>cu",
|
||||
function()
|
||||
require("vtsls").commands.remove_unused_imports(0)
|
||||
end,
|
||||
LazyVim.lsp.action["source.removeUnused.ts"],
|
||||
desc = "Remove unused imports",
|
||||
},
|
||||
{
|
||||
"<leader>cD",
|
||||
function()
|
||||
require("vtsls").commands.fix_all(0)
|
||||
end,
|
||||
LazyVim.lsp.action["source.fixAll.ts"],
|
||||
desc = "Fix all diagnostics",
|
||||
},
|
||||
{
|
||||
|
@ -27,21 +27,7 @@ function M.get()
|
||||
{ "<leader>cC", vim.lsp.codelens.refresh, desc = "Refresh & Display Codelens", mode = { "n" }, has = "codeLens" },
|
||||
{ "<leader>cR", LazyVim.lsp.rename_file, desc = "Rename File", mode ={"n"}, has = { "workspace/didRenameFiles", "workspace/willRenameFiles" } },
|
||||
{ "<leader>cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" },
|
||||
{
|
||||
"<leader>cA",
|
||||
function()
|
||||
vim.lsp.buf.code_action({
|
||||
context = {
|
||||
only = {
|
||||
"source",
|
||||
},
|
||||
diagnostics = {},
|
||||
},
|
||||
})
|
||||
end,
|
||||
desc = "Source Action",
|
||||
has = "codeAction",
|
||||
},
|
||||
{ "<leader>cA", LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" },
|
||||
{ "]]", function() LazyVim.lsp.words.jump(vim.v.count1) end, has = "documentHighlight",
|
||||
desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end },
|
||||
{ "[[", function() LazyVim.lsp.words.jump(-vim.v.count1) end, has = "documentHighlight",
|
||||
|
@ -324,4 +324,17 @@ function M.words.jump(count, cycle)
|
||||
end
|
||||
end
|
||||
|
||||
M.action = setmetatable({}, {
|
||||
__index = function(_, action)
|
||||
return function()
|
||||
vim.lsp.buf.code_action({
|
||||
apply = true,
|
||||
context = {
|
||||
only = { action },
|
||||
diagnostics = {},
|
||||
},
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
return M
|
||||
|
Reference in New Issue
Block a user