Skip to content

Commit

Permalink
Ensure resolved hint's file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneToIgnore committed Sep 2, 2023
1 parent 10464c7 commit caf0185
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/rust-analyzer/src/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ impl GlobalStateSnapshot {
pub(crate) fn vfs_memory_usage(&self) -> usize {
self.vfs.read().0.memory_usage()
}

pub(crate) fn file_exists(&self, file_id: FileId) -> bool {
self.vfs.read().0.exists(file_id)
}
}

pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url {
Expand Down
2 changes: 2 additions & 0 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,8 @@ pub(crate) fn handle_inlay_hints_resolve(

let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
let file_id = FileId(resolve_data.file_id);
anyhow::ensure!(snap.file_exists(file_id), "Invalid LSP resolve data");

let line_index = snap.file_line_index(file_id)?;
let range = from_proto::text_range(
&line_index,
Expand Down
5 changes: 5 additions & 0 deletions crates/vfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ impl Vfs {
mem::take(&mut self.changes)
}

/// Provides a panic-less way to verify file_id validity.
pub fn exists(&self, file_id: FileId) -> bool {
self.get(file_id).is_some()
}

/// Returns the id associated with `path`
///
/// - If `path` does not exists in the `Vfs`, allocate a new id for it, associated with a
Expand Down

0 comments on commit caf0185

Please sign in to comment.