feat: nvim-lspconfig (works)

This commit is contained in:
punkfairie 2024-12-31 16:20:48 -08:00
parent 637376a091
commit 014254e4ee
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696

View file

@ -1,73 +1,50 @@
return { return {
'nvim-lspconfig', 'nvim-lspconfig',
event = { 'BufReadPost', 'BufWritePost', 'BufNewFile' }, event = { 'BufRead', 'BufWinEnter', 'BufNewFile' },
before = function() cmd = { 'LspStart', 'LspRestart', 'LspStop', 'LspLog' },
require('lz.n').trigger_load('blink.cmp')
end,
after = function() after = function()
local i = require('icons') local i = require('icons')
local opts = { -- Diagnostics -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
---@class vim.diagnostic.Opts ---@type vim.diagnostic.Opts
diagnostics = { local diagnosticConfig = {
underline = true, underline = true,
update_in_insert = false, update_in_insert = true,
virtual_text = { virtual_text = {
spacing = 4, spacing = 4,
source = 'if_many', source = 'if_many',
prefix = function(diagnostic) prefix = function(diagnostic)
for d, icon in pairs(i.diagnostics) do for d, icon in pairs(i.diagnostics) do
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
return icon return icon
end
end end
end
return '' return ''
end, end,
},
severity_sort = true,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = i.diagnostics.Error,
[vim.diagnostic.severity.WARN] = i.diagnostics.Warn,
[vim.diagnostic.severity.HINT] = i.diagnostics.Hint,
[vim.diagnostic.severity.INFO] = i.diagnostics.Info,
},
},
}, },
severity_sort = true,
capabilities = { signs = {
workspace = { text = {
fileOperations = { [vim.diagnostic.severity.ERROR] = i.diagnostics.Error,
didRename = true, [vim.diagnostic.severity.WARN] = i.diagnostics.Warn,
willRename = true, [vim.diagnostic.severity.HINT] = i.diagnostics.Hint,
}, [vim.diagnostic.severity.INFO] = i.diagnostics.Info,
},
},
servers = {
lua_ls = {
settings = {
Lua = {
workspace = { checkThirdParty = false },
codeLens = { enable = true },
completion = { callSnippet = 'Replace' },
doc = { privateName = { '^_' } },
hint = {
enable = true,
setType = false,
paramType = true,
paramName = 'Disable',
semicolon = 'Disable',
arrayIndex = 'Disable',
},
},
},
}, },
}, },
} }
-- Codelens. for severity, icon in pairs(diagnosticConfig.signs.text) do
local name =
vim.diagnostic.severity[severity]:lower():gsub('^%l', string.upper)
name = 'DiagnosticSign' .. name
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = '' })
end
vim.diagnostic.config(diagnosticConfig)
-- Codelens -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
vim.api.nvim_create_autocmd('User', { vim.api.nvim_create_autocmd('User', {
pattern = 'LspSupportsMethod', pattern = 'LspSupportsMethod',
callback = function(args) callback = function(args)
@ -88,44 +65,59 @@ return {
end, end,
}) })
-- Diagnostics. -- Server Setup -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
-- Server setup.
local has_blink, blink = pcall(require, 'blink.cmp') local has_blink, blink = pcall(require, 'blink.cmp')
local capabilities = vim.tbl_deep_extend( local capabilities = vim.tbl_deep_extend(
'force', 'force',
{}, {},
vim.lsp.protocol.make_client_capabilities(), vim.lsp.protocol.make_client_capabilities(),
has_blink and blink.get_lsp_capabilities() or {}, has_blink and blink.get_lsp_capabilities() or {},
opts.capabilities {
workspace = {
fileOperations = {
didRename = true,
willRename = true,
},
},
}
) )
local function setup(server) local lspconfig = require('lspconfig')
local server_opts = vim.tbl_deep_extend('force', {
capabilities = vim.deepcopy(capabilities),
}, opts.servers[server] or {})
if server_opts.enabled == false then lspconfig.util.default_config = vim.tbl_extend(
return 'force',
end lspconfig.util.default_config,
{ capabilities = capabilities }
)
if opts.setup and opts.setup[server] then lspconfig.lua_ls.setup({
if opts.setup[server](server, server_opts) then settings = {
return Lua = {
end workspace = {
end checkThirdParty = false,
},
codeLens = {
enable = true,
},
completion = {
callSnippet = 'Replace',
},
doc = {
privateName = { '^_' },
},
hint = {
enable = true,
setType = false,
paramType = true,
paramName = 'Disable',
semicolon = 'Disable',
arrayIndex = 'Disable',
},
},
},
})
require('lspconfig')[server].setup(server_opts) -- Keymaps -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
end
for server, server_opts in pairs(opts.servers) do
if server_opts.enabled ~= false then
setup(server)
end
end
-- Set keymaps.
vim.api.nvim_create_autocmd('LspAttach', { vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args) callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id) local client = vim.lsp.get_client_by_id(args.data.client_id)