@@ -86,7 +86,14 @@ impl<'a> NodeFinder<'a> {
8686 None , // trait_id
8787 false , // self_prefix
8888 ) ,
89- ModuleDefId :: TypeId ( struct_id) => vec ! [ self . struct_completion_item( name, struct_id) ] ,
89+ ModuleDefId :: TypeId ( type_id) => {
90+ let data_type = self . interner . get_type ( type_id) ;
91+ if data_type. borrow ( ) . is_struct ( ) {
92+ vec ! [ self . struct_completion_item( name, type_id) ]
93+ } else {
94+ vec ! [ self . enum_completion_item( name, type_id) ]
95+ }
96+ }
9097 ModuleDefId :: TypeAliasId ( id) => vec ! [ self . type_alias_completion_item( name, id) ] ,
9198 ModuleDefId :: TraitId ( trait_id) => vec ! [ self . trait_completion_item( name, trait_id) ] ,
9299 ModuleDefId :: GlobalId ( global_id) => vec ! [ self . global_completion_item( name, global_id) ] ,
@@ -106,14 +113,18 @@ impl<'a> NodeFinder<'a> {
106113 name : impl Into < String > ,
107114 id : ModuleId ,
108115 ) -> CompletionItem {
109- let completion_item = module_completion_item ( name) ;
110- self . completion_item_with_doc_comments ( ReferenceId :: Module ( id) , completion_item )
116+ let item = module_completion_item ( name) ;
117+ self . completion_item_with_doc_comments ( ReferenceId :: Module ( id) , item )
111118 }
112119
113- fn struct_completion_item ( & self , name : String , struct_id : TypeId ) -> CompletionItem {
114- let completion_item =
115- simple_completion_item ( name. clone ( ) , CompletionItemKind :: STRUCT , Some ( name) ) ;
116- self . completion_item_with_doc_comments ( ReferenceId :: Type ( struct_id) , completion_item)
120+ fn struct_completion_item ( & self , name : String , type_id : TypeId ) -> CompletionItem {
121+ let items = simple_completion_item ( name. clone ( ) , CompletionItemKind :: STRUCT , Some ( name) ) ;
122+ self . completion_item_with_doc_comments ( ReferenceId :: Type ( type_id) , items)
123+ }
124+
125+ fn enum_completion_item ( & self , name : String , type_id : TypeId ) -> CompletionItem {
126+ let item = simple_completion_item ( name. clone ( ) , CompletionItemKind :: ENUM , Some ( name) ) ;
127+ self . completion_item_with_doc_comments ( ReferenceId :: Type ( type_id) , item)
117128 }
118129
119130 pub ( super ) fn struct_field_completion_item (
@@ -124,33 +135,42 @@ impl<'a> NodeFinder<'a> {
124135 field_index : usize ,
125136 self_type : bool ,
126137 ) -> CompletionItem {
127- let completion_item = struct_field_completion_item ( field, typ, self_type) ;
128- self . completion_item_with_doc_comments (
129- ReferenceId :: StructMember ( struct_id, field_index) ,
130- completion_item,
131- )
138+ let item = struct_field_completion_item ( field, typ, self_type) ;
139+ let reference_id = ReferenceId :: StructMember ( struct_id, field_index) ;
140+ self . completion_item_with_doc_comments ( reference_id, item)
132141 }
133142
134143 fn type_alias_completion_item ( & self , name : String , id : TypeAliasId ) -> CompletionItem {
135- let completion_item =
136- simple_completion_item ( name. clone ( ) , CompletionItemKind :: STRUCT , Some ( name) ) ;
137- self . completion_item_with_doc_comments ( ReferenceId :: Alias ( id) , completion_item)
144+ let item = simple_completion_item ( name. clone ( ) , CompletionItemKind :: STRUCT , Some ( name) ) ;
145+ self . completion_item_with_doc_comments ( ReferenceId :: Alias ( id) , item)
138146 }
139147
140148 fn trait_completion_item ( & self , name : String , trait_id : TraitId ) -> CompletionItem {
141- let completion_item =
142- simple_completion_item ( name. clone ( ) , CompletionItemKind :: INTERFACE , Some ( name) ) ;
143- self . completion_item_with_doc_comments ( ReferenceId :: Trait ( trait_id) , completion_item)
149+ let item = simple_completion_item ( name. clone ( ) , CompletionItemKind :: INTERFACE , Some ( name) ) ;
150+ self . completion_item_with_doc_comments ( ReferenceId :: Trait ( trait_id) , item)
144151 }
145152
146153 fn global_completion_item ( & self , name : String , global_id : GlobalId ) -> CompletionItem {
147154 let global = self . interner . get_global ( global_id) ;
148155 let typ = self . interner . definition_type ( global. definition_id ) ;
149156 let description = typ. to_string ( ) ;
157+ let item = simple_completion_item ( name, CompletionItemKind :: CONSTANT , Some ( description) ) ;
158+ self . completion_item_with_doc_comments ( ReferenceId :: Global ( global_id) , item)
159+ }
150160
151- let completion_item =
152- simple_completion_item ( name, CompletionItemKind :: CONSTANT , Some ( description) ) ;
153- self . completion_item_with_doc_comments ( ReferenceId :: Global ( global_id) , completion_item)
161+ pub ( super ) fn enum_variant_completion_item (
162+ & self ,
163+ name : String ,
164+ type_id : TypeId ,
165+ variant_index : usize ,
166+ ) -> CompletionItem {
167+ let kind = CompletionItemKind :: ENUM_MEMBER ;
168+ let item = simple_completion_item ( name. clone ( ) , kind, Some ( name. clone ( ) ) ) ;
169+ let item = completion_item_with_detail ( item, name) ;
170+ self . completion_item_with_doc_comments (
171+ ReferenceId :: EnumVariant ( type_id, variant_index) ,
172+ item,
173+ )
154174 }
155175
156176 #[ allow( clippy:: too_many_arguments) ]
@@ -354,6 +374,8 @@ impl<'a> NodeFinder<'a> {
354374 if let ( Some ( type_id) , Some ( variant_index) ) =
355375 ( func_meta. type_id , func_meta. enum_variant_index )
356376 {
377+ completion_item. kind = Some ( CompletionItemKind :: ENUM_MEMBER ) ;
378+
357379 self . completion_item_with_doc_comments (
358380 ReferenceId :: EnumVariant ( type_id, variant_index) ,
359381 completion_item,
0 commit comments