diff options
author | Evgeni Chasnovski <evgeni.chasnovski@gmail.com> | 2025-02-06 10:33:15 +0200 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2025-02-07 22:10:59 +0000 |
commit | a9cdf76e3a142c78b2b5da58c428e15e31cb0a15 (patch) | |
tree | b372dafe93b5858405fd0bd92fed2dd3797873b4 | |
parent | ad853d1df093f30d0ca083a0c3a2935496533e8e (diff) | |
download | rneovim-a9cdf76e3a142c78b2b5da58c428e15e31cb0a15.tar.gz rneovim-a9cdf76e3a142c78b2b5da58c428e15e31cb0a15.tar.bz2 rneovim-a9cdf76e3a142c78b2b5da58c428e15e31cb0a15.zip |
fix(lsp): check for valid buf before processing semantic tokens response
Problem: There is no check for buffer validity before processing
semantic tokens response. This can lead to `Invalid buffer id` error
if processing request takes a long time and the buffer is wiped out.
For example, this can happen after by accident navigating to a buffer
from different project which leads to first loading project's
workspace and *then* processing semantic tokens. During that time
a buffer can be wiped out, as navigation to it was by accident.
Solution: Add extra check for buffer validity before processing semantic
tokens response.
-rw-r--r-- | runtime/lua/vim/lsp/semantic_tokens.lua | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index dd8b654856..619f7f1110 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -337,6 +337,10 @@ function STHighlighter:process_response(response, client, version) return end + if not api.nvim_buf_is_valid(self.bufnr) then + return + end + -- if we have a response to a delta request, update the state of our tokens -- appropriately. if it's a full response, just use that local tokens ---@type integer[] @@ -376,8 +380,10 @@ function STHighlighter:process_response(response, client, version) current_result.highlights = highlights current_result.namespace_cleared = false - -- redraw all windows displaying buffer - api.nvim__redraw({ buf = self.bufnr, valid = true }) + -- redraw all windows displaying buffer (if still valid) + if api.nvim_buf_is_valid(self.bufnr) then + api.nvim__redraw({ buf = self.bufnr, valid = true }) + end end --- @param bufnr integer |