diff --git a/lua/lazyvim/plugins/extras/lang/typescript.lua b/lua/lazyvim/plugins/extras/lang/typescript.lua index 4f53ae8c..297bfc1b 100644 --- a/lua/lazyvim/plugins/extras/lang/typescript.lua +++ b/lua/lazyvim/plugins/extras/lang/typescript.lua @@ -1,3 +1,15 @@ +local source_action = function(name) + return function() + vim.lsp.buf.code_action({ + apply = true, + context = { + only = { string.format("source.%s.ts", name) }, + diagnostics = {}, + }, + }) + end +end + return { -- add typescript to treesitter @@ -21,28 +33,17 @@ return { keys = { { "co", - function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { "source.organizeImports.ts" }, - diagnostics = {}, - }, - }) - end, + source_action("organizeImports"), desc = "Organize Imports", }, + { + "cM", + source_action("addMissingImports"), + desc = "Add Missing Imports", + }, { "cR", - function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { "source.removeUnused.ts" }, - diagnostics = {}, - }, - }) - end, + source_action("removeUnused"), desc = "Remove Unused Imports", }, },