some lsp configuration

This commit is contained in:
2025-11-16 18:55:41 -05:00
parent 65f8b53cfc
commit e1454ba52f
5 changed files with 141 additions and 1 deletions

65
lua/config/autocmds.lua Normal file
View File

@@ -0,0 +1,65 @@
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
})
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }),
callback = function(event)
-- shortcut for vim.keymap.set
local map = function(keys, func, desc)
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc })
end
-- defaults:
-- https://neovim.io/doc/user/news-0.11.html#_defaults
map("gl", vim.diagnostic.open_float, "Open Diagnostic Float")
map("K", vim.lsp.buf.hover, "Hover Documentation")
map("gs", vim.lsp.buf.signature_help, "Signature Documentation")
map("gD", vim.lsp.buf.declaration, "Goto Declaration")
map("<leader>la", vim.lsp.buf.code_action, "Code Action")
map("<leader>lr", vim.lsp.buf.rename, "Rename all references")
map("<leader>lf", vim.lsp.buf.format, "Format")
map("<leader>v", "<cmd>vsplit | lua vim.lsp.buf.definition()<cr>", "Goto Definition in Vertical Split")
local function client_supports_method(client, method, bufnr)
if vim.fn.has 'nvim-0.11' == 1 then
return client:supports_method(method, bufnr)
else
return client.supports_method(method, { bufnr = bufnr })
end
end
local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false })
-- When cursor stops moving: Highlights all instances of the symbol under the cursor
-- When cursor moves: Clears the highlighting
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.clear_references,
})
-- When LSP detaches: Clears the highlighting
vim.api.nvim_create_autocmd('LspDetach', {
group = vim.api.nvim_create_augroup('lsp-detach', { clear = true }),
callback = function(event2)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds { group = 'lsp-highlight', buffer = event2.buf }
end,
})
end
end,
})

View File

@@ -0,0 +1,25 @@
-- see lua/plugins/mason-lspconfig for enabled servers
vim.diagnostic.config({
virtual_lines = true,
-- virtual_text = true,
underline = true,
update_in_insert = false,
severity_sort = true,
float = {
border = "rounded",
source = true,
},
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "󰅚 ",
[vim.diagnostic.severity.WARN] = "󰀪 ",
[vim.diagnostic.severity.INFO] = "󰋽 ",
[vim.diagnostic.severity.HINT] = "󰌶 ",
},
numhl = {
[vim.diagnostic.severity.ERROR] = "ErrorMsg",
[vim.diagnostic.severity.WARN] = "WarningMsg",
},
},
})