Ensure resolved hint's file exists

This commit is contained in:
Kirill Bulatov 2023-08-29 14:19:17 +03:00
parent 10464c7c42
commit caf018507a
3 changed files with 11 additions and 0 deletions

View file

@ -489,6 +489,10 @@ impl GlobalStateSnapshot {
pub(crate) fn vfs_memory_usage(&self) -> usize { pub(crate) fn vfs_memory_usage(&self) -> usize {
self.vfs.read().0.memory_usage() 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 { pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url {

View file

@ -1438,6 +1438,8 @@ pub(crate) fn handle_inlay_hints_resolve(
let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?; let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
let file_id = FileId(resolve_data.file_id); 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 line_index = snap.file_line_index(file_id)?;
let range = from_proto::text_range( let range = from_proto::text_range(
&line_index, &line_index,

View file

@ -184,6 +184,11 @@ impl Vfs {
mem::take(&mut self.changes) 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` /// Returns the id associated with `path`
/// ///
/// - If `path` does not exists in the `Vfs`, allocate a new id for it, associated with a /// - If `path` does not exists in the `Vfs`, allocate a new id for it, associated with a