From c2bdbc0e7088f6e89f522d0dedc051ea96f98f9b Mon Sep 17 00:00:00 2001 From: n3wborn Date: Sat, 27 Jun 2026 00:51:11 +0200 Subject: [PATCH 1/2] refactor: lsp config --- lua/config/lsp.lua | 149 ++++++++++++++++++++++++++-------------- lua/plugins/fzf_lua.lua | 34 ++------- 2 files changed, 105 insertions(+), 78 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index e2f3cdc8..cd9b60b2 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,36 +1,25 @@ -local servers = { - 'bashls', - 'gopls', - 'jsonls', - -- emmylua_ls', - 'lua_ls', - 'kotlin_lsp', - 'marksman', - 'mpls', - 'oxfmt', - -- 'intelephense', - 'phpantom', - 'tsgo', - 'taplo', - 'twiggy-language-server', - 'v_analyzer', - 'zls', -} - -for _, server in ipairs(servers) do - vim.lsp.enable(server) -end - -local signs = require('config.icons').diagnostics +local diagnostic_icons = require('config.icons').diagnostics ---@type vim.diagnostic.Opts vim.diagnostic.config({ + status = { + format = function(counts) + local items = {} + for severity, count in pairs(counts) do + local name = vim.diagnostic.severity[severity] + local hl = 'DiagnosticSign' .. name:sub(1, 1) .. name:sub(2):lower() + table.insert(items, ('%%#%s#%s %d'):format(hl, diagnostic_icons[name], count)) + end + return table.concat(items, ' ') + end, + }, + signs = { text = { - [vim.diagnostic.severity.ERROR] = signs.Error, - [vim.diagnostic.severity.WARN] = signs.Warn, - [vim.diagnostic.severity.HINT] = signs.Hint, - [vim.diagnostic.severity.INFO] = signs.Info, + [vim.diagnostic.severity.ERROR] = diagnostic_icons.Error, + [vim.diagnostic.severity.WARN] = diagnostic_icons.Warn, + [vim.diagnostic.severity.HINT] = diagnostic_icons.Hint, + [vim.diagnostic.severity.INFO] = diagnostic_icons.Info, }, }, severity_sort = true, @@ -38,7 +27,15 @@ vim.diagnostic.config({ update_in_insert = true, -- TODO: choose which one is better -- update_in_insert = false, - float = true, + float = { + source = 'if_many', + -- Show severity icons as prefixes. + prefix = function(diag) + local level = vim.diagnostic.severity[diag.severity] + local prefix = string.format(' %s ', diagnostic_icons[level]) + return prefix, 'Diagnostic' .. level:gsub('^%l', string.upper) + end, + }, jump = { on_jump = vim.diagnostic.open_float }, -- TODO: choose lines or text virtual_lines = { @@ -57,56 +54,108 @@ vim.diagnostic.config({ -- }, }) -local lsp_group = vim.api.nvim_create_augroup('my.lsp', { clear = true }) - vim.api.nvim_create_autocmd('LspAttach', { - group = lsp_group, + group = vim.api.nvim_create_augroup('my.lsp.keymaps', { clear = true }), desc = 'LSP Keymaps', callback = function(ev) local client = assert(vim.lsp.get_client_by_id(ev.data.client_id)) local bufnr = ev.buf - local function map(mode, lhs, rhs, desc) - vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc }) + if client:supports_method('textDocument/documentSymbol') then + vim.keymap.set({ 'n', 'x' }, 'ss', function() + require('fzf-lua').lsp_document_symbols() + end, { desc = 'List Symbols' }) + vim.keymap.set( + { 'n', 'x' }, + 'sS', + 'FzfLua lsp_live_workspace_symbols', + { desc = 'List Workspace Symbols' } + ) end - map('n', 'D', vim.diagnostic.open_float, 'Line diagnostics') + if client:supports_method('textDocument/definition') then + vim.keymap.set({ 'n' }, 'gd', function() + require('fzf-lua').lsp_definitions({ jump1 = true }) + end, { desc = 'Go to Definition' }) + vim.keymap.set({ 'n' }, 'gD', function() + require('fzf-lua').lsp_definitions({ jump1 = false }) + end, { desc = 'Peek Definition' }) + end + + if client:supports_method('textDocument/references') then + vim.keymap.set({ 'n' }, 'grr', 'FzfLua lsp_references') + end if client:supports_method('textDocument/onTypeFormatting') then vim.lsp.on_type_formatting.enable(true, { bufnr = bufnr }) end if client:supports_method('textDocument/documentColor') then - vim.lsp.document_color.enable(not vim.lsp.document_color.is_enabled()) + vim.keymap.set({ 'n', 'x' }, 'grc', function() + vim.lsp.document_color.color_presentation() + end, { desc = 'Document Color Presentation' }) end if client:supports_method('textDocument/inlayHint') and vim.g.lsp_inlay_hints then vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) end - if client:supports_method('textDocument/documentHighlight') then - local group = vim.api.nvim_create_augroup('lsp-highlight-' .. bufnr, { clear = true }) + if client:supports_method('textDocument/signatureHelp') then + vim.keymap.set('i', '', function() + -- Close the completion menu first (if open). + if require('blink.cmp.completion.windows.menu').win:is_open() then + require('blink.cmp').hide() + end - vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + vim.lsp.buf.signature_help() + end, { desc = 'Signature Help' }) + end + + if client:supports_method('textDocument/documentHighlight') then + local under_cursor_highlights_group = + vim.api.nvim_create_augroup('my.lsp.cursor_highlights', { clear = false }) + vim.api.nvim_create_autocmd({ 'CursorHold', 'InsertLeave' }, { + group = under_cursor_highlights_group, + desc = 'Highlight references under the cursor', buffer = bufnr, - group = group, callback = vim.lsp.buf.document_highlight, }) - vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + vim.api.nvim_create_autocmd({ 'CursorMoved', 'InsertEnter', 'BufLeave' }, { + group = under_cursor_highlights_group, + desc = 'Clear highlight references', buffer = bufnr, - group = group, callback = vim.lsp.buf.clear_references, }) + end + end, +}) - vim.api.nvim_create_autocmd('LspDetach', { - buffer = bufnr, - once = true, - callback = function() - vim.lsp.buf.clear_references() - vim.api.nvim_del_augroup_by_name('lsp-highlight-' .. bufnr) - end, - }) +vim.api.nvim_create_autocmd({ 'BufReadPre', 'BufNewFile' }, { + once = true, + callback = function() + local servers = { + 'bashls', + 'gopls', + 'jsonls', + -- emmylua_ls', + 'lua_ls', + 'kotlin_lsp', + 'marksman', + 'mpls', + 'oxfmt', + -- 'intelephense', + 'phpantom', + 'tsgo', + 'taplo', + 'twiggy-language-server', + 'v_analyzer', + 'zls', + } + + for _, server in ipairs(servers) do + vim.lsp.enable(server) end + vim.lsp.enable(servers) end, }) diff --git a/lua/plugins/fzf_lua.lua b/lua/plugins/fzf_lua.lua index c488cc7f..952cc19d 100644 --- a/lua/plugins/fzf_lua.lua +++ b/lua/plugins/fzf_lua.lua @@ -7,34 +7,6 @@ return { cmd = 'FzfLua', keys = { { 'F', ':FzfLua' }, - { - 'ss', - function() - require('fzf-lua').lsp_document_symbols() - end, - desc = 'Goto Symbol', - }, - { - 'sS', - function() - require('fzf-lua').lsp_live_workspace_symbols() - end, - desc = 'Goto Symbol (Workspace)', - }, - { - 'gd', - function() - require('fzf-lua').lsp_definitions() - end, - desc = 'Goto Definition', - }, - { - 'gf', - function() - require('fzf-lua').lsp_finder() - end, - desc = 'LSP finder', - }, { 'gi', function() @@ -110,6 +82,12 @@ return { -- buffers = { -- formatter = 'path.filename_first', -- }, + helptags = { + actions = { + -- Open help pages in a vertical split. + ['enter'] = require('fzf-lua.actions').help_vert, + }, + }, lsp = { includeDeclaration = false, -- include current declaration in LSP context symbols = { From 230d4e234e5acc1b1910b25c2c5addf8eccd6ca0 Mon Sep 17 00:00:00 2001 From: n3wborn Date: Sat, 27 Jun 2026 00:58:42 +0200 Subject: [PATCH 2/2] fix(lsp): prefer function call for keymaps, remove comments --- lua/config/lsp.lua | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index cd9b60b2..8f19be31 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -37,7 +37,6 @@ vim.diagnostic.config({ end, }, jump = { on_jump = vim.diagnostic.open_float }, - -- TODO: choose lines or text virtual_lines = { current_line = true, severity = { @@ -45,13 +44,6 @@ vim.diagnostic.config({ vim.diagnostic.severity.ERROR, }, }, - -- virtual_text = { - -- current_line = true, - -- severity = { - -- vim.diagnostic.severity.WARN, - -- vim.diagnostic.severity.ERROR, - -- }, - -- }, }) vim.api.nvim_create_autocmd('LspAttach', { @@ -65,12 +57,9 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.keymap.set({ 'n', 'x' }, 'ss', function() require('fzf-lua').lsp_document_symbols() end, { desc = 'List Symbols' }) - vim.keymap.set( - { 'n', 'x' }, - 'sS', - 'FzfLua lsp_live_workspace_symbols', - { desc = 'List Workspace Symbols' } - ) + vim.keymap.set({ 'n', 'x' }, 'sS', function() + require('fzf-lua').lsp_live_workspace_symbols() + end, { desc = 'List Workspace Symbols' }) end if client:supports_method('textDocument/definition') then