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:
parent
c71791d64e
commit
d082cfdbec
2 changed files with 89 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue