@@ -5,8 +5,7 @@ mod completion_context;
55mod presentation;
66
77mod complete_dot;
8- mod complete_record_literal;
9- mod complete_record_pattern;
8+ mod complete_record;
109mod complete_pattern;
1110mod complete_fn_param;
1211mod complete_keyword;
@@ -32,12 +31,6 @@ use crate::{
3231pub use crate :: completion:: completion_item:: {
3332 CompletionItem , CompletionItemKind , InsertTextFormat ,
3433} ;
35- use either:: Either ;
36- use hir:: { StructField , Type } ;
37- use ra_syntax:: {
38- ast:: { self , NameOwner } ,
39- SmolStr ,
40- } ;
4134
4235#[ derive( Clone , Debug , PartialEq , Eq ) ]
4336pub struct CompletionConfig {
@@ -95,66 +88,11 @@ pub(crate) fn completions(
9588 complete_path:: complete_path ( & mut acc, & ctx) ;
9689 complete_scope:: complete_scope ( & mut acc, & ctx) ;
9790 complete_dot:: complete_dot ( & mut acc, & ctx) ;
98- complete_record_literal:: complete_record_literal ( & mut acc, & ctx) ;
99- complete_record_pattern:: complete_record_pattern ( & mut acc, & ctx) ;
91+ complete_record:: complete_record ( & mut acc, & ctx) ;
10092 complete_pattern:: complete_pattern ( & mut acc, & ctx) ;
10193 complete_postfix:: complete_postfix ( & mut acc, & ctx) ;
10294 complete_macro_in_item_position:: complete_macro_in_item_position ( & mut acc, & ctx) ;
10395 complete_trait_impl:: complete_trait_impl ( & mut acc, & ctx) ;
10496
10597 Some ( acc)
10698}
107-
108- pub ( crate ) fn get_missing_fields (
109- ctx : & CompletionContext ,
110- record : Either < & ast:: RecordLit , & ast:: RecordPat > ,
111- ) -> Option < Vec < ( StructField , Type ) > > {
112- let ( ty, variant) = match record {
113- Either :: Left ( record_lit) => (
114- ctx. sema . type_of_expr ( & record_lit. clone ( ) . into ( ) ) ?,
115- ctx. sema . resolve_record_literal ( record_lit) ?,
116- ) ,
117- Either :: Right ( record_pat) => (
118- ctx. sema . type_of_pat ( & record_pat. clone ( ) . into ( ) ) ?,
119- ctx. sema . resolve_record_pattern ( record_pat) ?,
120- ) ,
121- } ;
122-
123- let already_present_names = get_already_present_names ( record) ;
124- Some (
125- ty. variant_fields ( ctx. db , variant)
126- . into_iter ( )
127- . filter ( |( field, _) | {
128- !already_present_names. contains ( & SmolStr :: from ( field. name ( ctx. db ) . to_string ( ) ) )
129- } )
130- . collect ( ) ,
131- )
132- }
133-
134- fn get_already_present_names ( record : Either < & ast:: RecordLit , & ast:: RecordPat > ) -> Vec < SmolStr > {
135- // TODO kb have a single match
136- match record {
137- Either :: Left ( record_lit) => record_lit
138- . record_field_list ( )
139- . map ( |field_list| field_list. fields ( ) )
140- . map ( |fields| {
141- fields
142- . into_iter ( )
143- . filter_map ( |field| field. name_ref ( ) )
144- . map ( |name_ref| name_ref. text ( ) . clone ( ) )
145- . collect ( )
146- } )
147- . unwrap_or_default ( ) ,
148- Either :: Right ( record_pat) => record_pat
149- . record_field_pat_list ( )
150- . map ( |pat_list| pat_list. bind_pats ( ) )
151- . map ( |bind_pats| {
152- bind_pats
153- . into_iter ( )
154- . filter_map ( |pat| pat. name ( ) )
155- . map ( |name| name. text ( ) . clone ( ) )
156- . collect ( )
157- } )
158- . unwrap_or_default ( ) ,
159- }
160- }
0 commit comments