File tree 2 files changed +43
-6
lines changed
2 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,10 @@ impl Query {
200
200
pub fn can_complete_op ( & self ) -> bool {
201
201
// Deal with empty expressions first.
202
202
if let Some ( before) = & self . before {
203
+ if before. syntax . parent ( ) . map ( |e| e. kind ( ) ) == Some ( EXPR_BLOCK ) {
204
+ return false ;
205
+ }
206
+
203
207
if let Some ( exp_w) = before. expr_wrapper ( ) {
204
208
if let Some ( binary_exp) = exp_w. parent ( ) {
205
209
if binary_exp. kind ( ) == EXPR_BINARY {
@@ -219,6 +223,18 @@ impl Query {
219
223
}
220
224
221
225
if let Some ( after) = & self . after {
226
+ if after. syntax . parent ( ) . map ( |e| e. kind ( ) ) == Some ( EXPR_BLOCK ) {
227
+ return false ;
228
+ }
229
+
230
+ if after. syntax . kind ( ) == PUNCT_BRACE_END
231
+ && after. syntax . next_sibling_or_token ( ) . map ( |t| t. kind ( ) ) == Some ( LIT_STR )
232
+ && after. syntax . prev_sibling_or_token ( ) . map ( |t| t. kind ( ) )
233
+ == Some ( LIT_STR_TEMPLATE_INTERPOLATION )
234
+ {
235
+ return true ;
236
+ }
237
+
222
238
if let Some ( exp_w) = after. expr_wrapper ( ) {
223
239
if let Some ( binary_exp) = exp_w. parent ( ) {
224
240
if binary_exp. kind ( ) == EXPR_BINARY {
Original file line number Diff line number Diff line change @@ -177,6 +177,14 @@ fn test_query_path_segment_index() {
177
177
fn test_complete_ref ( ) {
178
178
let ( offsets, src) = src_cursor_offsets (
179
179
r#"$$
180
+ fn asd() {
181
+ if hello() is b {
182
+ $$
183
+ } else {
184
+ $$
185
+ }
186
+ }
187
+
180
188
let a =$$ $$;
181
189
$$
182
190
@@ -190,6 +198,10 @@ fn test_complete_ref() {
190
198
3*$$
191
199
}
192
200
201
+ fn b() {
202
+ a$$
203
+ }
204
+
193
205
const bar = $$;
194
206
195
207
{$$
@@ -211,6 +223,8 @@ fn test_complete_ref() {
211
223
fn test_complete_op ( ) {
212
224
let ( offsets, src) = src_cursor_offsets (
213
225
r#"
226
+ a = `${a $$}`;
227
+
214
228
let a = 3 $$;
215
229
216
230
let b = a $$;
@@ -221,6 +235,7 @@ fn test_complete_op() {
221
235
222
236
let c = "foo" $$
223
237
238
+ let in_template = `a ${a $$} b`;
224
239
"# ,
225
240
) ;
226
241
@@ -234,9 +249,7 @@ fn test_complete_op() {
234
249
assert ! ( q. can_complete_op( ) , "test failed for index {idx}" , ) ;
235
250
}
236
251
237
- let ( offsets, src) = src_cursor_offsets (
238
- r#"a op 2 $$"# ,
239
- ) ;
252
+ let ( offsets, src) = src_cursor_offsets ( r#"a op 2 $$"# ) ;
240
253
241
254
let syntax = Parser :: new ( & src)
242
255
. with_operator ( "op" , Operator :: default ( ) )
@@ -250,16 +263,24 @@ fn test_complete_op() {
250
263
}
251
264
252
265
#[ test]
253
- fn test_complete_op_fails ( ) {
266
+ fn test_op_completion_should_fail ( ) {
254
267
let ( offsets, src) = src_cursor_offsets (
255
268
r#"
256
269
let a = $$ op foo;
257
270
258
271
let a = 3* $$;
259
-
272
+
260
273
let a = 3*$$;
261
-
274
+
262
275
let b = $$ + $$;
276
+
277
+ fn asd() {
278
+ if hello() + 2 {
279
+ $$
280
+ } else {
281
+ $$
282
+ }
283
+ }
263
284
"# ,
264
285
) ;
265
286
You can’t perform that action at this time.
0 commit comments