@@ -206,7 +206,8 @@ let findArgCompletables ~(args : arg list) ~endPos ~posBeforeCursor
206
206
})
207
207
| _ -> loop args
208
208
209
- let rec exprToContextPathInner (e : Parsetree.expression ) =
209
+ let rec exprToContextPathInner ~(inJsxContext : bool ) (e : Parsetree.expression )
210
+ =
210
211
match e.pexp_desc with
211
212
| Pexp_constant (Pconst_string _ ) -> Some Completable. CPString
212
213
| Pexp_constant (Pconst_integer _ ) -> Some CPInt
@@ -217,13 +218,13 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
217
218
(CPArray
218
219
(match exprs with
219
220
| [] -> None
220
- | exp :: _ -> exprToContextPath exp))
221
+ | exp :: _ -> exprToContextPath ~in JsxContext exp))
221
222
| Pexp_ident {txt = Lident ("|." | "|.u" )} -> None
222
223
| Pexp_ident {txt; loc} ->
223
224
Some
224
225
(CPId {path = Utils. flattenLongIdent txt; completionContext = Value ; loc})
225
226
| Pexp_field (e1 , {txt = Lident name } ) -> (
226
- match exprToContextPath e1 with
227
+ match exprToContextPath ~in JsxContext e1 with
227
228
| Some contextPath ->
228
229
Some
229
230
(CPField
@@ -232,6 +233,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
232
233
fieldName = name;
233
234
posOfDot = None ;
234
235
exprLoc = e1.pexp_loc;
236
+ inJsx = inJsxContext;
235
237
})
236
238
| _ -> None )
237
239
| Pexp_field (e1 , {loc; txt = Ldot (lid , name )} ) ->
@@ -249,9 +251,10 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
249
251
fieldName = name;
250
252
posOfDot = None ;
251
253
exprLoc = e1.pexp_loc;
254
+ inJsx = inJsxContext;
252
255
})
253
256
| Pexp_send (e1 , {txt} ) -> (
254
- match exprToContextPath e1 with
257
+ match exprToContextPath ~in JsxContext e1 with
255
258
| None -> None
256
259
| Some contexPath -> Some (CPObj (contexPath, txt)))
257
260
| Pexp_apply
@@ -261,7 +264,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
261
264
(_, {pexp_desc = Pexp_apply (d, args); pexp_loc; pexp_attributes});
262
265
] ) ->
263
266
(* Transform away pipe with apply call *)
264
- exprToContextPath
267
+ exprToContextPath ~in JsxContext
265
268
{
266
269
pexp_desc = Pexp_apply (d, (Nolabel , lhs) :: args);
267
270
pexp_loc;
@@ -272,7 +275,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
272
275
[(_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes})]
273
276
) ->
274
277
(* Transform away pipe with identifier *)
275
- exprToContextPath
278
+ exprToContextPath ~in JsxContext
276
279
{
277
280
pexp_desc =
278
281
Pexp_apply
@@ -282,26 +285,28 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
282
285
pexp_attributes;
283
286
}
284
287
| Pexp_apply (e1 , args ) -> (
285
- match exprToContextPath e1 with
288
+ match exprToContextPath ~in JsxContext e1 with
286
289
| None -> None
287
290
| Some contexPath -> Some (CPApply (contexPath, args |> List. map fst)))
288
291
| Pexp_tuple exprs ->
289
- let exprsAsContextPaths = exprs |> List. filter_map exprToContextPath in
292
+ let exprsAsContextPaths =
293
+ exprs |> List. filter_map (exprToContextPath ~in JsxContext)
294
+ in
290
295
if List. length exprs = List. length exprsAsContextPaths then
291
296
Some (CTuple exprsAsContextPaths)
292
297
else None
293
298
| _ -> None
294
299
295
- and exprToContextPath (e : Parsetree.expression ) =
300
+ and exprToContextPath ~( inJsxContext : bool ) (e : Parsetree.expression ) =
296
301
match
297
302
( Res_parsetree_viewer. has_await_attribute e.pexp_attributes,
298
- exprToContextPathInner e )
303
+ exprToContextPathInner ~in JsxContext e )
299
304
with
300
305
| true , Some ctxPath -> Some (CPAwait ctxPath)
301
306
| false , Some ctxPath -> Some ctxPath
302
307
| _ , None -> None
303
308
304
- let completePipeChain (exp : Parsetree.expression ) =
309
+ let completePipeChain ~( inJsxContext : bool ) (exp : Parsetree.expression ) =
305
310
(* Complete the end of pipe chains by reconstructing the pipe chain as a single pipe,
306
311
so it can be completed.
307
312
Example:
@@ -315,13 +320,15 @@ let completePipeChain (exp : Parsetree.expression) =
315
320
| Pexp_apply
316
321
( {pexp_desc = Pexp_ident {txt = Lident (" |." | " |.u" )}},
317
322
[_; (_, {pexp_desc = Pexp_apply (d, _)})] ) ->
318
- exprToContextPath exp |> Option. map (fun ctxPath -> (ctxPath, d.pexp_loc))
323
+ exprToContextPath ~in JsxContext exp
324
+ |> Option. map (fun ctxPath -> (ctxPath, d.pexp_loc))
319
325
(* When the left side of the pipe we're completing is an identifier application.
320
326
Example: someArray->filterAllTheGoodStuff-> *)
321
327
| Pexp_apply
322
328
( {pexp_desc = Pexp_ident {txt = Lident (" |." | " |.u" )}},
323
329
[_; (_, {pexp_desc = Pexp_ident _; pexp_loc})] ) ->
324
- exprToContextPath exp |> Option. map (fun ctxPath -> (ctxPath, pexp_loc))
330
+ exprToContextPath ~in JsxContext exp
331
+ |> Option. map (fun ctxPath -> (ctxPath, pexp_loc))
325
332
| _ -> None
326
333
327
334
let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
@@ -408,6 +415,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
408
415
(Completable. toString x);
409
416
result := Some (x, ! scope)
410
417
in
418
+ let inJsxContext = ref false in
411
419
let setResult x = setResultOpt (Some x) in
412
420
let scopeValueDescription (vd : Parsetree.value_description ) =
413
421
scope :=
@@ -542,9 +550,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
542
550
(* Pipe chains get special treatment here, because when assigning values
543
551
we want the return of the entire pipe chain as a function call, rather
544
552
than as a pipe completion call. *)
545
- match completePipeChain vb.pvb_expr with
553
+ match completePipeChain ~in JsxContext: ! inJsxContext vb.pvb_expr with
546
554
| Some (ctxPath , _ ) -> Some ctxPath
547
- | None -> exprToContextPath vb.pvb_expr
555
+ | None -> exprToContextPath ~in JsxContext: ! inJsxContext vb.pvb_expr
548
556
in
549
557
scopePattern ?contextPath vb.pvb_pat
550
558
in
@@ -576,7 +584,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
576
584
scope :=
577
585
! scope |> Scope. addModule ~name: md.pmd_name.txt ~loc: md.pmd_name.loc
578
586
in
579
- let inJsxContext = ref false in
587
+
580
588
(* Identifies expressions where we can do typed pattern or expr completion. *)
581
589
let typedCompletionExpr (exp : Parsetree.expression ) =
582
590
let debugTypedCompletionExpr = false in
@@ -593,7 +601,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
593
601
print_endline " [typedCompletionExpr] No cases - has cursor" ;
594
602
(* We can do exhaustive switch completion if this is an ident we can
595
603
complete from. *)
596
- match exprToContextPath expr with
604
+ match exprToContextPath ~in JsxContext: ! inJsxContext expr with
597
605
| None -> ()
598
606
| Some contextPath ->
599
607
setResult (CexhaustiveSwitch {contextPath; exprLoc = exp.pexp_loc}))
@@ -623,7 +631,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
623
631
};
624
632
] ) -> (
625
633
(* A single case that's a pattern hole typically means `switch x { | }`. Complete as the pattern itself with nothing nested. *)
626
- match exprToContextPath exp with
634
+ match exprToContextPath ~in JsxContext: ! inJsxContext exp with
627
635
| None -> ()
628
636
| Some ctxPath ->
629
637
setResult
@@ -640,7 +648,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
640
648
print_endline " [typedCompletionExpr] Has cases" ;
641
649
(* If there's more than one case, or the case isn't a pattern hole, figure out if we're completing another
642
650
broken parser case (`switch x { | true => () | <com> }` for example). *)
643
- match exp |> exprToContextPath with
651
+ match exp |> exprToContextPath ~in JsxContext: ! inJsxContext with
644
652
| None ->
645
653
if Debug. verbose () && debugTypedCompletionExpr then
646
654
print_endline " [typedCompletionExpr] Has cases - no ctx path"
@@ -781,7 +789,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
781
789
( pvb_pat
782
790
|> CompletionPatterns. traversePattern ~pattern Path:[] ~loc HasCursor
783
791
~first CharBeforeCursorNoWhite ~pos BeforeCursor,
784
- exprToContextPath pvb_expr )
792
+ exprToContextPath ~in JsxContext: ! inJsxContext pvb_expr )
785
793
with
786
794
| Some (prefix , nested ), Some ctxPath ->
787
795
setResult
@@ -1037,14 +1045,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1037
1045
in
1038
1046
(match findThisExprLoc with
1039
1047
| Some loc when expr.pexp_loc = loc -> (
1040
- match exprToContextPath expr with
1048
+ match exprToContextPath ~in JsxContext: ! inJsxContext expr with
1041
1049
| None -> ()
1042
1050
| Some ctxPath -> setResult (Cpath ctxPath))
1043
1051
| _ -> () );
1044
1052
let setPipeResult ~(lhs : Parsetree.expression ) ~id =
1045
- match completePipeChain lhs with
1053
+ match completePipeChain ~in JsxContext: ! inJsxContext lhs with
1046
1054
| None -> (
1047
- match exprToContextPath lhs with
1055
+ match exprToContextPath ~in JsxContext: ! inJsxContext lhs with
1048
1056
| Some pipe ->
1049
1057
setResult
1050
1058
(Cpath
@@ -1079,7 +1087,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1079
1087
&& Option. is_none findThisExprLoc ->
1080
1088
if Debug. verbose () then
1081
1089
print_endline " [completionFrontend] Checking each case" ;
1082
- let ctxPath = exprToContextPath expr in
1090
+ let ctxPath = exprToContextPath ~in JsxContext: ! inJsxContext expr in
1083
1091
let oldCtxPath = ! currentCtxPath in
1084
1092
cases
1085
1093
|> List. iter (fun (case : Parsetree.case ) ->
@@ -1178,7 +1186,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1178
1186
if fieldName.loc |> Loc. hasPos ~pos: posBeforeCursor then
1179
1187
match fieldName.txt with
1180
1188
| Lident name -> (
1181
- match exprToContextPath e with
1189
+ match exprToContextPath ~in JsxContext: ! inJsxContext e with
1182
1190
| Some contextPath ->
1183
1191
let contextPath =
1184
1192
Completable. CPField
@@ -1187,6 +1195,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1187
1195
fieldName = name;
1188
1196
posOfDot;
1189
1197
exprLoc = e.pexp_loc;
1198
+ inJsx = ! inJsxContext;
1190
1199
}
1191
1200
in
1192
1201
setResult (Cpath contextPath)
@@ -1210,12 +1219,13 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1210
1219
else name);
1211
1220
posOfDot;
1212
1221
exprLoc = e.pexp_loc;
1222
+ inJsx = ! inJsxContext;
1213
1223
}
1214
1224
in
1215
1225
setResult (Cpath contextPath)
1216
1226
| Lapply _ -> ()
1217
1227
else if Loc. end_ e.pexp_loc = posBeforeCursor then
1218
- match exprToContextPath e with
1228
+ match exprToContextPath ~in JsxContext: ! inJsxContext e with
1219
1229
| Some contextPath ->
1220
1230
setResult
1221
1231
(Cpath
@@ -1225,6 +1235,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1225
1235
fieldName = " " ;
1226
1236
posOfDot;
1227
1237
exprLoc = e.pexp_loc;
1238
+ inJsx = ! inJsxContext;
1228
1239
}))
1229
1240
| None -> () )
1230
1241
| Pexp_apply ({pexp_desc = Pexp_ident compName}, args)
@@ -1295,7 +1306,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1295
1306
if Debug. verbose () then
1296
1307
print_endline " [expr_iter] Complete fn arguments (piped)" ;
1297
1308
let args = extractExpApplyArgs ~args in
1298
- let funCtxPath = exprToContextPath funExpr in
1309
+ let funCtxPath =
1310
+ exprToContextPath ~in JsxContext:! inJsxContext funExpr
1311
+ in
1299
1312
let argCompletable =
1300
1313
match funCtxPath with
1301
1314
| Some contextPath ->
@@ -1343,7 +1356,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1343
1356
(Loc. toString exp.pexp_loc))
1344
1357
|> String. concat " , " );
1345
1358
1346
- let funCtxPath = exprToContextPath funExpr in
1359
+ let funCtxPath =
1360
+ exprToContextPath ~in JsxContext:! inJsxContext funExpr
1361
+ in
1347
1362
let argCompletable =
1348
1363
match funCtxPath with
1349
1364
| Some contextPath ->
@@ -1387,7 +1402,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1387
1402
labelRange |> Range. hasPos ~pos: posBeforeCursor
1388
1403
|| (label = " " && posCursor = fst labelRange)
1389
1404
then
1390
- match exprToContextPath lhs with
1405
+ match exprToContextPath ~in JsxContext: ! inJsxContext lhs with
1391
1406
| Some contextPath -> setResult (Cpath (CPObj (contextPath, label)))
1392
1407
| None -> () )
1393
1408
| Pexp_fun (lbl , defaultExpOpt , pat , e ) ->
0 commit comments