@@ -7,6 +7,7 @@ use std::{panic, sync::Arc};
77
88use ra_prof:: profile;
99use ra_syntax:: { ast, Parse , SourceFile , TextRange , TextSize } ;
10+ use rustc_hash:: FxHashSet ;
1011
1112pub use crate :: {
1213 cancellation:: Canceled ,
@@ -95,7 +96,7 @@ pub trait FileLoader {
9596 /// `struct StrPath(str)` for clarity some day, but it's a bit messy, so we
9697 /// get by with a `&str` for the time being.
9798 fn resolve_path ( & self , anchor : FileId , path : & str ) -> Option < FileId > ;
98- fn relevant_crates ( & self , file_id : FileId ) -> Arc < Vec < CrateId > > ;
99+ fn relevant_crates ( & self , file_id : FileId ) -> Arc < FxHashSet < CrateId > > ;
99100}
100101
101102/// Database which stores all significant input facts: source code and project
@@ -133,16 +134,21 @@ pub trait SourceDatabaseExt: SourceDatabase {
133134 #[ salsa:: input]
134135 fn source_root ( & self , id : SourceRootId ) -> Arc < SourceRoot > ;
135136
136- fn source_root_crates ( & self , id : SourceRootId ) -> Arc < Vec < CrateId > > ;
137+ fn source_root_crates ( & self , id : SourceRootId ) -> Arc < FxHashSet < CrateId > > ;
137138}
138139
139140fn source_root_crates (
140141 db : & ( impl SourceDatabaseExt + SourceDatabase ) ,
141142 id : SourceRootId ,
142- ) -> Arc < Vec < CrateId > > {
143- let root = db. source_root ( id) ;
143+ ) -> Arc < FxHashSet < CrateId > > {
144144 let graph = db. crate_graph ( ) ;
145- let res = root. walk ( ) . filter_map ( |it| graph. crate_id_for_crate_root ( it) ) . collect :: < Vec < _ > > ( ) ;
145+ let res = graph
146+ . iter ( )
147+ . filter ( |& krate| {
148+ let root_file = graph[ krate] . root_file_id ;
149+ db. file_source_root ( root_file) == id
150+ } )
151+ . collect :: < FxHashSet < _ > > ( ) ;
146152 Arc :: new ( res)
147153}
148154
@@ -156,7 +162,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
156162 fn resolve_path ( & self , anchor : FileId , path : & str ) -> Option < FileId > {
157163 // FIXME: this *somehow* should be platform agnostic...
158164 if std:: path:: Path :: new ( path) . is_absolute ( ) {
159- let krate = * self . relevant_crates ( anchor) . get ( 0 ) ?;
165+ let krate = * self . relevant_crates ( anchor) . iter ( ) . next ( ) ?;
160166 let ( extern_source_id, relative_file) =
161167 self . 0 . crate_graph ( ) [ krate] . extern_source . extern_path ( path. as_ref ( ) ) ?;
162168
@@ -175,7 +181,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
175181 }
176182 }
177183
178- fn relevant_crates ( & self , file_id : FileId ) -> Arc < Vec < CrateId > > {
184+ fn relevant_crates ( & self , file_id : FileId ) -> Arc < FxHashSet < CrateId > > {
179185 let source_root = self . 0 . file_source_root ( file_id) ;
180186 self . 0 . source_root_crates ( source_root)
181187 }
0 commit comments