Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Properly sanitize out inlay hints from remote hosts (#42878)

Kirill Bulatove0b64773d9f2
diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs
index bdc024aaca7..5880d998925 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 cae4d64c67d..069c12c75c4 100644
--- a/crates/project/src/lsp_store.rs
+++ b/crates/project/src/lsp_store.rs
@@ -6881,6 +6881,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()
@@ -6892,6 +6893,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::<HashMap<_, _>>();
anyhow::ensure!(
!has_errors || !inlay_hints.is_empty(),