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',
'tsserver',
'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
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true }
@@ -64,28 +56,43 @@ local on_attach = function(client, bufnr)
end, bufopts)
end
-- Configure each language
-- How to add LSP for a specific language?
-- 1. use `:Mason` to install corresponding LSP
-- 2. add configuration below
lspconfig.pylsp.setup({
-- 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')
-- from :h mason-lspconfig-automatic-server-setup
require('mason-lspconfig').setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function(server_name) -- default handler (optional)
if server_name == 'tsserver' then
-- taken from https://github.com/vuejs/language-tools
-- If you are using mason.nvim, you can get the ts_plugin_path like this
local mason_registry = require('mason-registry')
local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() ..
'/node_modules/@vue/language-server'
lspconfig[server_name].setup {
on_attach = on_attach,
})
lspconfig.vuels.setup({
on_attach = on_attach
})
lspconfig.rust_analyzer.setup({
on_attach = on_attach
})
lspconfig.lua_ls.setup({
on_attach = on_attach
})
lspconfig.yamlls.setup({
on_attach = on_attach
})
lspconfig.tsserver.setup({
on_attach = on_attach
})
lspconfig.gopls.setup({
init_options = {
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
})