♻️ refactor(nvim): typescript-extended extra now uses vstls instead of typescript-tools and tsserver

This commit is contained in:
Sergio Laín 2024-05-31 21:22:29 +02:00
parent 1f44b1bc01
commit a0c4638365
No known key found for this signature in database
GPG key ID: FB00AF7015FFE76B

View file

@ -1,29 +1,3 @@
local ts_server_activated = true -- Change this variable to false if you want to use typescript-tools instead of lspconfig tsserver implementation
local ft = { "typescript", "typescriptreact", "javascript", "javascriptreact" }
local inlayHints = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayVariableTypeHintsWhenTypeMatchesName = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
}
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 {
{ import = "lazyvim.plugins.extras.lang.typescript" },
{ import = "plugins.extras.lang.json-extended" },
@ -38,106 +12,23 @@ return {
"neovim/nvim-lspconfig",
opts = {
servers = {
tsserver = {
vtsls = {
handlers = {
["textDocument/publishDiagnostics"] = function(err, result, ctx, config)
require("ts-error-translator").translate_diagnostics(err, result, ctx, config)
vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config)
end,
},
enabled = ts_server_activated,
init_options = {
preferences = {
disableSuggestions = true,
},
},
settings = {
typescript = {
inlayHints = inlayHints,
implementationsCodeLens = {
enabled = true,
},
referencesCodeLens = {
enabled = true,
showOnAllFunctions = true,
},
},
javascript = {
inlayHints = inlayHints,
implementationsCodeLens = {
enabled = true,
},
referencesCodeLens = {
enabled = true,
showOnAllFunctions = true,
},
},
},
keys = {
{
"<leader>cO",
source_action("organizeImports"),
desc = "Organize Imports",
},
{
"<leader>cM",
source_action("addMissingImports"),
desc = "Add Missing Imports",
},
{
"<leader>cR",
source_action("removeUnused"),
desc = "Remove Unused Imports",
},
},
},
denols = {},
},
},
},
{
"pmizio/typescript-tools.nvim",
dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
enabled = not ts_server_activated,
ft = ft,
opts = {
cmd = { "typescript-language-server", "--stdio" },
handlers = {
["textDocument/publishDiagnostics"] = function(err, result, ctx, config)
require("ts-error-translator").translate_diagnostics(err, result, ctx, config)
vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config)
end,
},
settings = {
code_lens = "all",
expose_as_code_action = "all",
tsserver_plugins = {
"@styled/typescript-styled-plugin",
},
tsserver_file_preferences = {
completions = {
completeFunctionCalls = true,
},
init_options = {
preferences = {
disableSuggestions = true,
},
},
includeInlayParameterNameHints = "all",
includeInlayEnumMemberValueHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayVariableTypeHints = true,
},
},
},
keys = {
{ "<leader>cO", ft = ft, "<cmd>TSToolsOrganizeImports<cr>", desc = "Organize Imports" },
{ "<leader>cR", ft = ft, "<cmd>TSToolsRemoveUnusedImports<cr>", desc = "Remove Unused Imports" },
{ "<leader>cM", ft = ft, "<cmd>TSToolsAddMissingImports<cr>", desc = "Add Missing Imports" },
},
},
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)