From 94fdc5f174d20b9ff56864f0d1ba4d088786caf2 Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:06:08 +0000 Subject: [PATCH] Properly sanitize out inlay hints from remote hosts (#42878) (cherry-pick to stable) (#42882) Cherry-pick of #42878 to stable ---- Part of https://github.com/zed-industries/zed/issues/42671 Release Notes: - Fixed remote hosts causing duplicate hints to be displayed Co-authored-by: Kirill Bulatov --- crates/collab/src/tests/editor_tests.rs | 32 +++++++++++++++++-------- crates/project/src/lsp_store.rs | 11 +++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs index bdc024aaca7242ab0fe261e3b673bf4d0efe23b1..5880d998925743d4cdd822574b647b53194e2116 100644 --- a/crates/collab/src/tests/editor_tests.rs +++ b/crates/collab/src/tests/editor_tests.rs @@ -2169,16 +2169,28 @@ async fn test_inlay_hint_refresh_is_forwarded( } else { "initial hint" }; - Ok(Some(vec![lsp::InlayHint { - position: lsp::Position::new(0, character), - label: lsp::InlayHintLabel::String(label.to_string()), - kind: None, - text_edits: None, - tooltip: None, - padding_left: None, - padding_right: None, - data: None, - }])) + Ok(Some(vec![ + lsp::InlayHint { + position: lsp::Position::new(0, character), + label: lsp::InlayHintLabel::String(label.to_string()), + kind: None, + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + lsp::InlayHint { + position: lsp::Position::new(1090, 1090), + label: lsp::InlayHintLabel::String("out-of-bounds hint".to_string()), + kind: None, + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + ])) } }) .next() diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index fed95e8bbbb88777c0f3386af16a3f53bafac7f5..13b6f826195167e8c68e5eb9a7a83bcb9ad1af3e 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -6876,6 +6876,7 @@ impl LspStore { })) .await; + let buffer_snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot())?; let mut has_errors = false; let inlay_hints = inlay_hints .into_iter() @@ -6887,6 +6888,16 @@ impl LspStore { None } }) + .map(|(server_id, mut new_hints)| { + new_hints.retain(|hint| { + hint.position.is_valid(&buffer_snapshot) + && range.start.is_valid(&buffer_snapshot) + && range.end.is_valid(&buffer_snapshot) + && hint.position.cmp(&range.start, &buffer_snapshot).is_ge() + && hint.position.cmp(&range.end, &buffer_snapshot).is_lt() + }); + (server_id, new_hints) + }) .collect::>(); anyhow::ensure!( !has_errors || !inlay_hints.is_empty(),