Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trigger LspDetach on buffer delete #28795

Merged
merged 2 commits into from
May 23, 2024

Conversation

AThePeanut4
Copy link
Contributor

Currently, the LspDetach autocmd is triggered when the attached client quits, or if the vim.lsp.buf_detach_client function is called, but not if the buffer is deleted.

I've basically just updated the on_detach callback to be like buf_detach_client. Would it perhaps be better to just call buf_detach_client directly? I'm also not sure if the vim.diagnostic.reset bit is necessary.

There should probably be a test for this, but I have no idea how any of that works... this PR is mostly because it was easier than writing up a bug report :) Please feel free to make/suggest any necessary changes.

buffer = bufnr,
modeline = false,
data = { client_id = client.id },
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: what happens if the autocmd handler throws an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't thought of that, but are errors actually propagated through nvim_exec_autocmds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with a simple handler that just unconditionally errors, and it doesn't seem to break anything for a normal LSP. I say normal because it was breaking things with null-ls (none-ls), but the error was coming from the client.notify call, which null-ls monkey-patches afaik. Not sure if this is something that should be accounted for.

@mfussenegger mfussenegger merged commit 5ac8db1 into neovim:master May 23, 2024
29 checks passed
@mfussenegger
Copy link
Member

Thanks. I extended a test case to cover the LspDetach event.

github-actions bot pushed a commit that referenced this pull request May 23, 2024
Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
(cherry picked from commit 5ac8db1)
Copy link
Contributor

Successfully created backport PR for release-0.10:

@AThePeanut4 AThePeanut4 deleted the lspdetach-on-bufdelete branch May 23, 2024 12:11
@wookayin wookayin added this to the 0.10.1 milestone May 26, 2024
huangyingw pushed a commit to huangyingw/neovim that referenced this pull request May 31, 2024
Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants