@@ -8,7 +8,7 @@ use hir_def::{
88 resolver:: { self , HasResolver , Resolver } ,
99 AsMacroCall , FunctionId , TraitId , VariantId ,
1010} ;
11- use hir_expand:: { diagnostics:: AstDiagnostic , hygiene:: Hygiene , ExpansionInfo } ;
11+ use hir_expand:: { diagnostics:: AstDiagnostic , hygiene:: Hygiene , name :: AsName , ExpansionInfo } ;
1212use hir_ty:: associated_type_shorthand_candidates;
1313use itertools:: Itertools ;
1414use ra_db:: { FileId , FileRange } ;
@@ -24,8 +24,8 @@ use crate::{
2424 diagnostics:: Diagnostic ,
2525 semantics:: source_to_def:: { ChildContainer , SourceToDefCache , SourceToDefCtx } ,
2626 source_analyzer:: { resolve_hir_path, resolve_hir_path_qualifier, SourceAnalyzer } ,
27- AssocItem , Callable , Field , Function , HirFileId , ImplDef , InFile , Local , MacroDef , Module ,
28- ModuleDef , Name , Origin , Path , ScopeDef , Trait , Type , TypeAlias , TypeParam , VariantDef ,
27+ AssocItem , Callable , Crate , Field , Function , HirFileId , ImplDef , InFile , Local , MacroDef ,
28+ Module , ModuleDef , Name , Origin , Path , ScopeDef , Trait , Type , TypeAlias , TypeParam , VariantDef ,
2929} ;
3030use resolver:: TypeNs ;
3131
@@ -228,6 +228,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
228228 self . imp . resolve_path ( path)
229229 }
230230
231+ pub fn resolve_extern_crate ( & self , extern_crate : & ast:: ExternCrate ) -> Option < Crate > {
232+ self . imp . resolve_extern_crate ( extern_crate)
233+ }
234+
231235 pub fn resolve_variant ( & self , record_lit : ast:: RecordExpr ) -> Option < VariantDef > {
232236 self . imp . resolve_variant ( record_lit) . map ( VariantDef :: from)
233237 }
@@ -443,6 +447,17 @@ impl<'db> SemanticsImpl<'db> {
443447 self . analyze ( path. syntax ( ) ) . resolve_path ( self . db , path)
444448 }
445449
450+ fn resolve_extern_crate ( & self , extern_crate : & ast:: ExternCrate ) -> Option < Crate > {
451+ let krate = self . scope ( extern_crate. syntax ( ) ) . krate ( ) ?;
452+ krate. dependencies ( self . db ) . into_iter ( ) . find_map ( |dep| {
453+ if dep. name == extern_crate. name_ref ( ) ?. as_name ( ) {
454+ Some ( dep. krate )
455+ } else {
456+ None
457+ }
458+ } )
459+ }
460+
446461 fn resolve_variant ( & self , record_lit : ast:: RecordExpr ) -> Option < VariantId > {
447462 self . analyze ( record_lit. syntax ( ) ) . resolve_variant ( self . db , record_lit)
448463 }
@@ -612,6 +627,10 @@ impl<'a> SemanticsScope<'a> {
612627 Some ( Module { id : self . resolver . module ( ) ? } )
613628 }
614629
630+ pub fn krate ( & self ) -> Option < Crate > {
631+ Some ( Crate { id : self . resolver . krate ( ) ? } )
632+ }
633+
615634 /// Note: `FxHashSet<TraitId>` should be treated as an opaque type, passed into `Type
616635 // FIXME: rename to visible_traits to not repeat scope?
617636 pub fn traits_in_scope ( & self ) -> FxHashSet < TraitId > {
0 commit comments