From 1e3ba58a40dde8e68152e13d29137dc507bf56ce Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Sat, 24 Feb 2024 23:15:25 -0500 Subject: [PATCH] add capabilities check --- init.lua | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/init.lua b/init.lua index 4fdf2a4..f9be842 100644 --- a/init.lua +++ b/init.lua @@ -395,9 +395,7 @@ require('lazy').setup({ -- Shortcut for searching your neovim configuration files vim.keymap.set('n', 'sn', function() - builtin.find_files { - cwd = vim.fn.stdpath 'config', - } + builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' }) end, }, @@ -488,9 +486,7 @@ require('lazy').setup({ -- Execute a code action, usually your cursor needs to be on top of an error -- or a suggestion from your LSP for this to activate. - map('ca', function() - vim.lsp.buf.code_action { context = { only = { 'quickfix', 'refactor', 'source' } } } - end, '[C]ode [A]ction') + map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') -- Opens a popup that displays documentation about the word under your cursor -- See `:help K` for why this keymap @@ -508,15 +504,18 @@ require('lazy').setup({ -- See `:help CursorHold` for information about when this is executed -- -- When you move your cursor, the highlights will be cleared (the second autocommand). - vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - buffer = event.buf, - callback = vim.lsp.buf.document_highlight, - }) + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.server_capabilities.documentHighlightProvider then + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + buffer = event.buf, + callback = vim.lsp.buf.document_highlight, + }) - vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { - buffer = event.buf, - callback = vim.lsp.buf.clear_references, - }) + vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + buffer = event.buf, + callback = vim.lsp.buf.clear_references, + }) + end end, })