@@ -47,6 +47,30 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
4747 fuzzy_completion ( acc, ctx) . unwrap_or_default ( )
4848}
4949
50+ fn complete_enum_variants ( acc : & mut Completions , ctx : & CompletionContext , ty : & Type ) {
51+ if let Some ( Adt :: Enum ( enum_data) ) = ty. as_adt ( ) {
52+ let variants = enum_data. variants ( ctx. db ) ;
53+
54+ let module = if let Some ( module) = ctx. scope . module ( ) {
55+ // Compute path from the completion site if available.
56+ module
57+ } else {
58+ // Otherwise fall back to the enum's definition site.
59+ enum_data. module ( ctx. db )
60+ } ;
61+
62+ for variant in variants {
63+ if let Some ( path) = module. find_use_path ( ctx. db , ModuleDef :: from ( variant) ) {
64+ // Variants with trivial paths are already added by the existing completion logic,
65+ // so we should avoid adding these twice
66+ if path. segments . len ( ) > 1 {
67+ acc. add_qualified_enum_variant ( ctx, variant, path) ;
68+ }
69+ }
70+ }
71+ }
72+ }
73+
5074// TODO kb add a setting toggle for this feature?
5175fn fuzzy_completion ( acc : & mut Completions , ctx : & CompletionContext ) -> Option < ( ) > {
5276 let _p = profile:: span ( "fuzzy_completion®" ) ;
@@ -71,6 +95,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
7195 ScopeDef :: MacroDef ( macro_def) ,
7296 ) ) ,
7397 } )
98+ . filter ( |( mod_path, _) | mod_path. len ( ) > 1 )
7499 . filter_map ( |( mod_path, definition) | {
75100 let mut resolution_with_missing_import = render_resolution (
76101 RenderContext :: new ( ctx) ,
@@ -89,36 +114,13 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
89114 resolution_with_missing_import. update_text_edit ( text_edits. finish ( ) ) ;
90115
91116 Some ( resolution_with_missing_import)
92- } ) ;
117+ } )
118+ . take ( 20 ) ;
93119
94120 acc. add_all ( possible_imports) ;
95121 Some ( ( ) )
96122}
97123
98- fn complete_enum_variants ( acc : & mut Completions , ctx : & CompletionContext , ty : & Type ) {
99- if let Some ( Adt :: Enum ( enum_data) ) = ty. as_adt ( ) {
100- let variants = enum_data. variants ( ctx. db ) ;
101-
102- let module = if let Some ( module) = ctx. scope . module ( ) {
103- // Compute path from the completion site if available.
104- module
105- } else {
106- // Otherwise fall back to the enum's definition site.
107- enum_data. module ( ctx. db )
108- } ;
109-
110- for variant in variants {
111- if let Some ( path) = module. find_use_path ( ctx. db , ModuleDef :: from ( variant) ) {
112- // Variants with trivial paths are already added by the existing completion logic,
113- // so we should avoid adding these twice
114- if path. segments . len ( ) > 1 {
115- acc. add_qualified_enum_variant ( ctx, variant, path) ;
116- }
117- }
118- }
119- }
120- }
121-
122124#[ cfg( test) ]
123125mod tests {
124126 use expect_test:: { expect, Expect } ;
0 commit comments