22//!
33//! Files which do not belong to any explicitly configured `FileSet` belong to
44//! the default `FileSet`.
5- use std:: fmt;
5+ use std:: {
6+ fmt,
7+ panic:: { RefUnwindSafe , UnwindSafe } ,
8+ sync:: Arc ,
9+ } ;
610
711use fst:: { IntoStreamer , Streamer } ;
812use rustc_hash:: FxHashMap ;
913use stdx:: hash:: NoHashHashMap ;
1014
11- use crate :: { AnchoredPath , FileId , Vfs , VfsPath } ;
15+ use crate :: { loader :: Handle , AnchoredPath , FileId , Vfs , VfsPath } ;
1216
1317/// A set of [`VfsPath`]s identified by [`FileId`]s.
14- #[ derive( Default , Clone , Eq , PartialEq ) ]
18+ #[ derive( Default , Clone ) ]
1519pub struct FileSet {
1620 files : FxHashMap < VfsPath , FileId > ,
1721 paths : NoHashHashMap < FileId , VfsPath > ,
22+ handle : Option < Arc < dyn Handle + Sync + Send + UnwindSafe + RefUnwindSafe > > ,
1823}
1924
25+ impl PartialEq for FileSet {
26+ fn eq ( & self , other : & Self ) -> bool {
27+ self . files == other. files && self . paths == other. paths
28+ }
29+ }
30+
31+ impl Eq for FileSet { }
32+
2033impl FileSet {
2134 /// Returns the number of stored paths.
2235 pub fn len ( & self ) -> usize {
@@ -31,7 +44,15 @@ impl FileSet {
3144 let mut base = self . paths [ & path. anchor ] . clone ( ) ;
3245 base. pop ( ) ;
3346 let path = base. join ( path. path ) ?;
34- self . files . get ( & path) . copied ( )
47+ let answer = self . files . get ( & path) ;
48+ if answer. is_none ( ) {
49+ if let Some ( handle) = & self . handle {
50+ if let Some ( x) = path. as_path ( ) {
51+ handle. subscribe ( x. to_owned ( ) ) ;
52+ }
53+ }
54+ }
55+ answer. copied ( )
3556 }
3657
3758 /// Get the id corresponding to `path` if it exists in the set.
@@ -110,7 +131,9 @@ impl FileSetConfig {
110131 /// Creates a new [`FileSet`] for every set of prefixes in `self`.
111132 pub fn partition ( & self , vfs : & Vfs ) -> Vec < FileSet > {
112133 let mut scratch_space = Vec :: new ( ) ;
113- let mut res = vec ! [ FileSet :: default ( ) ; self . len( ) ] ;
134+ let mut file_set = FileSet :: default ( ) ;
135+ file_set. handle = vfs. handle . clone ( ) ;
136+ let mut res = vec ! [ file_set; self . len( ) ] ;
114137 for ( file_id, path) in vfs. iter ( ) {
115138 let root = self . classify ( path, & mut scratch_space) ;
116139 res[ root] . insert ( file_id, path. clone ( ) ) ;
0 commit comments