mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Ensure resolved hint's file exists
This commit is contained in:
parent
10464c7c42
commit
caf018507a
3 changed files with 11 additions and 0 deletions
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue