lsp: Fix language servers not starting up on save (#32156)

Closes #24349

Release Notes:

- Fixed language servers not starting up when a buffer is saved.

---------

Co-authored-by: 张小白 <364772080@qq.com>
This commit is contained in:
Piotr Osiewicz 2025-06-05 14:22:34 +02:00 committed by GitHub
parent c71791d64e
commit d082cfdbec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 89 additions and 5 deletions

View file

@ -3960,6 +3960,15 @@ impl LspStore {
let buffer_id = buffer.read(cx).remote_id();
let handle = cx.new(|_| buffer.clone());
if let Some(local) = self.as_local_mut() {
let refcount = local.registered_buffers.entry(buffer_id).or_insert(0);
if !ignore_refcounts {
*refcount += 1;
}
// We run early exits on non-existing buffers AFTER we mark the buffer as registered in order to handle buffer saving.
// When a new unnamed buffer is created and saved, we will start loading it's language. Once the language is loaded, we go over all "language-less" buffers and try to fit that new language
// with them. However, we do that only for the buffers that we think are open in at least one editor; thus, we need to keep tab of unnamed buffers as well, even though they're not actually registered with any language
// servers in practice (we don't support non-file URI schemes in our LSP impl).
let Some(file) = File::from_dyn(buffer.read(cx).file()) else {
return handle;
};
@ -3967,11 +3976,6 @@ impl LspStore {
return handle;
}
let refcount = local.registered_buffers.entry(buffer_id).or_insert(0);
if !ignore_refcounts {
*refcount += 1;
}
if ignore_refcounts || *refcount == 1 {
local.register_buffer_with_language_servers(buffer, cx);
}