return { -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', dependencies = { -- Automatically install LSPs and related tools to stdpath for neovim 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` { 'j-hui/fidget.nvim', config = function() local fidget = require("fidget") vim.notify = fidget.notify fidget.setup() end }, }, config = function() vim.api.nvim_create_autocmd('LspAttach', { callback = function(event) local map = function(keys, func, desc) vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) end -- map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') map('gd', function() vim.lsp.buf.definition() end, '[G]oto [D]efinition') -- map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') -- map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') map('gd', require('telescope.builtin').lsp_type_definitions, '[G]oto Type [D]efinition') map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') -- map('rn', vim.lsp.buf.rename, '[R]e[n]ame') -- map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') -- map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') map('bf', vim.lsp.buf.format, '[B]uffer [F]ormat') -- The following two autocommands are used to highlight references of the -- word under your cursor when your cursor rests there for a little while. -- See `:help CursorHold` for information about when this is executed -- -- When you move your cursor, the highlights will be cleared (the second autocommand). local client = vim.lsp.get_client_by_id(event.data.client_id) if client and client:supports_method( vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { buffer = event.buf, callback = vim.lsp.buf.clear_references, }) end if client and client:supports_method( vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then map('ti', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) end, "[T]oggle [I]nlay") end -- autoformat vim.api.nvim_create_autocmd("BufWritePre", { buffer = event.buf, callback = function() vim.lsp.buf.format { async = false, id = event.data.client_id } end, }) end, }) -- Ensure the servers and tools above are installed -- To check the current status of installed tools and/or manually install -- other tools, you can run -- :Mason -- -- You can press `g?` for help in this menu require('mason').setup() -- You can add other tools here that you want Mason to install -- for you, so that they are available from within Neovim. require('mason-tool-installer').setup {} require('mason-lspconfig').setup { ensure_installed = { "lua_ls", "rust_analyzer", "ltex_plus" --"ts_ls", "vue_ls", } } vim.lsp.config("lua_ls", { settings = { Lua = { -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings -- diagnostics = { disable = { 'missing-fields' } }, runtime = { version = "LuaJIT", path = vim.split(package.path, ';') }, diagnostics = { globals = { "vim", "require" } }, workspace = { -- library = vim.api.nvim_get_runtime_file('', true) library = { [vim.fn.expand("$VIMRUNTIME/lua")] = true, [vim.fn.stdpath("config") .. "/lua"] = true, ["${3rd}/luv/library"] = true, } } }, } }) local vue_language_server_path = vim.fn.expand '$MASON/packages' .. '/vue-language-server' .. '/node_modules/@vue/language-server' local vue_plugin = { name = '@vue/typescript-plugin', location = vue_language_server_path, languages = { 'vue' }, configNamespace = 'typescript', } local vtsls_config = { settings = { vtsls = { tsserver = { globalPlugins = { vue_plugin, }, }, }, }, filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, } local vue_ls_config = { on_init = function(client) client.handlers['tsserver/request'] = function(_, result, context) local clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'vtsls' }) if #clients == 0 then vim.notify('Could not find `vtsls` lsp client, `vue_ls` would not work without it.', vim.log.levels.ERROR) return end local ts_client = clients[1] local param = unpack(result) local id, command, payload = unpack(param) ts_client:exec_cmd({ title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd` command = 'typescript.tsserverRequest', arguments = { command, payload, }, }, { bufnr = context.bufnr }, function(_, r) local response_data = { { id, r.body } } ---@diagnostic disable-next-line: param-type-mismatch client:notify('tsserver/response', response_data) end) end end, } -- nvim 0.11 or above vim.lsp.config('vtsls', vtsls_config) vim.lsp.config('vue_ls', vue_ls_config) vim.lsp.enable({ 'vtsls', 'vue_ls' }) vim.lsp.config("ltex_plus", { settings = { ltex = { language = "de-DE" } } }) end, }