mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-22 08:53:33 +02:00
feat(lsp): simpler API to deal with code actions
This commit is contained in:
parent
e0a0123b18
commit
1bd4d2fc72
5 changed files with 20 additions and 45 deletions
|
@ -53,15 +53,7 @@ return {
|
||||||
keys = {
|
keys = {
|
||||||
{
|
{
|
||||||
"<leader>co",
|
"<leader>co",
|
||||||
function()
|
LazyVim.lsp.action["source.organizeImports"],
|
||||||
vim.lsp.buf.code_action({
|
|
||||||
apply = true,
|
|
||||||
context = {
|
|
||||||
only = { "source.organizeImports" },
|
|
||||||
diagnostics = {},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
desc = "Organize Imports",
|
desc = "Organize Imports",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,15 +31,7 @@ return {
|
||||||
keys = {
|
keys = {
|
||||||
{
|
{
|
||||||
"<leader>co",
|
"<leader>co",
|
||||||
function()
|
LazyVim.lsp.action["source.organizeImports"],
|
||||||
vim.lsp.buf.code_action({
|
|
||||||
apply = true,
|
|
||||||
context = {
|
|
||||||
only = { "source.organizeImports" },
|
|
||||||
diagnostics = {},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
desc = "Organize Imports",
|
desc = "Organize Imports",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -85,30 +85,22 @@ return {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"<leader>co",
|
"<leader>co",
|
||||||
function()
|
LazyVim.lsp.action["source.organizeImports"],
|
||||||
require("vtsls").commands.organize_imports(0)
|
|
||||||
end,
|
|
||||||
desc = "Organize Imports",
|
desc = "Organize Imports",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"<leader>cM",
|
"<leader>cM",
|
||||||
function()
|
LazyVim.lsp.action["source.addMissingImports.ts"],
|
||||||
require("vtsls").commands.add_missing_imports(0)
|
|
||||||
end,
|
|
||||||
desc = "Add missing imports",
|
desc = "Add missing imports",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"<leader>cu",
|
"<leader>cu",
|
||||||
function()
|
LazyVim.lsp.action["source.removeUnused.ts"],
|
||||||
require("vtsls").commands.remove_unused_imports(0)
|
|
||||||
end,
|
|
||||||
desc = "Remove unused imports",
|
desc = "Remove unused imports",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"<leader>cD",
|
"<leader>cD",
|
||||||
function()
|
LazyVim.lsp.action["source.fixAll.ts"],
|
||||||
require("vtsls").commands.fix_all(0)
|
|
||||||
end,
|
|
||||||
desc = "Fix all diagnostics",
|
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>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", 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>cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" },
|
||||||
{
|
{ "<leader>cA", LazyVim.lsp.action.source, desc = "Source Action", has = "codeAction" },
|
||||||
"<leader>cA",
|
|
||||||
function()
|
|
||||||
vim.lsp.buf.code_action({
|
|
||||||
context = {
|
|
||||||
only = {
|
|
||||||
"source",
|
|
||||||
},
|
|
||||||
diagnostics = {},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
desc = "Source Action",
|
|
||||||
has = "codeAction",
|
|
||||||
},
|
|
||||||
{ "]]", function() LazyVim.lsp.words.jump(vim.v.count1) end, has = "documentHighlight",
|
{ "]]", function() LazyVim.lsp.words.jump(vim.v.count1) end, has = "documentHighlight",
|
||||||
desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end },
|
desc = "Next Reference", cond = function() return LazyVim.lsp.words.enabled end },
|
||||||
{ "[[", function() LazyVim.lsp.words.jump(-vim.v.count1) end, has = "documentHighlight",
|
{ "[[", function() LazyVim.lsp.words.jump(-vim.v.count1) end, has = "documentHighlight",
|
||||||
|
|
|
@ -324,4 +324,17 @@ function M.words.jump(count, cycle)
|
||||||
end
|
end
|
||||||
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
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue