File tree 3 files changed +11
-0
lines changed
3 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -473,6 +473,10 @@ impl GlobalStateSnapshot {
473
473
pub ( crate ) fn vfs_memory_usage ( & self ) -> usize {
474
474
self . vfs . read ( ) . 0 . memory_usage ( )
475
475
}
476
+
477
+ pub ( crate ) fn file_exists ( & self , file_id : FileId ) -> bool {
478
+ self . vfs . read ( ) . 0 . exists ( file_id)
479
+ }
476
480
}
477
481
478
482
pub ( crate ) fn file_id_to_url ( vfs : & vfs:: Vfs , id : FileId ) -> Url {
Original file line number Diff line number Diff line change @@ -1436,6 +1436,8 @@ pub(crate) fn handle_inlay_hints_resolve(
1436
1436
1437
1437
let resolve_data: lsp_ext:: InlayHintResolveData = serde_json:: from_value ( data) ?;
1438
1438
let file_id = FileId ( resolve_data. file_id ) ;
1439
+ anyhow:: ensure!( snap. file_exists( file_id) , "Invalid LSP resolve data" ) ;
1440
+
1439
1441
let line_index = snap. file_line_index ( file_id) ?;
1440
1442
let range = from_proto:: text_range (
1441
1443
& line_index,
Original file line number Diff line number Diff line change @@ -184,6 +184,11 @@ impl Vfs {
184
184
mem:: take ( & mut self . changes )
185
185
}
186
186
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
+
187
192
/// Returns the id associated with `path`
188
193
///
189
194
/// - 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