add capabilities check

This commit is contained in:
TJ DeVries 2024-02-24 23:15:25 -05:00
parent 51842d8064
commit 1e3ba58a40

View File

@ -395,9 +395,7 @@ require('lazy').setup({
-- Shortcut for searching your neovim configuration files -- Shortcut for searching your neovim configuration files
vim.keymap.set('n', '<leader>sn', function() vim.keymap.set('n', '<leader>sn', function()
builtin.find_files { builtin.find_files { cwd = vim.fn.stdpath 'config' }
cwd = vim.fn.stdpath 'config',
}
end, { desc = '[S]earch [N]eovim files' }) end, { desc = '[S]earch [N]eovim files' })
end, end,
}, },
@ -488,9 +486,7 @@ require('lazy').setup({
-- Execute a code action, usually your cursor needs to be on top of an error -- 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. -- or a suggestion from your LSP for this to activate.
map('<leader>ca', function() map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
vim.lsp.buf.code_action { context = { only = { 'quickfix', 'refactor', 'source' } } }
end, '[C]ode [A]ction')
-- Opens a popup that displays documentation about the word under your cursor -- Opens a popup that displays documentation about the word under your cursor
-- See `:help K` for why this keymap -- See `:help K` for why this keymap
@ -508,15 +504,18 @@ require('lazy').setup({
-- See `:help CursorHold` for information about when this is executed -- See `:help CursorHold` for information about when this is executed
-- --
-- When you move your cursor, the highlights will be cleared (the second autocommand). -- When you move your cursor, the highlights will be cleared (the second autocommand).
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { local client = vim.lsp.get_client_by_id(event.data.client_id)
buffer = event.buf, if client and client.server_capabilities.documentHighlightProvider then
callback = vim.lsp.buf.document_highlight, vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
}) buffer = event.buf,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf, buffer = event.buf,
callback = vim.lsp.buf.clear_references, callback = vim.lsp.buf.clear_references,
}) })
end
end, end,
}) })