nvim: inline mason-lsp config

This commit is contained in:
He4eT 2024-04-04 00:24:06 +02:00
commit 41805c8b0f

View file

@ -531,6 +531,10 @@ local on_attach = function(_, bufnr)
end, { desc = 'Format current buffer with LSP' }) end, { desc = 'Format current buffer with LSP' })
end end
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- Enable the following language servers -- Enable the following language servers
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
-- --
@ -538,82 +542,68 @@ end
-- the `settings` field of the server config. You must look up that documentation yourself. -- the `settings` field of the server config. You must look up that documentation yourself.
local servers = { local servers = {
lua_ls = { lua_ls = {
Lua = { settings = {
workspace = { checkThirdParty = false }, Lua = {
telemetry = { enable = false }, workspace = { checkThirdParty = false },
diagnostics = { telemetry = { enable = false },
-- Get the language server to recognize the `vim` global diagnostics = {
globals = { -- Get the language server to recognize the `vim` global
'vim', globals = {
'require', 'vim',
'require',
},
}, },
}, },
}, },
}, },
tsserver = {
on_attach = on_attach,
capabilities = capabilities,
init_options = {
plugins = {
{
name = '@vue/typescript-plugin',
location = require('mason-registry')
.get_package('vue-language-server')
:get_install_path() .. '/node_modules/@vue/language-server',
languages = { 'vue' },
},
},
},
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
handlers = {
-- Usually gets called after a code action
-- like in moving an anonymous function to outer scope
-- https://github.com/jose-elias-alvarez/typescript.nvim/issues/17
['_typescript.rename'] = function(_, result)
return result
end,
-- 'Go to definition' workaround
-- https://github.com/holoiii/nvim/commit/73a4db74fe463f5064346ba63870557fedd134ad
['textDocument/definition'] = function(err, result, ...)
result = vim.tbl_islist(result) and result[1] or result
vim.lsp.handlers['textDocument/definition'](err, result, ...)
end,
},
},
volar = {}, volar = {},
} }
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers require('mason-lspconfig').setup {
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- Ensure the servers above are installed
local mason_lspconfig = require 'mason-lspconfig'
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers), ensure_installed = vim.tbl_keys(servers),
} handlers = {
function(server_name)
mason_lspconfig.setup_handlers { local server = servers[server_name] or {}
function(server_name) server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
require('lspconfig')[server_name].setup { require('lspconfig')[server_name].setup(server)
capabilities = capabilities, end,
on_attach = on_attach, },
settings = servers[server_name],
}
end,
} }
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
border = 'solid', border = 'solid',
}) })
require('lspconfig').tsserver.setup {
on_attach = on_attach,
capabilities = capabilities,
init_options = {
plugins = {
{
name = '@vue/typescript-plugin',
location = require('mason-registry')
.get_package('vue-language-server')
:get_install_path() .. '/node_modules/@vue/language-server',
languages = { 'vue' },
},
},
},
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
handlers = {
-- Usually gets called after a code action
-- like in moving an anonymous function to outer scope
-- https://github.com/jose-elias-alvarez/typescript.nvim/issues/17
['_typescript.rename'] = function(_, result)
local line = result.position.line
local character = result.position.character
local column = vim.str_byteindex(vim.fn.getline '.', character, true)
vim.api.nvim_win_set_cursor(0, { line + 1, column })
vim.lsp.buf.rename()
return result
end,
-- 'Go to definition' workaround
-- https://github.com/holoiii/nvim/commit/73a4db74fe463f5064346ba63870557fedd134ad
['textDocument/definition'] = function(err, result, ...)
result = vim.tbl_islist(result) and result[1] or result
vim.lsp.handlers['textDocument/definition'](err, result, ...)
end,
},
}
-- nvim-cmp setup -- nvim-cmp setup
local cmp = require 'cmp' local cmp = require 'cmp'
local luasnip = require 'luasnip' local luasnip = require 'luasnip'