@@ -7,7 +7,7 @@ mod tests;
7
7
use std:: { iter, ops:: ControlFlow } ;
8
8
9
9
use hir:: {
10
- db :: DefDatabase , HasAttrs , Local , ModuleSource , Name , PathResolution , ScopeDef , Semantics ,
10
+ HasAttrs , Local , ModPath , ModuleDef , ModuleSource , Name , PathResolution , ScopeDef , Semantics ,
11
11
SemanticsScope , Symbol , Type , TypeInfo ,
12
12
} ;
13
13
use ide_db:: {
@@ -758,15 +758,43 @@ impl<'a> CompletionContext<'a> {
758
758
} ) ;
759
759
760
760
let depth_from_crate_root = iter:: successors ( Some ( module) , |m| m. parent ( db) )
761
- // `BlockExpr` modules are not count as module depth
761
+ // `BlockExpr` modules do not count towards module depth
762
762
. filter ( |m| !matches ! ( m. definition_source( db) . value, ModuleSource :: BlockExpr ( _) ) )
763
763
. count ( )
764
764
// exclude `m` itself
765
765
. saturating_sub ( 1 ) ;
766
766
767
- let exclude_traits = resolve_exclude_traits_list ( db, config. exclude_traits ) ;
768
- let mut exclude_flyimport_traits =
769
- resolve_exclude_traits_list ( db, config. exclude_flyimport_traits ) ;
767
+ let exclude_traits: FxHashSet < _ > = config
768
+ . exclude_traits
769
+ . iter ( )
770
+ . filter_map ( |path| {
771
+ scope
772
+ . resolve_mod_path ( & ModPath :: from_segments (
773
+ hir:: PathKind :: Plain ,
774
+ path. split ( "::" ) . map ( Symbol :: intern) . map ( Name :: new_symbol_root) ,
775
+ ) )
776
+ . find_map ( |it| match it {
777
+ hir:: ItemInNs :: Types ( ModuleDef :: Trait ( t) ) => Some ( t) ,
778
+ _ => None ,
779
+ } )
780
+ } )
781
+ . collect ( ) ;
782
+
783
+ let mut exclude_flyimport_traits: FxHashSet < _ > = config
784
+ . exclude_flyimport_traits
785
+ . iter ( )
786
+ . filter_map ( |path| {
787
+ scope
788
+ . resolve_mod_path ( & ModPath :: from_segments (
789
+ hir:: PathKind :: Plain ,
790
+ path. split ( "::" ) . map ( Symbol :: intern) . map ( Name :: new_symbol_root) ,
791
+ ) )
792
+ . find_map ( |it| match it {
793
+ hir:: ItemInNs :: Types ( ModuleDef :: Trait ( t) ) => Some ( t) ,
794
+ _ => None ,
795
+ } )
796
+ } )
797
+ . collect ( ) ;
770
798
exclude_flyimport_traits. extend ( exclude_traits. iter ( ) . copied ( ) ) ;
771
799
772
800
let complete_semicolon = if config. add_semicolon_to_unit {
@@ -841,71 +869,6 @@ impl<'a> CompletionContext<'a> {
841
869
}
842
870
}
843
871
844
- fn resolve_exclude_traits_list ( db : & RootDatabase , traits : & [ String ] ) -> FxHashSet < hir:: Trait > {
845
- let _g = tracing:: debug_span!( "resolve_exclude_trait_list" , ?traits) . entered ( ) ;
846
- let crate_graph = db. crate_graph ( ) ;
847
- let mut crate_name_to_def_map = FxHashMap :: default ( ) ;
848
- let mut result = FxHashSet :: default ( ) ;
849
- ' process_traits: for trait_ in traits {
850
- let mut segments = trait_. split ( "::" ) . peekable ( ) ;
851
- let Some ( crate_name) = segments. next ( ) else {
852
- tracing:: error!(
853
- ?trait_,
854
- "error resolving trait from traits exclude list: invalid path"
855
- ) ;
856
- continue ;
857
- } ;
858
- let Some ( def_map) = crate_name_to_def_map. entry ( crate_name) . or_insert_with ( || {
859
- let krate = crate_graph
860
- . iter ( )
861
- . find ( |& krate| crate_graph[ krate] . display_name . as_deref ( ) == Some ( crate_name) ) ;
862
- let def_map = krate. map ( |krate| db. crate_def_map ( krate) ) ;
863
- if def_map. is_none ( ) {
864
- tracing:: error!(
865
- "error resolving `{trait_}` from trait exclude lists: crate could not be found"
866
- ) ;
867
- }
868
- def_map
869
- } ) else {
870
- // Do not report more than one error for the same crate.
871
- continue ;
872
- } ;
873
- let mut module = & def_map[ hir:: DefMap :: ROOT ] ;
874
- let trait_name = ' lookup_mods: {
875
- while let Some ( segment) = segments. next ( ) {
876
- if segments. peek ( ) . is_none ( ) {
877
- break ' lookup_mods segment;
878
- }
879
-
880
- let Some ( & inner) =
881
- module. children . get ( & Name :: new_symbol_root ( hir:: Symbol :: intern ( segment) ) )
882
- else {
883
- tracing:: error!(
884
- "error resolving `{trait_}` from trait exclude lists: could not find module `{segment}`"
885
- ) ;
886
- continue ' process_traits;
887
- } ;
888
- module = & def_map[ inner] ;
889
- }
890
-
891
- tracing:: error!( "error resolving `{trait_}` from trait exclude lists: invalid path" ) ;
892
- continue ' process_traits;
893
- } ;
894
- let resolved_trait = module
895
- . scope
896
- . trait_by_name ( & Name :: new_symbol_root ( hir:: Symbol :: intern ( trait_name) ) )
897
- . map ( hir:: Trait :: from) ;
898
- let Some ( resolved_trait) = resolved_trait else {
899
- tracing:: error!(
900
- "error resolving `{trait_}` from trait exclude lists: trait could not be found"
901
- ) ;
902
- continue ;
903
- } ;
904
- result. insert ( resolved_trait) ;
905
- }
906
- result
907
- }
908
-
909
872
const OP_TRAIT_LANG_NAMES : & [ & str ] = & [
910
873
"add_assign" ,
911
874
"add" ,
0 commit comments