Skip to content

Commit caf0185

Browse files
Ensure resolved hint's file exists
1 parent 10464c7 commit caf0185

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

crates/rust-analyzer/src/global_state.rs

+4
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ impl GlobalStateSnapshot {
489489
pub(crate) fn vfs_memory_usage(&self) -> usize {
490490
self.vfs.read().0.memory_usage()
491491
}
492+
493+
pub(crate) fn file_exists(&self, file_id: FileId) -> bool {
494+
self.vfs.read().0.exists(file_id)
495+
}
492496
}
493497

494498
pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url {

crates/rust-analyzer/src/handlers/request.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,8 @@ pub(crate) fn handle_inlay_hints_resolve(
14381438

14391439
let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
14401440
let file_id = FileId(resolve_data.file_id);
1441+
anyhow::ensure!(snap.file_exists(file_id), "Invalid LSP resolve data");
1442+
14411443
let line_index = snap.file_line_index(file_id)?;
14421444
let range = from_proto::text_range(
14431445
&line_index,

crates/vfs/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ impl Vfs {
184184
mem::take(&mut self.changes)
185185
}
186186

187+
/// Provides a panic-less way to verify file_id validity.
188+
pub fn exists(&self, file_id: FileId) -> bool {
189+
self.get(file_id).is_some()
190+
}
191+
187192
/// Returns the id associated with `path`
188193
///
189194
/// - If `path` does not exists in the `Vfs`, allocate a new id for it, associated with a

0 commit comments

Comments
 (0)