diff options
author | sommerfeld <sommerfeld@sommerfeld.dev> | 2024-06-12 18:19:27 +0100 |
---|---|---|
committer | sommerfeld <sommerfeld@sommerfeld.dev> | 2024-06-12 18:19:27 +0100 |
commit | 953fc404fc4e75dfbec40f7b8d60fc4a0bba8e82 (patch) | |
tree | 0db60861290c6279f81eeddbe7ca8cd07dcfaed8 /home | |
parent | 39a2cfa4afe61a94d41299257b16d5af899e5185 (diff) | |
download | dotfiles-953fc404fc4e75dfbec40f7b8d60fc4a0bba8e82.tar.gz dotfiles-953fc404fc4e75dfbec40f7b8d60fc4a0bba8e82.tar.bz2 dotfiles-953fc404fc4e75dfbec40f7b8d60fc4a0bba8e82.zip |
[nvim] Add LSP current word highlighting
Diffstat (limited to 'home')
-rw-r--r-- | home/.config/nvim/lua/custom/plugins/lsp.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/home/.config/nvim/lua/custom/plugins/lsp.lua b/home/.config/nvim/lua/custom/plugins/lsp.lua index 6bd73d7..ad7d43d 100644 --- a/home/.config/nvim/lua/custom/plugins/lsp.lua +++ b/home/.config/nvim/lua/custom/plugins/lsp.lua @@ -119,6 +119,45 @@ return { map.n("gR", vim.lsp.buf.rename, { buffer = bufnr }) map.n("ga", vim.lsp.buf.code_action, { buffer = bufnr }) map.v("ga", vim.lsp.buf.code_action, { buffer = bufnr }) + + -- The following two autocommands are used to highlight references of the + -- word under your cursor when your cursor rests there for a little while. + -- See `:help CursorHold` for information about when this is executed + -- + -- When you move your cursor, the highlights will be cleared (the second autocommand). + if client.server_capabilities.documentHighlightProvider then + local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false }) + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + buffer = bufnr, + group = highlight_augroup, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + buffer = bufnr, + 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 + + -- The following autocommand is used to enable inlay hints in your + -- code, if the language server you are using supports them + -- + -- This may be unwanted, since they displace some of your code + if client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then + map.n('<leader>th', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({})) + vim.lsp.inlay_hint.enable() + end, { buffer = bufnr }) + end end, }) end, |