vim/lsp: simplify config, no functional changes
This commit is contained in:
parent
8f54dcfc89
commit
67d18020f6
1 changed files with 67 additions and 75 deletions
|
@ -1,84 +1,76 @@
|
||||||
local custom_server_opts = {
|
local config = function()
|
||||||
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]])
|
|
||||||
client.server_capabilities.semanticTokensProvider = nil
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
local custom_attach = function(client, bufnr)
|
|
||||||
vim.bo.omnifunc = 'v:lua.vim.lsp.omnifunc' -- do completion with <c-x><c-o>
|
|
||||||
|
|
||||||
local map = vim.keymap.set
|
|
||||||
local opts = { buffer = bufnr }
|
|
||||||
|
|
||||||
map('n', '<space>ca', vim.lsp.buf.code_action, opts)
|
|
||||||
map('n', '<space>cf', vim.lsp.buf.format, opts)
|
|
||||||
map('n', 'gD', vim.lsp.buf.declaration, opts)
|
|
||||||
map('n', 'gd', vim.lsp.buf.definition, opts)
|
|
||||||
map('n', 'K', vim.lsp.buf.hover, opts)
|
|
||||||
map('n', 'gi', vim.lsp.buf.implementation, opts)
|
|
||||||
map('n', 'grr', vim.lsp.buf.rename, opts)
|
|
||||||
map('n', 'gt', vim.lsp.buf.type_definition, opts)
|
|
||||||
|
|
||||||
local filetype_attach = custom_filetype_attach[vim.bo.filetype]
|
|
||||||
if filetype_attach then filetype_attach(client, bufnr) end
|
|
||||||
end
|
|
||||||
|
|
||||||
local custom_capabilities = function()
|
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
local has_cmp_nvim_lsp, cmp = pcall(require, 'cmp_nvim_lsp')
|
||||||
local ok, cmp = pcall(require, 'cmp_nvim_lsp')
|
if has_cmp_nvim_lsp then
|
||||||
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
|
local on_attach = function(client, bufnr)
|
||||||
end
|
vim.bo.omnifunc = 'v:lua.vim.lsp.omnifunc' -- do completion with <c-x><c-o>
|
||||||
|
|
||||||
local config = function()
|
local map = vim.keymap.set
|
||||||
local lsp = require 'lspconfig'
|
local opts = { buffer = bufnr }
|
||||||
local capabilities = custom_capabilities()
|
|
||||||
|
|
||||||
require('mason').setup()
|
map('n', '<space>ca', vim.lsp.buf.code_action, opts)
|
||||||
require('mason-lspconfig').setup {
|
map('n', '<space>cf', vim.lsp.buf.format, opts)
|
||||||
handlers = {
|
map('n', 'gD', vim.lsp.buf.declaration, opts)
|
||||||
function(server)
|
map('n', 'gd', vim.lsp.buf.definition, opts)
|
||||||
local common_opts = {
|
map('n', 'K', vim.lsp.buf.hover, opts)
|
||||||
on_attach = custom_attach,
|
map('n', 'gi', vim.lsp.buf.implementation, opts)
|
||||||
capabilities = capabilities,
|
map('n', 'grr', vim.lsp.buf.rename, opts)
|
||||||
}
|
map('n', 'gt', vim.lsp.buf.type_definition, opts)
|
||||||
local server_opts = custom_server_opts[server] or {}
|
|
||||||
local opts = vim.tbl_extend('force', common_opts, server_opts)
|
-- Opt out of semantic highlighting because it has been casusing the issues
|
||||||
lsp[server].setup(opts)
|
-- described here: https://github.com/williamboman/mason-lspconfig.nvim/issues/211#issuecomment-1528817490
|
||||||
end,
|
client.server_capabilities.semanticTokensProvider = nil
|
||||||
}
|
end
|
||||||
|
|
||||||
|
require('mason').setup {}
|
||||||
|
require('mason-lspconfig').setup {}
|
||||||
|
require("mason-lspconfig").setup_handlers {
|
||||||
|
-- Default handler.
|
||||||
|
function(server)
|
||||||
|
require('lspconfig')[server].setup {
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
|
||||||
|
lua_ls = function()
|
||||||
|
require('lspconfig').lua_ls.setup {
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
|
||||||
|
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,
|
||||||
|
|
||||||
|
omnisharp = function()
|
||||||
|
require('lspconfig').omnisharp.setup {
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
|
||||||
|
-- Show unimported types and add`using` directives.
|
||||||
|
enable_import_completion = true,
|
||||||
|
|
||||||
|
-- Don't include preview versions of the .NET SDK.
|
||||||
|
sdk_include_prereleases = false,
|
||||||
|
}
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue