feat: nvim-lspconfig (works)
This commit is contained in:
parent
637376a091
commit
014254e4ee
1 changed files with 77 additions and 85 deletions
|
@ -1,73 +1,50 @@
|
|||
return {
|
||||
'nvim-lspconfig',
|
||||
event = { 'BufReadPost', 'BufWritePost', 'BufNewFile' },
|
||||
before = function()
|
||||
require('lz.n').trigger_load('blink.cmp')
|
||||
end,
|
||||
event = { 'BufRead', 'BufWinEnter', 'BufNewFile' },
|
||||
cmd = { 'LspStart', 'LspRestart', 'LspStop', 'LspLog' },
|
||||
after = function()
|
||||
local i = require('icons')
|
||||
|
||||
local opts = {
|
||||
---@class vim.diagnostic.Opts
|
||||
diagnostics = {
|
||||
underline = true,
|
||||
update_in_insert = false,
|
||||
virtual_text = {
|
||||
spacing = 4,
|
||||
source = 'if_many',
|
||||
prefix = function(diagnostic)
|
||||
for d, icon in pairs(i.diagnostics) do
|
||||
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
|
||||
return icon
|
||||
end
|
||||
-- Diagnostics -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
---@type vim.diagnostic.Opts
|
||||
local diagnosticConfig = {
|
||||
underline = true,
|
||||
update_in_insert = true,
|
||||
virtual_text = {
|
||||
spacing = 4,
|
||||
source = 'if_many',
|
||||
prefix = function(diagnostic)
|
||||
for d, icon in pairs(i.diagnostics) do
|
||||
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
|
||||
return icon
|
||||
end
|
||||
end
|
||||
|
||||
return '●'
|
||||
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,
|
||||
},
|
||||
},
|
||||
return ''
|
||||
end,
|
||||
},
|
||||
|
||||
capabilities = {
|
||||
workspace = {
|
||||
fileOperations = {
|
||||
didRename = true,
|
||||
willRename = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
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',
|
||||
},
|
||||
},
|
||||
},
|
||||
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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- 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', {
|
||||
pattern = 'LspSupportsMethod',
|
||||
callback = function(args)
|
||||
|
@ -88,44 +65,59 @@ return {
|
|||
end,
|
||||
})
|
||||
|
||||
-- Diagnostics.
|
||||
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
|
||||
|
||||
-- Server setup.
|
||||
-- Server Setup -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
local has_blink, blink = pcall(require, 'blink.cmp')
|
||||
local capabilities = vim.tbl_deep_extend(
|
||||
'force',
|
||||
{},
|
||||
vim.lsp.protocol.make_client_capabilities(),
|
||||
has_blink and blink.get_lsp_capabilities() or {},
|
||||
opts.capabilities
|
||||
{
|
||||
workspace = {
|
||||
fileOperations = {
|
||||
didRename = true,
|
||||
willRename = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
local function setup(server)
|
||||
local server_opts = vim.tbl_deep_extend('force', {
|
||||
capabilities = vim.deepcopy(capabilities),
|
||||
}, opts.servers[server] or {})
|
||||
local lspconfig = require('lspconfig')
|
||||
|
||||
if server_opts.enabled == false then
|
||||
return
|
||||
end
|
||||
lspconfig.util.default_config = vim.tbl_extend(
|
||||
'force',
|
||||
lspconfig.util.default_config,
|
||||
{ capabilities = capabilities }
|
||||
)
|
||||
|
||||
if opts.setup and opts.setup[server] then
|
||||
if opts.setup[server](server, server_opts) then
|
||||
return
|
||||
end
|
||||
end
|
||||
lspconfig.lua_ls.setup({
|
||||
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',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
require('lspconfig')[server].setup(server_opts)
|
||||
end
|
||||
|
||||
for server, server_opts in pairs(opts.servers) do
|
||||
if server_opts.enabled ~= false then
|
||||
setup(server)
|
||||
end
|
||||
end
|
||||
|
||||
-- Set keymaps.
|
||||
-- Keymaps -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
callback = function(args)
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
|
|
Loading…
Reference in a new issue