@@ -21,33 +21,36 @@ use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
21
21
pub type ProcMacroPaths = FxHashMap < CrateId , Result < ( Option < String > , AbsPathBuf ) , String > > ;
22
22
pub type ProcMacros = FxHashMap < CrateId , ProcMacroLoadResult > ;
23
23
24
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
25
+ pub struct SourceRootId ( pub u32 ) ;
26
+
24
27
/// Files are grouped into source roots. A source root is a directory on the
25
28
/// file systems which is watched for changes. Typically it corresponds to a
26
29
/// Rust crate. Source roots *might* be nested: in this case, a file belongs to
27
30
/// the nearest enclosing source root. Paths to files are always relative to a
28
31
/// source root, and the analyzer does not know the root path of the source root at
29
32
/// all. So, a file from one source root can't refer to a file in another source
30
33
/// root by path.
31
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
32
- pub struct SourceRootId ( pub u32 ) ;
33
-
34
34
#[ derive( Clone , Debug , PartialEq , Eq ) ]
35
35
pub struct SourceRoot {
36
36
/// Sysroot or crates.io library.
37
37
///
38
38
/// Libraries are considered mostly immutable, this assumption is used to
39
39
/// optimize salsa's query structure
40
40
pub is_library : bool ,
41
+ cargo_file_id : Option < FileId > ,
42
+ ratoml_file_id : Option < FileId > ,
41
43
file_set : FileSet ,
42
44
}
43
45
44
46
impl SourceRoot {
45
47
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 }
47
50
}
48
51
49
52
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 }
51
54
}
52
55
53
56
pub fn path_for_file ( & self , file : & FileId ) -> Option < & VfsPath > {
@@ -65,6 +68,16 @@ impl SourceRoot {
65
68
pub fn iter ( & self ) -> impl Iterator < Item = FileId > + ' _ {
66
69
self . file_set . iter ( )
67
70
}
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
+ }
68
81
}
69
82
70
83
/// `CrateGraph` is a bit of information which turns a set of text files into a
0 commit comments