diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-17 10:40:11 -0700 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-17 10:40:11 -0700 |
| commit | ea127689e0ae2d39b49004be605e541ff80e2621 (patch) | |
| tree | abbe79e5e37792bd8ebea8f9ac788ff5b8aed704 /.config/nvim/lua/eugenetriguba/plugins/lsp.lua | |
| download | openbsd-dotfiles-ea127689e0ae2d39b49004be605e541ff80e2621.zip | |
Initial Commit
Diffstat (limited to '.config/nvim/lua/eugenetriguba/plugins/lsp.lua')
| -rw-r--r-- | .config/nvim/lua/eugenetriguba/plugins/lsp.lua | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/.config/nvim/lua/eugenetriguba/plugins/lsp.lua b/.config/nvim/lua/eugenetriguba/plugins/lsp.lua new file mode 100644 index 0000000..f5ff7d5 --- /dev/null +++ b/.config/nvim/lua/eugenetriguba/plugins/lsp.lua @@ -0,0 +1,113 @@ +vim.pack.add { + { + name = 'lazydev.nvim', + src = 'https://github.com/folke/lazydev.nvim', + }, + { + name = 'nvim-lspconfig', + src = 'https://github.com/neovim/nvim-lspconfig', + }, + { + name = 'fidget.nvim', + src = 'https://github.com/j-hui/fidget.nvim', + }, +} + +require('fidget').setup {} +require('lazydev').setup { + library = { + { path = '${3rd}/luv/library', words = { 'vim%.uv' } }, + }, +} + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }), + callback = function(event) + local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + + local fzf = require 'fzf-lua' + fzf.register_ui_select({}, true) + map('grn', vim.lsp.buf.rename, '[R]e[n]ame') + map('gra', fzf.lsp_code_actions, '[G]oto Code [A]ction', { 'n', 'x' }) + map('grr', fzf.lsp_references, '[G]oto [R]eferences') + map('gri', fzf.lsp_implementations, '[G]oto [I]mplementation') + map('grd', fzf.lsp_definitions, '[G]oto [D]efinition') + map('grD', fzf.lsp_declarations, '[G]oto [D]eclaration') + map('gO', fzf.lsp_document_symbols, 'Open Document Symbols') + map('gW', fzf.lsp_workspace_symbols, 'Open Workspace Symbols') + map('grt', fzf.lsp_typedefs, '[G]oto [T]ype Definition') + map('<C-space>', vim.lsp.completion.get, '[C]ompletion', 'i') + + local client = vim.lsp.get_client_by_id(event.data.client_id) + + if client and client:supports_method('textDocument/completion', event.buf) then + vim.lsp.completion.enable(true, client.id, event.buf, { + autotrigger = false, + convert = function(item) + return { abbr = item.label:gsub('%b()', '') } + end, + }) + end + + if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then + local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false }) + 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, + }) + + 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 + + if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then + map('<leader>th', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) + end, '[T]oggle Inlay [H]ints') + end + end, +}) + +vim.api.nvim_create_autocmd('CursorHold', { + callback = function() + vim.diagnostic.open_float(nil, { + focus = false, + scope = 'cursor', + border = 'rounded', + source = 'if_many', + close_events = { 'CursorMoved', 'InsertEnter', 'BufLeave', 'WinLeave' }, + }) + end, +}) + +vim.diagnostic.config { + severity_sort = true, + float = { border = 'rounded', source = 'if_many' }, + underline = true, + signs = { + text = { + [vim.diagnostic.severity.ERROR] = ' ', + [vim.diagnostic.severity.WARN] = ' ', + [vim.diagnostic.severity.INFO] = ' ', + [vim.diagnostic.severity.HINT] = ' ', + }, + }, + virtual_text = false, +} + +vim.lsp.enable { 'lua_ls', 'clangd', 'bashls' } |