vim: refactor LSP configuration
This commit is contained in:
parent
5ccc32e991
commit
d3089a8b06
1 changed files with 46 additions and 44 deletions
|
@ -1,10 +1,38 @@
|
||||||
local filetypes = {
|
local custom_server_opts = {
|
||||||
|
omnisharp = {
|
||||||
|
-- Support for showing unimported types and adding `using` directives.
|
||||||
|
enable_import_completion = true,
|
||||||
|
|
||||||
|
-- Don't include preview versions of the .NET SDK.
|
||||||
|
sdk_include_prereleases = false,
|
||||||
|
},
|
||||||
|
|
||||||
|
lua_ls = {
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
-- I'm using lua only inside neovim, so the runtime is LuaJIT.
|
||||||
|
runtime = { version = 'LuaJIT' },
|
||||||
|
|
||||||
|
-- Get the language server to recognize the `vim` global.
|
||||||
|
diagnostics = { globals = {'vim'} },
|
||||||
|
|
||||||
|
-- Make the server aware of Neovim runtime files.
|
||||||
|
workspace = { library = vim.api.nvim_get_runtime_file("", true) },
|
||||||
|
|
||||||
|
-- Do not send telemetry data containing a randomized but unique identifier
|
||||||
|
telemetry = { enable = false },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local custom_filetype_attach = {
|
||||||
cs = function(client, bufnr)
|
cs = function(client, bufnr)
|
||||||
client.server_capabilities.semanticTokensProvider = nil
|
client.server_capabilities.semanticTokensProvider = nil
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local on_attach = function(client, bufnr)
|
local custom_attach = function(client, bufnr)
|
||||||
vim.bo.omnifunc = 'v:lua.vim.lsp.omnifunc' -- do completion with <c-x><c-o>
|
vim.bo.omnifunc = 'v:lua.vim.lsp.omnifunc' -- do completion with <c-x><c-o>
|
||||||
|
|
||||||
local map = vim.keymap.set
|
local map = vim.keymap.set
|
||||||
|
@ -19,62 +47,36 @@ local on_attach = function(client, bufnr)
|
||||||
map('n', 'grr', vim.lsp.buf.rename, opts)
|
map('n', 'grr', vim.lsp.buf.rename, opts)
|
||||||
map('n', 'gt', vim.lsp.buf.type_definition, opts)
|
map('n', 'gt', vim.lsp.buf.type_definition, opts)
|
||||||
|
|
||||||
local filetype_attach = filetypes[vim.bo.filetype]
|
local filetype_attach = custom_filetype_attach[vim.bo.filetype]
|
||||||
if filetype_attach then filetype_attach(client, bufnr) end
|
if filetype_attach then filetype_attach(client, bufnr) end
|
||||||
end
|
end
|
||||||
|
|
||||||
local config = function()
|
local custom_capabilities = function()
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
local has_cmp, cmp = pcall(require, 'cmp_nvim_lsp')
|
|
||||||
if has_cmp then
|
local ok, cmp = pcall(require, 'cmp_nvim_lsp')
|
||||||
|
if ok then
|
||||||
vim.tbl_deep_extend('force', capabilities, cmp.default_capabilities())
|
vim.tbl_deep_extend('force', capabilities, cmp.default_capabilities())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return capabilities
|
||||||
|
end
|
||||||
|
|
||||||
|
local config = function()
|
||||||
local lsp = require 'lspconfig'
|
local lsp = require 'lspconfig'
|
||||||
|
local capabilities = custom_capabilities()
|
||||||
|
|
||||||
require('mason').setup()
|
require('mason').setup()
|
||||||
require('mason-lspconfig').setup {
|
require('mason-lspconfig').setup {
|
||||||
handlers = {
|
handlers = {
|
||||||
-- default handler
|
|
||||||
function(server)
|
function(server)
|
||||||
require('lspconfig')[server].setup {
|
local common_opts = {
|
||||||
on_attach = on_attach,
|
on_attach = custom_attach,
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
}
|
}
|
||||||
end,
|
local server_opts = custom_server_opts[server] or {}
|
||||||
|
local opts = vim.tbl_extend('force', common_opts, server_opts)
|
||||||
omnisharp = function()
|
lsp[server].setup(opts)
|
||||||
lsp.omnisharp.setup {
|
|
||||||
on_attach = on_attach,
|
|
||||||
capabilities = capabilities,
|
|
||||||
|
|
||||||
-- Support for showing unimported types and adding `using` directives.
|
|
||||||
enable_import_completion = true,
|
|
||||||
|
|
||||||
-- Don't include preview versions of the .NET SDK.
|
|
||||||
sdk_include_prereleases = false,
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
|
|
||||||
lua_ls = function()
|
|
||||||
lsp.lua_ls.setup {
|
|
||||||
on_attach = on_attach,
|
|
||||||
capabilities = capabilities,
|
|
||||||
settings = {
|
|
||||||
Lua = {
|
|
||||||
-- I'm using lua only inside neovim, so the runtime is LuaJIT.
|
|
||||||
runtime = { version = 'LuaJIT' },
|
|
||||||
|
|
||||||
-- Get the language server to recognize the `vim` global.
|
|
||||||
diagnostics = { globals = {'vim'} },
|
|
||||||
|
|
||||||
-- Make the server aware of Neovim runtime files.
|
|
||||||
workspace = { library = vim.api.nvim_get_runtime_file("", true) },
|
|
||||||
|
|
||||||
-- Do not send telemetry data containing a randomized but unique identifier
|
|
||||||
telemetry = { enable = false },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue