File tree Expand file tree Collapse file tree 3 files changed +11
-0
lines changed Expand file tree Collapse file tree 3 files changed +11
-0
lines changed Original file line number Diff line number Diff 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
494498pub ( crate ) fn file_id_to_url ( vfs : & vfs:: Vfs , id : FileId ) -> Url {
Original file line number Diff line number Diff 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,
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments