update vtsls config

add organize imports
This commit is contained in:
xfy
2024-07-30 10:23:15 +08:00
parent cc896200c2
commit 294b9c60bd
3 changed files with 53 additions and 76 deletions

View File

@ -2,26 +2,8 @@ local on_attach = require("nvchad.configs.lspconfig").on_attach
local capabilities = require("nvchad.configs.lspconfig").capabilities
local lspconfig = require("lspconfig")
--[[ local lspconfig_configs = require("lspconfig.configs") ]]
local util = require("lspconfig/util")
local function organize_imports()
local params = {
command = "_typescript.organizeImports",
arguments = { vim.api.nvim_buf_get_name(0) },
}
vim.lsp.buf.execute_command(params)
end
local mason_registry = require("mason-registry")
local has_volar, volar = pcall(mason_registry.get_package, "vue-language-server")
-- npm i -g @vue/typescript-plugin
local vue_language_server_path
if has_volar then
vue_language_server_path = volar:get_install_path() .. "/node_modules/@vue/language-server"
end
require("mason-lspconfig").setup_handlers({
function(server)
local server_config = {
@ -52,53 +34,8 @@ lspconfig["rust_analyzer"].setup({
settings = rust_config,
})
lspconfig.vtsls.setup {
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
settings = {
vtsls = {
-- autoUseWorkspaceTsdk = true,
tsserver = {
globalPlugins = {
{
name = '@vue/typescript-plugin',
location = vue_language_server_path,
languages = { 'vue' },
configNamespace = "typescript",
enableForWorkspaceTypeScriptVersions = true,
},
},
},
},
},
commands = {
OrganizeImports = {
organize_imports,
description = "Organize Imports",
},
},
on_attach = on_attach,
capabilities = capabilities,
}
--[[ lspconfig.vtsls.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "typescript", "javascript", "javascriptreact", "typescriptreact", "vue" },
init_options = {
plugins = {
{
name = "@vue/typescript-plugin",
location = vue_language_server_path,
languages = { "vue" },
},
},
},
commands = {
OrganizeImports = {
organize_imports,
description = "Organize Imports",
},
},
}) ]]
local vtsls_config = require("configs.vtsls")
lspconfig.vtsls.setup(vtsls_config)
lspconfig.clangd.setup({
on_attach = on_attach,

51
lua/configs/vtsls.lua Normal file
View File

@ -0,0 +1,51 @@
local on_attach = require("nvchad.configs.lspconfig").on_attach
local capabilities = require("nvchad.configs.lspconfig").capabilities
local function organize_imports()
local params = {
command = "typescript.organizeImports",
arguments = { vim.api.nvim_buf_get_name(0) },
}
vim.lsp.buf.execute_command(params)
end
local mason_registry = require("mason-registry")
local has_volar, volar = pcall(mason_registry.get_package, "vue-language-server")
-- npm i -g @vue/typescript-plugin
local vue_language_server_path
if has_volar then
vue_language_server_path = volar:get_install_path() .. "/node_modules/@vue/language-server"
end
local M = {
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
settings = {
vtsls = {
-- autoUseWorkspaceTsdk = true,
tsserver = {
globalPlugins = {
{
name = '@vue/typescript-plugin',
location = vue_language_server_path,
languages = { 'vue' },
configNamespace = "typescript",
enableForWorkspaceTypeScriptVersions = true,
},
},
},
},
},
single_file_support = true,
commands = {
OrganizeImports = {
organize_imports,
description = "Organize Imports",
},
},
on_attach = on_attach,
capabilities = capabilities,
}
return M

View File

@ -2,12 +2,6 @@ local cmp = require("cmp")
local overrides = require("configs.overrides")
local plugins = {
{
"NvChad/nvcommunity",
--[[ { import = "nvcommunity.git.diffview" }, ]]
--[[ { import = "nvcommunity.git.lazygit" }, ]]
},
-- LSP, formatter, linter
{
"neovim/nvim-lspconfig",
@ -385,11 +379,6 @@ local plugins = {
event = "VeryLazy",
opts = {},
},
--[[ {
"Fildo7525/pretty_hover",
event = "LspAttach",
opts = {},
}, ]]
{
"folke/trouble.nvim",
cmd = "Trouble",