@@ -228,13 +228,17 @@ fn add_type_alias_impl(
228
228
let alias_name = type_alias. name ( ctx. db ) . to_smol_str ( ) ;
229
229
230
230
let label = format ! ( "type {} =" , alias_name) ;
231
- let snippet = format ! ( "type {} = " , alias_name) ;
231
+ let replacement = format ! ( "type {} = " , alias_name) ;
232
232
233
233
let mut item = CompletionItem :: new ( SymbolKind :: TypeAlias , replacement_range, label) ;
234
- item. text_edit ( TextEdit :: replace ( replacement_range, snippet) )
235
- . lookup_by ( format ! ( "type {}" , alias_name) )
234
+ item. lookup_by ( format ! ( "type {}" , alias_name) )
236
235
. set_documentation ( type_alias. docs ( ctx. db ) )
237
236
. set_relevance ( CompletionRelevance { is_item_from_trait : true , ..Default :: default ( ) } ) ;
237
+ match ctx. config . snippet_cap {
238
+ Some ( cap) => item
239
+ . snippet_edit ( cap, TextEdit :: replace ( replacement_range, format ! ( "{}$0;" , replacement) ) ) ,
240
+ None => item. text_edit ( TextEdit :: replace ( replacement_range, replacement) ) ,
241
+ } ;
238
242
item. add_to ( acc) ;
239
243
}
240
244
@@ -257,16 +261,22 @@ fn add_const_impl(
257
261
} ;
258
262
259
263
let label = make_const_compl_syntax ( & transformed_const) ;
260
- let snippet = format ! ( "{} " , label) ;
264
+ let replacement = format ! ( "{} " , label) ;
261
265
262
266
let mut item = CompletionItem :: new ( SymbolKind :: Const , replacement_range, label) ;
263
- item. text_edit ( TextEdit :: replace ( replacement_range, snippet) )
264
- . lookup_by ( format ! ( "const {}" , const_name) )
267
+ item. lookup_by ( format ! ( "const {}" , const_name) )
265
268
. set_documentation ( const_. docs ( ctx. db ) )
266
269
. set_relevance ( CompletionRelevance {
267
270
is_item_from_trait : true ,
268
271
..Default :: default ( )
269
272
} ) ;
273
+ match ctx. config . snippet_cap {
274
+ Some ( cap) => item. snippet_edit (
275
+ cap,
276
+ TextEdit :: replace ( replacement_range, format ! ( "{}$0;" , replacement) ) ,
277
+ ) ,
278
+ None => item. text_edit ( TextEdit :: replace ( replacement_range, replacement) ) ,
279
+ } ;
270
280
item. add_to ( acc) ;
271
281
}
272
282
}
@@ -678,7 +688,7 @@ trait Test {
678
688
}
679
689
680
690
impl Test for () {
681
- type SomeType = \n \
691
+ type SomeType = $0; \n \
682
692
}
683
693
" ,
684
694
) ;
@@ -703,7 +713,7 @@ trait Test {
703
713
}
704
714
705
715
impl Test for () {
706
- const SOME_CONST: u16 = \n \
716
+ const SOME_CONST: u16 = $0; \n \
707
717
}
708
718
" ,
709
719
) ;
@@ -725,7 +735,7 @@ trait Test {
725
735
}
726
736
727
737
impl Test for () {
728
- const SOME_CONST: u16 = \n \
738
+ const SOME_CONST: u16 = $0; \n \
729
739
}
730
740
" ,
731
741
) ;
@@ -784,8 +794,8 @@ impl Test for T {{
784
794
"default const OTHER_CONST: i32 = 0;" ,
785
795
] {
786
796
test ( "fn bar" , "fn $0" , "fn bar() {\n $0\n }" , next_sibling) ;
787
- test ( "type Foo" , "type $0" , "type Foo = " , next_sibling) ;
788
- test ( "const CONST" , "const $0" , "const CONST: u16 = " , next_sibling) ;
797
+ test ( "type Foo" , "type $0" , "type Foo = $0; " , next_sibling) ;
798
+ test ( "const CONST" , "const $0" , "const CONST: u16 = $0; " , next_sibling) ;
789
799
}
790
800
}
791
801
@@ -831,8 +841,8 @@ impl Foo for T {{
831
841
)
832
842
} ;
833
843
test ( "fn function" , "fn f$0" , "fn function() {\n $0\n }" ) ;
834
- test ( "type Type" , "type T$0" , "type Type = " ) ;
835
- test ( "const CONST" , "const C$0" , "const CONST: i32 = " ) ;
844
+ test ( "type Type" , "type T$0" , "type Type = $0; " ) ;
845
+ test ( "const CONST" , "const C$0" , "const CONST: i32 = $0; " ) ;
836
846
}
837
847
838
848
#[ test]
@@ -962,7 +972,7 @@ trait Foo<T> {
962
972
struct Bar;
963
973
964
974
impl Foo<u32> for Bar {
965
- const B$0;
975
+ const B$0
966
976
}
967
977
"# ,
968
978
r#"
@@ -972,7 +982,7 @@ trait Foo<T> {
972
982
struct Bar;
973
983
974
984
impl Foo<u32> for Bar {
975
- const BAR: u32 = ;
985
+ const BAR: u32 = $0 ;
976
986
}
977
987
"# ,
978
988
)
0 commit comments