@@ -12,40 +12,49 @@ use cfg::CfgOptions;
1212use la_arena:: { Arena , Idx , RawIdx } ;
1313use rustc_hash:: { FxHashMap , FxHashSet } ;
1414use semver:: Version ;
15+ use serde:: Serialize ;
1516use syntax:: SmolStr ;
1617use triomphe:: Arc ;
1718use vfs:: { file_set:: FileSet , AbsPathBuf , AnchoredPath , FileId , VfsPath } ;
1819
1920// Map from crate id to the name of the crate and path of the proc-macro. If the value is `None`,
2021// then the crate for the proc-macro hasn't been build yet as the build data is missing.
2122pub type ProcMacroPaths = FxHashMap < CrateId , Result < ( Option < String > , AbsPathBuf ) , String > > ;
23+
24+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
25+ pub struct SourceRootId ( pub u32 ) ;
26+
2227/// Files are grouped into source roots. A source root is a directory on the
2328/// file systems which is watched for changes. Typically it corresponds to a
2429/// Rust crate. Source roots *might* be nested: in this case, a file belongs to
2530/// the nearest enclosing source root. Paths to files are always relative to a
2631/// source root, and the analyzer does not know the root path of the source root at
2732/// all. So, a file from one source root can't refer to a file in another source
2833/// root by path.
29- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
30- pub struct SourceRootId ( pub u32 ) ;
31-
3234#[ derive( Clone , Debug , PartialEq , Eq ) ]
3335pub struct SourceRoot {
3436 /// Sysroot or crates.io library.
3537 ///
3638 /// Libraries are considered mostly immutable, this assumption is used to
3739 /// optimize salsa's query structure
3840 pub is_library : bool ,
41+ cargo_file_id : Option < FileId > ,
42+ /// FIXME : @alibektas We know that this is wrong.
43+ /// base-db must stay as a level of abstraction
44+ /// that has no knowledge of such specific files
45+ /// so this should be moved somewhere else.
46+ ratoml_file_id : Option < FileId > ,
3947 file_set : FileSet ,
4048}
4149
4250impl SourceRoot {
4351 pub fn new_local ( file_set : FileSet ) -> SourceRoot {
44- SourceRoot { is_library : false , file_set }
52+ eprintln ! ( "{:#?}" , file_set) ;
53+ SourceRoot { is_library : false , file_set, cargo_file_id : None , ratoml_file_id : None }
4554 }
4655
4756 pub fn new_library ( file_set : FileSet ) -> SourceRoot {
48- SourceRoot { is_library : true , file_set }
57+ SourceRoot { is_library : true , file_set, cargo_file_id : None , ratoml_file_id : None }
4958 }
5059
5160 pub fn path_for_file ( & self , file : & FileId ) -> Option < & VfsPath > {
@@ -63,6 +72,16 @@ impl SourceRoot {
6372 pub fn iter ( & self ) -> impl Iterator < Item = FileId > + ' _ {
6473 self . file_set . iter ( )
6574 }
75+
76+ /// Get `FileId` of the `Cargo.toml` if one present in `SourceRoot`
77+ pub fn cargo_toml ( & self ) -> Option < FileId > {
78+ self . cargo_file_id
79+ }
80+
81+ /// Get `FileId` of the `rust-analyzer.toml` if one present in `SourceRoot`
82+ pub fn ratoml ( & self ) -> Option < FileId > {
83+ self . ratoml_file_id
84+ }
6685}
6786
6887/// `CrateGraph` is a bit of information which turns a set of text files into a
@@ -101,6 +120,15 @@ pub type CrateId = Idx<CrateData>;
101120#[ derive( Debug , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
102121pub struct CrateName ( SmolStr ) ;
103122
123+ impl Serialize for CrateName {
124+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
125+ where
126+ S : serde:: Serializer ,
127+ {
128+ serializer. serialize_str ( self )
129+ }
130+ }
131+
104132impl CrateName {
105133 /// Creates a crate name, checking for dashes in the string provided.
106134 /// Dashes are not allowed in the crate names,
0 commit comments