aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_meta/api_keysets.lua
diff options
context:
space:
mode:
authorChris AtLee <chris@atlee.ca>2023-08-01 08:13:52 -0400
committerGitHub <noreply@github.com>2023-08-01 05:13:52 -0700
commite55e80d51ca5d85770981bffb9254badc3662e0c (patch)
treedddf5a414335cb9e9ddd37c9967bb1aff44d99b2 /runtime/lua/vim/_meta/api_keysets.lua
parent20bfdbe83253cf5ec0a42bd75bd4ed7df945ab37 (diff)
downloadrneovim-e55e80d51ca5d85770981bffb9254badc3662e0c.tar.gz
rneovim-e55e80d51ca5d85770981bffb9254badc3662e0c.tar.bz2
rneovim-e55e80d51ca5d85770981bffb9254badc3662e0c.zip
fix(lsp): inlay hints: "Failed to delete autocmd" when closing buffer #24469
Problem: "Failed to delete autocmd" error when deleting LspNotify autocmd. #24456 Solution: Change a few things in the inlay_hint and diagnostic LSP code: 1. Re-introduce the `enabled` flag for the buffer state tables. Previously I was relying on the presence of an autocmd id in the state table to track whether inlay_hint / diagnostic was enabled for a buffer. There are two reasons why this doesn't work well: - Each time inlay_hint / diagnostic is enabled, we call `nvim_buf_attach` on the buffer, resulting in multiple `on_reload` or `on_detach` callbacks being registered. - Commands like `bwipeout` delete buffer local autocmds, sometimes before our `on_detach` callbacks have a chance to delete them first. This causes the - Use module local enabled state for diagnostic as well. bwipeout can race with on_detach callbacks for deleting autocmds. Error referenced in #24456. 2. Change the `LspDetach` autocmd to run each time (i.e., remove the `once` flag). Since we're only registering autocmds once per buffer now, we need to make sure that we set the enabled flag properly each time the LSP client detaches from the buffer. - Remove `once` from the LspDetach autocmds for inlay_hint and diagnostic. We only set up the autocmd once now. Gets removed when buffer is deleted. 3. Have the `LspNotify` handler also refresh the inlay_hint / diagnostics when receiving the `textDocument/didOpen` event. Before this point, the LSP backend doesn't have the contents of the buffer, so can't provide inlay hints or diagnostics. Downsides of this approach: * When inlay_hint / diagnostics are disabled on a buffer, it will continue to receive `LspNotify` events for that buffer. The callback exits early since the `enabled` flag is false. Alternatives: * Can we wrap the call to `nvim_del_autocmd` in `pcall` to swallow any errors resulting from trying to delete the autocmd? Fixes #24456 Helped-by: Maria José Solano <majosolano99@gmail.com>
Diffstat (limited to 'runtime/lua/vim/_meta/api_keysets.lua')
0 files changed, 0 insertions, 0 deletions