feat(typescript)!: the typescript extra now uses vtsls instead of tsserver. You may want to update your lsp settings.
This commit is contained in:
@ -1,14 +1,3 @@
|
||||
local inlay_hints_settings = {
|
||||
includeInlayEnumMemberValueHints = true,
|
||||
includeInlayFunctionLikeReturnTypeHints = true,
|
||||
includeInlayFunctionParameterTypeHints = true,
|
||||
includeInlayParameterNameHints = "literals",
|
||||
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
||||
includeInlayPropertyDeclarationTypeHints = true,
|
||||
includeInlayVariableTypeHints = false,
|
||||
includeInlayVariableTypeHintsWhenTypeMatchesName = false,
|
||||
}
|
||||
|
||||
return {
|
||||
recommended = function()
|
||||
return LazyVim.extras.wants({
|
||||
@ -24,13 +13,12 @@ return {
|
||||
})
|
||||
end,
|
||||
|
||||
-- add typescript to treesitter
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
opts = function(_, opts)
|
||||
if type(opts.ensure_installed) == "table" then
|
||||
vim.list_extend(opts.ensure_installed, { "typescript", "tsx" })
|
||||
end
|
||||
"yioneko/nvim-vtsls",
|
||||
lazy = true,
|
||||
opts = {},
|
||||
config = function(_, opts)
|
||||
require("vtsls").config(opts)
|
||||
end,
|
||||
},
|
||||
|
||||
@ -40,52 +28,85 @@ return {
|
||||
opts = {
|
||||
-- make sure mason installs the server
|
||||
servers = {
|
||||
---@type lspconfig.options.tsserver
|
||||
tsserver = {
|
||||
enabled = false,
|
||||
},
|
||||
vtsls = {
|
||||
settings = {
|
||||
complete_function_calls = true,
|
||||
typescript = {
|
||||
updateImportsOnFileMove = { enabled = "always" },
|
||||
enableMoveToFileCodeAction = true,
|
||||
experimental = {
|
||||
completion = {
|
||||
enableServerSideFuzzyMatch = true,
|
||||
},
|
||||
},
|
||||
suggest = {
|
||||
completeFunctionCalls = true,
|
||||
},
|
||||
inlayHints = {
|
||||
enumMemberValues = { enabled = true },
|
||||
functionLikeReturnTypes = { enabled = true },
|
||||
parameterNames = { enabled = "literals" },
|
||||
parameterTypes = { enabled = true },
|
||||
propertyDeclarationTypes = { enabled = true },
|
||||
variableTypes = { enabled = false },
|
||||
},
|
||||
},
|
||||
},
|
||||
keys = {
|
||||
{
|
||||
"gD",
|
||||
function()
|
||||
require("vtsls").commands.goto_source_definition(0)
|
||||
end,
|
||||
desc = "Goto Source Definition",
|
||||
},
|
||||
{
|
||||
"<leader>co",
|
||||
function()
|
||||
vim.lsp.buf.code_action({
|
||||
apply = true,
|
||||
context = {
|
||||
only = { "source.organizeImports.ts" },
|
||||
diagnostics = {},
|
||||
},
|
||||
})
|
||||
require("vtsls").commands.organize_imports(0)
|
||||
end,
|
||||
desc = "Organize Imports",
|
||||
},
|
||||
{
|
||||
"<leader>cR",
|
||||
"<leader>cM",
|
||||
function()
|
||||
vim.lsp.buf.code_action({
|
||||
apply = true,
|
||||
context = {
|
||||
only = { "source.removeUnused.ts" },
|
||||
diagnostics = {},
|
||||
},
|
||||
})
|
||||
require("vtsls").commands.add_missing_imports(0)
|
||||
end,
|
||||
desc = "Remove Unused Imports",
|
||||
desc = "Add missing imports",
|
||||
},
|
||||
},
|
||||
settings = {
|
||||
typescript = {
|
||||
inlayHints = inlay_hints_settings,
|
||||
},
|
||||
javascript = {
|
||||
inlayHints = inlay_hints_settings,
|
||||
},
|
||||
completions = {
|
||||
completeFunctionCalls = true,
|
||||
{
|
||||
"<leader>cD",
|
||||
function()
|
||||
require("vtsls").commands.fix_all(0)
|
||||
end,
|
||||
desc = "Fix all diagnostics",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
setup = {
|
||||
tsserver = function()
|
||||
-- disable tsserver
|
||||
return true
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
opts = function(_, opts)
|
||||
-- copy typescript settings to javascript
|
||||
opts.servers.vtsls.settings.javascript = vim.deepcopy(opts.servers.vtsls.settings.typescript)
|
||||
|
||||
-- add vtsls to lspconfig
|
||||
require("lspconfig.configs").vtsls = require("vtsls").lspconfig
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
"mfussenegger/nvim-dap",
|
||||
optional = true,
|
||||
|
@ -26,14 +26,18 @@ return {
|
||||
volar = {},
|
||||
-- Volar 2.0 has discontinued their "take over mode" which in previous version provided support for typescript in vue files.
|
||||
-- The new approach to get typescript support involves using the typescript language server along side volar.
|
||||
tsserver = {
|
||||
init_options = {
|
||||
plugins = {
|
||||
-- Use typescript language server along with vue typescript plugin
|
||||
{
|
||||
name = "@vue/typescript-plugin",
|
||||
location = vue_typescript_plugin,
|
||||
languages = { "javascript", "typescript", "vue" },
|
||||
vtsls = {
|
||||
settings = {
|
||||
vtsls = {
|
||||
tsserver = {
|
||||
globalPlugins = {
|
||||
-- Use typescript language server along with vue typescript plugin
|
||||
{
|
||||
name = "@vue/typescript-plugin",
|
||||
location = vue_typescript_plugin,
|
||||
languages = { "vue" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -225,11 +225,13 @@ return {
|
||||
for server, server_opts in pairs(servers) do
|
||||
if server_opts then
|
||||
server_opts = server_opts == true and {} or server_opts
|
||||
-- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
|
||||
if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then
|
||||
setup(server)
|
||||
elseif server_opts.enabled ~= false then
|
||||
ensure_installed[#ensure_installed + 1] = server
|
||||
if server_opts.enabled ~= false then
|
||||
-- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
|
||||
if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then
|
||||
setup(server)
|
||||
else
|
||||
ensure_installed[#ensure_installed + 1] = server
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user