vim: refactor LSP configuration
This commit is contained in:
parent
1108538484
commit
43b65bf2c1
1 changed files with 65 additions and 68 deletions
|
@ -6,41 +6,37 @@ M.dependencies = {
|
||||||
'Hoffs/omnisharp-extended-lsp.nvim',
|
'Hoffs/omnisharp-extended-lsp.nvim',
|
||||||
}
|
}
|
||||||
|
|
||||||
M.event = {
|
M.event = { 'BufReadPre', 'BufNewFile' }
|
||||||
'BufReadPre',
|
|
||||||
'BufNewFile',
|
|
||||||
}
|
|
||||||
|
|
||||||
M.config = function(--[[plugin]]_, --[[opts]]_)
|
M.config = function( --[[plugin]] _, --[[opts]] _)
|
||||||
local border = { border = 'rounded' }
|
local border = { border = 'rounded' }
|
||||||
|
|
||||||
local default_opts = {
|
local defaults = {
|
||||||
capabilities = vim.tbl_deep_extend(
|
capabilities = vim.tbl_deep_extend('force',
|
||||||
'force',
|
|
||||||
vim.lsp.protocol.make_client_capabilities(),
|
vim.lsp.protocol.make_client_capabilities(),
|
||||||
vim.F.npcall(function() require('cmp_nvim_lsp').default_capabilities() end) or {}
|
vim.F.npcall(function() require('cmp_nvim_lsp').default_capabilities() end) or {}),
|
||||||
),
|
|
||||||
|
|
||||||
handlers = {
|
handlers = {
|
||||||
['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, border),
|
['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, border),
|
||||||
['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, border),
|
['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, border),
|
||||||
},
|
},
|
||||||
|
|
||||||
on_attach = function(--[[client]]_, bufnr)
|
on_attach = function( --[[client]] _, buffer)
|
||||||
vim.bo.omnifunc = 'v:lua.vim.lsp.omnifunc' -- do completion with <c-x><c-o>
|
local map = vim.keymap.set
|
||||||
local map, opts = vim.keymap.set, { buffer = bufnr }
|
local buf = vim.lsp.buf
|
||||||
map('n', '<localleader>c', vim.lsp.buf.code_action, opts)
|
local map_opts = { buffer = buffer }
|
||||||
map('n', '<localleader>f', vim.lsp.buf.format, opts)
|
map('n', '<localleader>c', buf.code_action, map_opts)
|
||||||
map('n', 'gd', vim.lsp.buf.definition, opts)
|
map('n', '<localleader>f', buf.format, map_opts)
|
||||||
map('n', 'gD', vim.lsp.buf.declaration, opts)
|
map('n', 'gd', buf.definition, map_opts)
|
||||||
map('n', 'gi', vim.lsp.buf.implementation, opts)
|
map('n', 'gD', buf.declaration, map_opts)
|
||||||
map('n', 'grr', vim.lsp.buf.rename, opts)
|
map('n', 'gi', buf.implementation, map_opts)
|
||||||
map('n', 'gt', vim.lsp.buf.type_definition, opts)
|
map('n', 'grr', buf.rename, map_opts)
|
||||||
map('n', 'K', vim.lsp.buf.hover, opts)
|
map('n', 'gt', buf.type_definition, map_opts)
|
||||||
map('i', '<c-l>', vim.lsp.buf.signature_help, opts)
|
map('n', 'K', buf.hover, map_opts)
|
||||||
|
map('i', '<c-l>', buf.signature_help, map_opts)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_init = function(client, --[[init_result]]_)
|
on_init = function(client, --[[init_result]] _)
|
||||||
-- Opt out of semantic highlighting because it has been causing the issues
|
-- Opt out of semantic highlighting because it has been causing the issues
|
||||||
-- https://github.com/neovim/nvim-lspconfig/issues/2542#issuecomment-1547019213
|
-- https://github.com/neovim/nvim-lspconfig/issues/2542#issuecomment-1547019213
|
||||||
if client.server_capabilities then
|
if client.server_capabilities then
|
||||||
|
@ -49,37 +45,28 @@ M.config = function(--[[plugin]]_, --[[opts]]_)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
require('lspconfig.ui.windows').default_options = border
|
local server_opts = setmetatable({
|
||||||
require('mason').setup { ui = border }
|
lua_ls = function(opts)
|
||||||
require('mason-lspconfig').setup {
|
return vim.tbl_deep_extend('force', opts, {
|
||||||
handlers = {
|
|
||||||
--[[default =]] function(server)
|
|
||||||
require('lspconfig')[server].setup(default_opts)
|
|
||||||
end,
|
|
||||||
|
|
||||||
lua_ls = function(--[[server]]_)
|
|
||||||
local opts = vim.tbl_deep_extend('force', default_opts, {
|
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
-- I'm using lua only inside neovim, so the runtime is LuaJIT.
|
-- I'm using lua only inside neovim, so the runtime is LuaJIT.
|
||||||
runtime = { version = 'LuaJIT' },
|
runtime = { version = 'LuaJIT' },
|
||||||
|
|
||||||
-- Get the language server to recognize the `vim` global.
|
-- Get the language server to recognize the `vim` global.
|
||||||
diagnostics = { globals = {'vim'} },
|
diagnostics = { globals = { 'vim' } },
|
||||||
|
|
||||||
-- Make the server aware of Neovim runtime files.
|
-- Make the server aware of Neovim runtime files.
|
||||||
workspace = { library = vim.api.nvim_get_runtime_file("", true) },
|
workspace = { library = vim.api.nvim_get_runtime_file('', true) },
|
||||||
|
|
||||||
-- Do not send telemetry data containing a randomized but unique identifier
|
-- Do not send telemetry data containing a randomized but unique identifier
|
||||||
telemetry = { enable = false },
|
telemetry = { enable = false },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
require('lspconfig').lua_ls.setup(opts)
|
|
||||||
end,
|
end,
|
||||||
|
omnisharp = function(opts)
|
||||||
omnisharp = function(--[[server]]_)
|
return vim.tbl_deep_extend('force', opts, {
|
||||||
local opts = vim.tbl_deep_extend('force', default_opts, {
|
|
||||||
-- Use .editoconfig for code style, naming convention and analyzer settings.
|
-- Use .editoconfig for code style, naming convention and analyzer settings.
|
||||||
enable_editorconfig_support = true,
|
enable_editorconfig_support = true,
|
||||||
|
|
||||||
|
@ -92,15 +79,25 @@ M.config = function(--[[plugin]]_, --[[opts]]_)
|
||||||
-- Don't include preview versions of the .NET SDK.
|
-- Don't include preview versions of the .NET SDK.
|
||||||
sdk_include_prereleases = false,
|
sdk_include_prereleases = false,
|
||||||
|
|
||||||
handlers = {
|
handlers = { ['textDocument/definition'] = require('omnisharp_extended').handler },
|
||||||
['textDocument/definition'] = require('omnisharp_extended').handler,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
require('lspconfig').omnisharp.setup(opts)
|
end,
|
||||||
|
}, {
|
||||||
|
__index = function( --[[tbl]] _, --[[key]] _)
|
||||||
|
return function(opts) return opts end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
require('lspconfig.ui.windows').default_options = border
|
||||||
|
require('mason').setup { ui = border }
|
||||||
|
require('mason-lspconfig').setup {
|
||||||
|
handlers = {
|
||||||
|
function(server_name)
|
||||||
|
local opts = server_opts[server_name](defaults)
|
||||||
|
require('lspconfig')[server_name].setup(opts)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue