lsp: Fix overnotifying about open buffers for unrelated servers (#38196)

Do not report all open buffers to new instances of the same language
server, as they can respond with ~spurious errors.

This regressed in  https://github.com/zed-industries/zed/pull/34142

Closes https://github.com/zed-industries/zed/issues/35017

Release Notes:

- Fixed Zed overly notifying language servers about open buffers, which
could've resulted in confusing errors in multi-language projects (in
e.g. Go).
This commit is contained in:
Piotr Osiewicz
2025-09-15 15:20:04 +02:00
committed by GitHub
parent 53b2f37452
commit 6d6c3d648a
2 changed files with 12 additions and 4 deletions
+8 -4
View File
@@ -10540,7 +10540,10 @@ impl LspStore {
for (worktree_id, servers) in &local.lsp_tree.instances {
if *worktree_id != key.worktree_id {
for server_map in servers.roots.values() {
if server_map.contains_key(&key.name) {
if server_map
.values()
.any(|(node, _)| node.id() == Some(server_id))
{
worktrees_using_server.push(*worktree_id);
}
}
@@ -10550,6 +10553,7 @@ impl LspStore {
let mut buffer_paths_registered = Vec::new();
self.buffer_store.clone().update(cx, |buffer_store, cx| {
let mut lsp_adapters = HashMap::default();
for buffer_handle in buffer_store.buffers() {
let buffer = buffer_handle.read(cx);
let file = match File::from_dyn(buffer.file()) {
@@ -10562,9 +10566,9 @@ impl LspStore {
};
if !worktrees_using_server.contains(&file.worktree.read(cx).id())
|| !self
.languages
.lsp_adapters(&language.name())
|| !lsp_adapters
.entry(language.name())
.or_insert_with(|| self.languages.lsp_adapters(&language.name()))
.iter()
.any(|a| a.name == key.name)
{
@@ -114,6 +114,10 @@ impl InnerTreeNode {
}),
}
}
pub(crate) fn id(&self) -> Option<LanguageServerId> {
self.id.get().copied()
}
}
impl LanguageServerTree {