nix/config/nvim/after/plugin/lsp.lua

63 lines
1.5 KiB
Lua

local lsp = require('config.lsp')
vim.diagnostic.config({
signs = false,
float = {
format = function(diagnostic)
return ('%s (%s)'):format(diagnostic.message, diagnostic.source)
end,
header = '',
prefix = ' ',
},
jump = { float = true },
})
vim.lsp.config('*', {
on_attach = lsp.on_attach,
flags = { debounce_text_changes = 0 },
})
for _, server in ipairs({
'bashls',
'basedpyright',
'clangd',
'cssls',
'emmet_language_server',
'eslint',
'html',
'nixd',
'mdx_analyzer',
'jsonls',
'vtsls',
'lua_ls',
'ruff',
'tinymist',
}) do
local ok, config = pcall(require, 'lsp.' .. server)
if ok and config then
vim.lsp.config(server, config)
else
vim.lsp.config(server, {})
end
vim.lsp.enable(server)
end
-- remove duplicate entries from goto defintion list
-- example: https://github.com/LuaLS/lua-language-server/issues/2451
local locations_to_items = vim.lsp.util.locations_to_items
vim.lsp.util.locations_to_items = function(locations, offset_encoding)
local lines = {}
local loc_i = 1
for _, loc in ipairs(vim.deepcopy(locations)) do
local uri = loc.uri or loc.targetUri
local range = loc.range or loc.targetSelectionRange
if lines[uri .. range.start.line] then
table.remove(locations, loc_i)
else
loc_i = loc_i + 1
end
lines[uri .. range.start.line] = true
end
return locations_to_items(locations, offset_encoding)
end