summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2024-07-11 19:15:28 +0000
committerJosh Rahm <rahm@google.com>2024-07-11 19:15:28 +0000
commit6e40aca53f746d0fdc075dcd62e504e56138c06b (patch)
tree91509862ae95c8450e31b1eba8f44788de572097
parenta815f31519cbdd47b559485ba2a72072166759ab (diff)
downloadconfig.vim-6e40aca53f746d0fdc075dcd62e504e56138c06b.tar.gz
config.vim-6e40aca53f746d0fdc075dcd62e504e56138c06b.tar.bz2
config.vim-6e40aca53f746d0fdc075dcd62e504e56138c06b.zip
Do document highlighting only for file types which lsps support it
-rw-r--r--init.vim6
-rw-r--r--lua/lsp.lua15
2 files changed, 15 insertions, 6 deletions
diff --git a/init.vim b/init.vim
index 8126339..65cafff 100644
--- a/init.vim
+++ b/init.vim
@@ -129,9 +129,9 @@ augroup InitVim
autocmd TextYankPost *
\ lua require'vim.highlight'.on_yank(
\ { higroup = "IncSearch", timeout = 100 });
- autocmd CursorHold * lua vim.lsp.buf.document_highlight()
- autocmd CursorHoldI * lua vim.lsp.buf.document_highlight()
- autocmd CursorMoved * lua vim.lsp.buf.clear_references()
+ " autocmd CursorHold * lua vim.lsp.buf.document_highlight()
+ " autocmd CursorHoldI * lua vim.lsp.buf.document_highlight()
+ " autocmd CursorMoved * lua vim.lsp.buf.clear_references()
augroup END
" Local configuration that can be set by hostname or just a local configuration.
diff --git a/lua/lsp.lua b/lua/lsp.lua
index 47eb97e..9a34981 100644
--- a/lua/lsp.lua
+++ b/lua/lsp.lua
@@ -219,9 +219,18 @@ M.on_attach = function(client, bufnr)
vim.api.nvim_command("augroup LSP")
vim.api.nvim_command("autocmd!")
if client.server_capabilities.documentHighlightProvider then
- vim.api.nvim_command("autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()")
- vim.api.nvim_command("autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()")
- vim.api.nvim_command("autocmd CursorMoved <buffer> lua vim.lsp.util.buf_clear_references()")
+ vim.api.nvim_create_autocmd("CursorHold", {
+ buffer = bufnr,
+ callback = vim.lsp.buf.document_highlight
+ })
+ vim.api.nvim_create_autocmd("CursorHoldI", {
+ buffer = bufnr,
+ callback = vim.lsp.buf.document_highlight
+ })
+ vim.api.nvim_create_autocmd("CursorMoved", {
+ buffer = bufnr,
+ callback = vim.lsp.buf.buf_clear_references
+ })
end
vim.api.nvim_command("augroup END")