@@ -49,15 +49,19 @@ impl<'a> MacroRender<'a> {
49
49
. add_import ( import_to_add)
50
50
. set_detail ( self . detail ( ) ) ;
51
51
52
- let needs_bang = self . needs_bang ( ) ;
52
+ let needs_bang = !( self . ctx . completion . in_use_tree ( )
53
+ || matches ! ( self . ctx. completion. path_call_kind( ) , Some ( CallKind :: Mac ) ) ) ;
54
+ let has_parens = self . ctx . completion . path_call_kind ( ) . is_some ( ) ;
55
+
53
56
match self . ctx . snippet_cap ( ) {
54
- Some ( cap) if needs_bang => {
55
- let snippet = self . snippet ( ) ;
56
- let lookup = self . lookup ( ) ;
57
+ Some ( cap) if needs_bang && !has_parens => {
58
+ let snippet = format ! ( "{}!{}$0{}" , self . name , self . bra , self . ket ) ;
59
+ let lookup = self . banged_name ( ) ;
57
60
item. insert_snippet ( cap, snippet) . lookup_by ( lookup) ;
58
61
}
59
- None if needs_bang => {
60
- item. insert_text ( self . banged_name ( ) ) ;
62
+ _ if needs_bang => {
63
+ let lookup = self . banged_name ( ) ;
64
+ item. insert_text ( self . banged_name ( ) ) . lookup_by ( lookup) ;
61
65
}
62
66
_ => {
63
67
cov_mark:: hit!( dont_insert_macro_call_parens_unncessary) ;
@@ -83,14 +87,6 @@ impl<'a> MacroRender<'a> {
83
87
}
84
88
}
85
89
86
- fn snippet ( & self ) -> String {
87
- format ! ( "{}!{}$0{}" , self . name, self . bra, self . ket)
88
- }
89
-
90
- fn lookup ( & self ) -> String {
91
- self . banged_name ( )
92
- }
93
-
94
90
fn banged_name ( & self ) -> String {
95
91
format ! ( "{}!" , self . name)
96
92
}
@@ -163,6 +159,25 @@ fn main() { frobnicate!(); }
163
159
) ;
164
160
}
165
161
162
+ #[ test]
163
+ fn add_bang_to_parens ( ) {
164
+ check_edit (
165
+ "frobnicate!" ,
166
+ r#"
167
+ macro_rules! frobnicate { () => () }
168
+ fn main() {
169
+ frob$0()
170
+ }
171
+ "# ,
172
+ r#"
173
+ macro_rules! frobnicate { () => () }
174
+ fn main() {
175
+ frobnicate!()
176
+ }
177
+ "# ,
178
+ ) ;
179
+ }
180
+
166
181
#[ test]
167
182
fn guesses_macro_braces ( ) {
168
183
check_edit (
0 commit comments