@@ -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 "->" } -> 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
@@ -266,7 +269,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
266
269
[(_, lhs); (_, {pexp_desc = Pexp_apply {funct = d; args; partial}})];
267
270
} ->
268
271
(* Transform away pipe with apply call *)
269
- exprToContextPath
272
+ exprToContextPath ~in JsxContext
270
273
{
271
274
pexp_desc =
272
275
Pexp_apply {funct = d; args = (Nolabel , lhs) :: args; partial};
@@ -283,7 +286,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
283
286
partial;
284
287
} ->
285
288
(* Transform away pipe with identifier *)
286
- exprToContextPath
289
+ exprToContextPath ~in JsxContext
287
290
{
288
291
pexp_desc =
289
292
Pexp_apply
@@ -296,29 +299,31 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
296
299
pexp_attributes;
297
300
}
298
301
| Pexp_apply {funct = e1 ; args} -> (
299
- match exprToContextPath e1 with
302
+ match exprToContextPath ~in JsxContext e1 with
300
303
| None -> None
301
304
| Some contexPath ->
302
305
Some
303
306
(CPApply (contexPath, args |> List. map fst |> List. map Asttypes. to_noloc))
304
307
)
305
308
| Pexp_tuple exprs ->
306
- let exprsAsContextPaths = exprs |> List. filter_map exprToContextPath in
309
+ let exprsAsContextPaths =
310
+ exprs |> List. filter_map (exprToContextPath ~in JsxContext)
311
+ in
307
312
if List. length exprs = List. length exprsAsContextPaths then
308
313
Some (CTuple exprsAsContextPaths)
309
314
else None
310
315
| _ -> None
311
316
312
- and exprToContextPath (e : Parsetree.expression ) =
317
+ and exprToContextPath ~( inJsxContext : bool ) (e : Parsetree.expression ) =
313
318
match
314
319
( Res_parsetree_viewer. has_await_attribute e.pexp_attributes,
315
- exprToContextPathInner e )
320
+ exprToContextPathInner ~in JsxContext e )
316
321
with
317
322
| true , Some ctxPath -> Some (CPAwait ctxPath)
318
323
| false , Some ctxPath -> Some ctxPath
319
324
| _ , None -> None
320
325
321
- let completePipeChain (exp : Parsetree.expression ) =
326
+ let completePipeChain ~( inJsxContext : bool ) (exp : Parsetree.expression ) =
322
327
(* Complete the end of pipe chains by reconstructing the pipe chain as a single pipe,
323
328
so it can be completed.
324
329
Example:
@@ -334,15 +339,17 @@ let completePipeChain (exp : Parsetree.expression) =
334
339
funct = {pexp_desc = Pexp_ident {txt = Lident " ->" }};
335
340
args = [_; (_, {pexp_desc = Pexp_apply {funct = d}})];
336
341
} ->
337
- exprToContextPath exp |> Option. map (fun ctxPath -> (ctxPath, d.pexp_loc))
342
+ exprToContextPath ~in JsxContext exp
343
+ |> Option. map (fun ctxPath -> (ctxPath, d.pexp_loc))
338
344
(* When the left side of the pipe we're completing is an identifier application.
339
345
Example: someArray->filterAllTheGoodStuff-> *)
340
346
| Pexp_apply
341
347
{
342
348
funct = {pexp_desc = Pexp_ident {txt = Lident " ->" }};
343
349
args = [_; (_, {pexp_desc = Pexp_ident _; pexp_loc})];
344
350
} ->
345
- exprToContextPath exp |> Option. map (fun ctxPath -> (ctxPath, pexp_loc))
351
+ exprToContextPath ~in JsxContext exp
352
+ |> Option. map (fun ctxPath -> (ctxPath, pexp_loc))
346
353
| _ -> None
347
354
348
355
let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
@@ -429,6 +436,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
429
436
(Completable. toString x);
430
437
result := Some (x, ! scope)
431
438
in
439
+ let inJsxContext = ref false in
432
440
let setResult x = setResultOpt (Some x) in
433
441
let scopeValueDescription (vd : Parsetree.value_description ) =
434
442
scope :=
@@ -563,9 +571,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
563
571
(* Pipe chains get special treatment here, because when assigning values
564
572
we want the return of the entire pipe chain as a function call, rather
565
573
than as a pipe completion call. *)
566
- match completePipeChain vb.pvb_expr with
574
+ match completePipeChain ~in JsxContext: ! inJsxContext vb.pvb_expr with
567
575
| Some (ctxPath , _ ) -> Some ctxPath
568
- | None -> exprToContextPath vb.pvb_expr
576
+ | None -> exprToContextPath ~in JsxContext: ! inJsxContext vb.pvb_expr
569
577
in
570
578
scopePattern ?contextPath vb.pvb_pat
571
579
in
@@ -597,7 +605,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
597
605
scope :=
598
606
! scope |> Scope. addModule ~name: md.pmd_name.txt ~loc: md.pmd_name.loc
599
607
in
600
- let inJsxContext = ref false in
608
+
601
609
(* Identifies expressions where we can do typed pattern or expr completion. *)
602
610
let typedCompletionExpr (exp : Parsetree.expression ) =
603
611
let debugTypedCompletionExpr = false in
@@ -614,7 +622,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
614
622
print_endline " [typedCompletionExpr] No cases - has cursor" ;
615
623
(* We can do exhaustive switch completion if this is an ident we can
616
624
complete from. *)
617
- match exprToContextPath expr with
625
+ match exprToContextPath ~in JsxContext: ! inJsxContext expr with
618
626
| None -> ()
619
627
| Some contextPath ->
620
628
setResult (CexhaustiveSwitch {contextPath; exprLoc = exp.pexp_loc}))
@@ -644,7 +652,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
644
652
};
645
653
] ) -> (
646
654
(* A single case that's a pattern hole typically means `switch x { | }`. Complete as the pattern itself with nothing nested. *)
647
- match exprToContextPath exp with
655
+ match exprToContextPath ~in JsxContext: ! inJsxContext exp with
648
656
| None -> ()
649
657
| Some ctxPath ->
650
658
setResult
@@ -661,7 +669,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
661
669
print_endline " [typedCompletionExpr] Has cases" ;
662
670
(* If there's more than one case, or the case isn't a pattern hole, figure out if we're completing another
663
671
broken parser case (`switch x { | true => () | <com> }` for example). *)
664
- match exp |> exprToContextPath with
672
+ match exp |> exprToContextPath ~in JsxContext: ! inJsxContext with
665
673
| None ->
666
674
if Debug. verbose () && debugTypedCompletionExpr then
667
675
print_endline " [typedCompletionExpr] Has cases - no ctx path"
@@ -802,7 +810,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
802
810
( pvb_pat
803
811
|> CompletionPatterns. traversePattern ~pattern Path:[] ~loc HasCursor
804
812
~first CharBeforeCursorNoWhite ~pos BeforeCursor,
805
- exprToContextPath pvb_expr )
813
+ exprToContextPath ~in JsxContext: ! inJsxContext pvb_expr )
806
814
with
807
815
| Some (prefix , nested ), Some ctxPath ->
808
816
setResult
@@ -1059,14 +1067,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1059
1067
in
1060
1068
(match findThisExprLoc with
1061
1069
| Some loc when expr.pexp_loc = loc -> (
1062
- match exprToContextPath expr with
1070
+ match exprToContextPath ~in JsxContext: ! inJsxContext expr with
1063
1071
| None -> ()
1064
1072
| Some ctxPath -> setResult (Cpath ctxPath))
1065
1073
| _ -> () );
1066
1074
let setPipeResult ~(lhs : Parsetree.expression ) ~id =
1067
- match completePipeChain lhs with
1075
+ match completePipeChain ~in JsxContext: ! inJsxContext lhs with
1068
1076
| None -> (
1069
- match exprToContextPath lhs with
1077
+ match exprToContextPath ~in JsxContext: ! inJsxContext lhs with
1070
1078
| Some pipe ->
1071
1079
setResult
1072
1080
(Cpath
@@ -1101,7 +1109,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1101
1109
&& Option. is_none findThisExprLoc ->
1102
1110
if Debug. verbose () then
1103
1111
print_endline " [completionFrontend] Checking each case" ;
1104
- let ctxPath = exprToContextPath expr in
1112
+ let ctxPath = exprToContextPath ~in JsxContext: ! inJsxContext expr in
1105
1113
let oldCtxPath = ! currentCtxPath in
1106
1114
cases
1107
1115
|> List. iter (fun (case : Parsetree.case ) ->
@@ -1144,7 +1152,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1144
1152
];
1145
1153
}
1146
1154
when Res_parsetree_viewer. is_tagged_template_literal innerExpr ->
1147
- exprToContextPath innerExpr
1155
+ exprToContextPath ~in JsxContext: ! inJsxContext innerExpr
1148
1156
|> Option. iter (fun cpath ->
1149
1157
setResult
1150
1158
(Cpath
@@ -1154,6 +1162,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1154
1162
fieldName = " " ;
1155
1163
posOfDot;
1156
1164
exprLoc = expr.pexp_loc;
1165
+ inJsx = ! inJsxContext;
1157
1166
}));
1158
1167
setFound () )
1159
1168
(*
@@ -1174,7 +1183,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1174
1183
}
1175
1184
when Res_parsetree_viewer. is_tagged_template_literal innerExpr
1176
1185
&& expr.pexp_loc |> Loc. hasPos ~pos: posBeforeCursor ->
1177
- exprToContextPath innerExpr
1186
+ exprToContextPath ~in JsxContext: ! inJsxContext innerExpr
1178
1187
|> Option. iter (fun cpath ->
1179
1188
setResult
1180
1189
(Cpath
@@ -1184,6 +1193,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1184
1193
fieldName;
1185
1194
posOfDot;
1186
1195
exprLoc = expr.pexp_loc;
1196
+ inJsx = ! inJsxContext;
1187
1197
}));
1188
1198
setFound () )
1189
1199
| _ -> (
@@ -1262,7 +1272,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1262
1272
if fieldName.loc |> Loc. hasPos ~pos: posBeforeCursor then
1263
1273
match fieldName.txt with
1264
1274
| Lident name -> (
1265
- match exprToContextPath e with
1275
+ match exprToContextPath ~in JsxContext: ! inJsxContext e with
1266
1276
| Some contextPath ->
1267
1277
let contextPath =
1268
1278
Completable. CPField
@@ -1271,6 +1281,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1271
1281
fieldName = name;
1272
1282
posOfDot;
1273
1283
exprLoc = e.pexp_loc;
1284
+ inJsx = ! inJsxContext;
1274
1285
}
1275
1286
in
1276
1287
setResult (Cpath contextPath)
@@ -1294,12 +1305,13 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1294
1305
else name);
1295
1306
posOfDot;
1296
1307
exprLoc = e.pexp_loc;
1308
+ inJsx = ! inJsxContext;
1297
1309
}
1298
1310
in
1299
1311
setResult (Cpath contextPath)
1300
1312
| Lapply _ -> ()
1301
1313
else if Loc. end_ e.pexp_loc = posBeforeCursor then
1302
- match exprToContextPath e with
1314
+ match exprToContextPath ~in JsxContext: ! inJsxContext e with
1303
1315
| Some contextPath ->
1304
1316
setResult
1305
1317
(Cpath
@@ -1309,6 +1321,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1309
1321
fieldName = " " ;
1310
1322
posOfDot;
1311
1323
exprLoc = e.pexp_loc;
1324
+ inJsx = ! inJsxContext;
1312
1325
}))
1313
1326
| None -> () )
1314
1327
| Pexp_apply {funct = {pexp_desc = Pexp_ident compName}; args}
@@ -1386,7 +1399,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1386
1399
if Debug. verbose () then
1387
1400
print_endline " [expr_iter] Complete fn arguments (piped)" ;
1388
1401
let args = extractExpApplyArgs ~args in
1389
- let funCtxPath = exprToContextPath funExpr in
1402
+ let funCtxPath =
1403
+ exprToContextPath ~in JsxContext:! inJsxContext funExpr
1404
+ in
1390
1405
let argCompletable =
1391
1406
match funCtxPath with
1392
1407
| Some contextPath ->
@@ -1437,7 +1452,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1437
1452
(Loc. toString exp.pexp_loc))
1438
1453
|> String. concat " , " );
1439
1454
1440
- let funCtxPath = exprToContextPath funExpr in
1455
+ let funCtxPath =
1456
+ exprToContextPath ~in JsxContext:! inJsxContext funExpr
1457
+ in
1441
1458
let argCompletable =
1442
1459
match funCtxPath with
1443
1460
| Some contextPath ->
@@ -1481,7 +1498,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1481
1498
labelRange |> Range. hasPos ~pos: posBeforeCursor
1482
1499
|| (label = " " && posCursor = fst labelRange)
1483
1500
then
1484
- match exprToContextPath lhs with
1501
+ match exprToContextPath ~in JsxContext: ! inJsxContext lhs with
1485
1502
| Some contextPath -> setResult (Cpath (CPObj (contextPath, label)))
1486
1503
| None -> () )
1487
1504
| Pexp_fun
0 commit comments