Properly configured vue language server finally

- all language servers now use on_attach to get proper keybindings
This commit is contained in:
2024-09-09 13:25:17 +02:00
parent 6b2f48285a
commit 2dfd39b1bc

View File

@@ -17,18 +17,10 @@ require('mason-lspconfig').setup({
'yamlls', 'yamlls',
'tsserver', 'tsserver',
'gopls', 'gopls',
'vuels' -- 'volar',
}, },
}) })
-- Set different settings for different languages' LSP
-- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- How to use setup({}): https://github.com/neovim/nvim-lspconfig/wiki/Understanding-setup-%7B%7D
-- - the settings table is sent to the LSP
-- - on_attach: a lua callback function to run after LSP attaches to a given buffer
local lspconfig = require('lspconfig')
-- Customized on_attach function -- Customized on_attach function
-- See `:help vim.diagnostic.*` for documentation on any of the below functions -- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
@@ -64,28 +56,43 @@ local on_attach = function(client, bufnr)
end, bufopts) end, bufopts)
end end
-- Configure each language -- Set different settings for different languages' LSP
-- How to add LSP for a specific language? -- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- 1. use `:Mason` to install corresponding LSP -- How to use setup({}): https://github.com/neovim/nvim-lspconfig/wiki/Understanding-setup-%7B%7D
-- 2. add configuration below -- - the settings table is sent to the LSP
lspconfig.pylsp.setup({ -- - on_attach: a lua callback function to run after LSP attaches to a given buffer
on_attach = on_attach, local lspconfig = require('lspconfig')
})
lspconfig.vuels.setup({ -- from :h mason-lspconfig-automatic-server-setup
on_attach = on_attach require('mason-lspconfig').setup_handlers({
}) -- The first entry (without a key) will be the default handler
lspconfig.rust_analyzer.setup({ -- and will be called for each installed server that doesn't have
on_attach = on_attach -- a dedicated handler.
}) function(server_name) -- default handler (optional)
lspconfig.lua_ls.setup({ if server_name == 'tsserver' then
on_attach = on_attach -- taken from https://github.com/vuejs/language-tools
}) -- If you are using mason.nvim, you can get the ts_plugin_path like this
lspconfig.yamlls.setup({ local mason_registry = require('mason-registry')
on_attach = on_attach local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() ..
}) '/node_modules/@vue/language-server'
lspconfig.tsserver.setup({
on_attach = on_attach lspconfig[server_name].setup {
}) on_attach = on_attach,
lspconfig.gopls.setup({ init_options = {
on_attach = on_attach plugins = {
{
name = '@vue/typescript-plugin',
location = vue_language_server_path,
languages = { 'vue' },
},
},
},
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
}
else
lspconfig[server_name].setup {
on_attach = on_attach
}
end
end
}) })