@@ -21,33 +21,36 @@ use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
2121pub type ProcMacroPaths = FxHashMap < CrateId , Result < ( Option < String > , AbsPathBuf ) , String > > ;
2222pub type ProcMacros = FxHashMap < CrateId , ProcMacroLoadResult > ;
2323
24+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
25+ pub struct SourceRootId ( pub u32 ) ;
26+
2427/// Files are grouped into source roots. A source root is a directory on the
2528/// file systems which is watched for changes. Typically it corresponds to a
2629/// Rust crate. Source roots *might* be nested: in this case, a file belongs to
2730/// the nearest enclosing source root. Paths to files are always relative to a
2831/// source root, and the analyzer does not know the root path of the source root at
2932/// all. So, a file from one source root can't refer to a file in another source
3033/// root by path.
31- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
32- pub struct SourceRootId ( pub u32 ) ;
33-
3434#[ derive( Clone , Debug , PartialEq , Eq ) ]
3535pub struct SourceRoot {
3636 /// Sysroot or crates.io library.
3737 ///
3838 /// Libraries are considered mostly immutable, this assumption is used to
3939 /// optimize salsa's query structure
4040 pub is_library : bool ,
41+ cargo_file_id : Option < FileId > ,
42+ ratoml_file_id : Option < FileId > ,
4143 file_set : FileSet ,
4244}
4345
4446impl SourceRoot {
4547 pub fn new_local ( file_set : FileSet ) -> SourceRoot {
46- SourceRoot { is_library : false , file_set }
48+ eprintln ! ( "{:#?}" , file_set) ;
49+ SourceRoot { is_library : false , file_set, cargo_file_id : None , ratoml_file_id : None }
4750 }
4851
4952 pub fn new_library ( file_set : FileSet ) -> SourceRoot {
50- SourceRoot { is_library : true , file_set }
53+ SourceRoot { is_library : true , file_set, cargo_file_id : None , ratoml_file_id : None }
5154 }
5255
5356 pub fn path_for_file ( & self , file : & FileId ) -> Option < & VfsPath > {
@@ -65,6 +68,16 @@ impl SourceRoot {
6568 pub fn iter ( & self ) -> impl Iterator < Item = FileId > + ' _ {
6669 self . file_set . iter ( )
6770 }
71+
72+ /// Get `FileId` of the `Cargo.toml` if one present in `SourceRoot`
73+ pub fn cargo_toml ( & self ) -> Option < FileId > {
74+ self . cargo_file_id
75+ }
76+
77+ /// Get `FileId` of the `rust-analyzer.toml` if one present in `SourceRoot`
78+ pub fn ratoml ( & self ) -> Option < FileId > {
79+ self . ratoml_file_id
80+ }
6881}
6982
7083/// `CrateGraph` is a bit of information which turns a set of text files into a
0 commit comments