From 87493af2378fac7b518fd2c4db903cd3a2c27095 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 17 May 2024 10:07:49 +0200 Subject: [PATCH] fix(lsp): dont try to highlight refs for deleted buffers --- lua/lazyvim/util/lsp.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index c3a72ff6..4df758a4 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -135,6 +135,14 @@ function M.words.setup(opts) if not opts.enabled then return end + local handler = vim.lsp.handlers["textDocument/documentHighlight"] + vim.lsp.handlers["textDocument/documentHighlight"] = function(err, result, ctx, config) + if not vim.api.nvim_buf_is_loaded(ctx.bufnr) then + return + end + return handler(err, result, ctx, config) + end + M.on_attach(function(client, buf) if client.supports_method("textDocument/documentHighlight") then vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI", "CursorMoved", "CursorMovedI" }, {