From 2dfd39b1bc4be193df2ad5c65d1b1de63a6b0654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20L=C3=BCdecke?= Date: Mon, 9 Sep 2024 13:25:17 +0200 Subject: [PATCH] Properly configured vue language server finally - all language servers now use on_attach to get proper keybindings --- lua/lsp.lua | 73 +++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/lua/lsp.lua b/lua/lsp.lua index 253cce3..f718b08 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -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({ - 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({ - on_attach = on_attach +-- 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, + 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 })