2024-11-08 16:16:27 +00:00
|
|
|
--
|
|
|
|
-- Start config for builtin Neovim language server protocol client
|
|
|
|
--
|
|
|
|
-- Source: https://github.com/RRethy/vim-illuminate
|
|
|
|
-- ..............................................
|
|
|
|
--
|
|
|
|
-- Author: Sven Vogel
|
|
|
|
-- Created: 08.11.2024
|
|
|
|
-- Edited: 08.11.2024
|
|
|
|
--
|
|
|
|
-- ==============================================
|
|
|
|
|
2024-11-08 17:06:24 +00:00
|
|
|
local ui = require 'config.ui'
|
|
|
|
local icons = require 'config.icons'
|
2024-11-08 16:16:27 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
{
|
|
|
|
'neovim/nvim-lspconfig',
|
|
|
|
dependencies = {
|
|
|
|
"williamboman/mason.nvim",
|
|
|
|
{
|
|
|
|
"williamboman/mason-lspconfig.nvim",
|
|
|
|
config = function()
|
|
|
|
end
|
|
|
|
},
|
|
|
|
},
|
|
|
|
opts = {
|
|
|
|
inlay_hints = {
|
|
|
|
enabled = true,
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
update_in_insert = false,
|
|
|
|
underline = true,
|
|
|
|
severity_sort = false,
|
|
|
|
float = {
|
|
|
|
border = ui.border,
|
|
|
|
source = 'always',
|
|
|
|
},
|
2024-11-08 16:47:59 +00:00
|
|
|
virtual_text = {
|
|
|
|
spacing = 4,
|
|
|
|
source = "if_many",
|
|
|
|
-- this will set set the prefix to a function that returns the diagnostics icon based on the severity
|
|
|
|
-- this only works on a recent 0.10.0 build. Will be set to "●" when not supported
|
|
|
|
prefix = "icons"
|
|
|
|
},
|
|
|
|
signs = {
|
|
|
|
text = {
|
|
|
|
[vim.diagnostic.severity.ERROR] = icons.diagnostics.error,
|
|
|
|
[vim.diagnostic.severity.WARN] = icons.diagnostics.warn,
|
|
|
|
[vim.diagnostic.severity.HINT] = icons.diagnostics.hint,
|
|
|
|
[vim.diagnostic.severity.INFO] = icons.diagnostics.info
|
|
|
|
}
|
|
|
|
}
|
2024-11-08 16:16:27 +00:00
|
|
|
}
|
|
|
|
},
|
2024-11-08 16:47:59 +00:00
|
|
|
config = function(_, opts)
|
2024-11-08 16:16:27 +00:00
|
|
|
require("mason").setup()
|
|
|
|
|
|
|
|
local handlers = {
|
|
|
|
-- The first entry (without a key) will be the default handler
|
|
|
|
-- and will be called for each installed server that doesn't have
|
|
|
|
-- a dedicated handler.
|
|
|
|
function(server_name) -- default handler (optional)
|
|
|
|
require("lspconfig")[server_name].setup({
|
|
|
|
on_attach = function(client, bufnr)
|
2024-11-08 17:06:24 +00:00
|
|
|
-- optionally enable inlay hints
|
|
|
|
-- Source: https://www.reddit.com/r/neovim/comments/14em0f8/how_to_use_the_new_lsp_inlay_hints/
|
|
|
|
-- ..............................................
|
|
|
|
|
|
|
|
if client.server_capabilities.inlayHintProvider and opts.inlay_hints.enabled then
|
|
|
|
vim.lsp.inlay_hint.enable(true, { bufnr })
|
|
|
|
end
|
2024-11-08 16:16:27 +00:00
|
|
|
end
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
require("mason-lspconfig").setup({ handlers = handlers })
|
|
|
|
|
2024-11-08 16:47:59 +00:00
|
|
|
-- Setup diagnostic signs
|
|
|
|
--
|
|
|
|
-- Source: https://www.lazyvim.org/plugins/lsp#mason-lspconfignvim
|
|
|
|
-- ..............................................
|
|
|
|
|
|
|
|
-- diagnostics signs
|
|
|
|
if type(opts.diagnostics.signs) ~= "boolean" then
|
|
|
|
for severity, icon in pairs(opts.diagnostics.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
|
|
|
|
end
|
|
|
|
|
|
|
|
-- diagnostic sign as prefix for virtual text
|
|
|
|
if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then
|
|
|
|
opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and "●" or function(diagnostic)
|
|
|
|
for d, icon in pairs(icons.diagnostics) do
|
|
|
|
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
|
|
|
|
return icon
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-11-08 16:16:27 +00:00
|
|
|
-- Setup diagnostic user interface
|
|
|
|
--
|
|
|
|
-- Source: https://vonheikemen.github.io/devlog/tools/setup-nvim-lspconfig-plus-nvim-cmp
|
|
|
|
-- ..............................................
|
|
|
|
|
|
|
|
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
|
|
|
|
vim.lsp.handlers.hover,
|
|
|
|
{
|
|
|
|
border = ui.border
|
|
|
|
})
|
|
|
|
|
|
|
|
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
|
|
|
|
vim.lsp.handlers.signature_help,
|
|
|
|
{
|
|
|
|
border = ui.border
|
|
|
|
})
|
2024-11-08 17:22:53 +00:00
|
|
|
|
2024-11-08 16:16:27 +00:00
|
|
|
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
|
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|