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