vim/lsp: lazy load

This commit is contained in:
Fernando Schauenburg 2023-08-13 22:40:52 +02:00
parent e36bce4610
commit 52d730a5a2

View file

@ -1,18 +1,27 @@
local config = function() local border = 'rounded'
-- Enable rounded borders for LSP handlers and :LspInfo windows.
local border = 'rounded'
for request, handler in pairs {
['textDocument/hover'] = vim.lsp.handlers.hover,
['textDocument/signatureHelp'] = vim.lsp.handlers.signature_help,
} do
vim.lsp.handlers[request] = vim.lsp.with(handler, { border = border })
end
require('lspconfig.ui.windows').default_options = { border = border }
return {
'neovim/nvim-lspconfig',
dependencies = {
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
},
event = {
'BufReadPost',
'BufNewFile'
},
config = function()
local opts = { local opts = {
capabilities = vim.lsp.protocol.make_client_capabilities(), capabilities = (function()
local caps = vim.lsp.protocol.make_client_capabilities()
local cmp = vim.F.npcall(require, 'cmp_nvim_lsp')
if cmp then
vim.tbl_deep_extend('force', caps, cmp.default_capabilities())
end
return caps
end)(),
on_attach = function(--[[client]]_, bufnr) on_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, opts = vim.keymap.set, { buffer = bufnr } local map, opts = vim.keymap.set, { buffer = bufnr }
map('n', '<localleader>c', vim.lsp.buf.code_action, opts) map('n', '<localleader>c', vim.lsp.buf.code_action, opts)
@ -26,7 +35,7 @@ local config = function()
map('i', '<c-l>', vim.lsp.buf.signature_help, opts) map('i', '<c-l>', vim.lsp.buf.signature_help, opts)
end, end,
on_init = function(client, --[[init_result]]_) on_init = function(client, --[[init_result]] _)
-- Opt out of semantic highlighting because it has been casusing the issues -- Opt out of semantic highlighting because it has been casusing 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
@ -35,18 +44,22 @@ local config = function()
end, end,
} }
local cmp = vim.F.npcall(require, 'cmp_nvim_lsp') -- Enable rounded borders for LSP handlers and :LspInfo windows.
if cmp then for request, handler in pairs {
vim.tbl_deep_extend('force', opts.capabilities, cmp.default_capabilities()) ['textDocument/hover'] = vim.lsp.handlers.hover,
['textDocument/signatureHelp'] = vim.lsp.handlers.signature_help,
} do
vim.lsp.handlers[request] = vim.lsp.with(handler, { border = border })
end end
require('lspconfig.ui.windows').default_options = { border = border }
require('mason').setup { require('mason').setup {
ui = { ui = {
border = 'rounded', border = border,
}, },
} }
require('mason-lspconfig').setup {} require('mason-lspconfig').setup {
require("mason-lspconfig").setup_handlers { handlers = {
--[[ default = ]] function(server) --[[ default = ]] function(server)
require('lspconfig')[server].setup(opts) require('lspconfig')[server].setup(opts)
end, end,
@ -59,10 +72,10 @@ local config = function()
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 },
@ -83,16 +96,8 @@ local config = function()
sdk_include_prereleases = false, sdk_include_prereleases = false,
})) }))
end, end,
}
end
return {
'neovim/nvim-lspconfig',
config = config,
dependencies = {
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
}, },
}
end,
} }