@@ -219,14 +219,24 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
219
219
| [] -> None
220
220
| exp :: _ -> exprToContextPath exp))
221
221
| Pexp_ident {txt = Lident ("|." | "|.u" )} -> None
222
- | Pexp_ident {txt} -> Some (CPId (Utils. flattenLongIdent txt, Value ))
222
+ | Pexp_ident {txt; loc} ->
223
+ Some
224
+ (CPId {path = Utils. flattenLongIdent txt; completionContext = Value ; loc})
223
225
| Pexp_field (e1 , {txt = Lident name } ) -> (
224
226
match exprToContextPath e1 with
225
227
| Some contextPath -> Some (CPField (contextPath, name))
226
228
| _ -> None )
227
- | Pexp_field (_ , {txt = Ldot (lid , name )} ) ->
229
+ | Pexp_field (_ , {loc; txt = Ldot (lid , name )} ) ->
228
230
(* Case x.M.field ignore the x part *)
229
- Some (CPField (CPId (Utils. flattenLongIdent lid, Module ), name))
231
+ Some
232
+ (CPField
233
+ ( CPId
234
+ {
235
+ path = Utils. flattenLongIdent lid;
236
+ completionContext = Module ;
237
+ loc;
238
+ },
239
+ name ))
230
240
| Pexp_send (e1 , {txt} ) -> (
231
241
match exprToContextPath e1 with
232
242
| None -> None
@@ -411,8 +421,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
411
421
let ctxPath =
412
422
if contextPathToSave = None then
413
423
match p with
414
- | {ppat_desc = Ppat_var {txt} } ->
415
- Some (Completable. CPId ([txt], Value ))
424
+ | {ppat_desc = Ppat_var {txt; loc} } ->
425
+ Some
426
+ (Completable. CPId {path = [txt]; completionContext = Value ; loc})
416
427
| _ -> None
417
428
else None
418
429
in
@@ -1055,12 +1066,16 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1055
1066
setResult
1056
1067
(Cpath
1057
1068
(CPId
1058
- ( lidPath,
1059
- if
1060
- isLikelyModulePath
1061
- && expr |> Res_parsetree_viewer. isBracedExpr
1062
- then ValueOrField
1063
- else Value )))
1069
+ {
1070
+ loc = lid.loc;
1071
+ path = lidPath;
1072
+ completionContext =
1073
+ (if
1074
+ isLikelyModulePath
1075
+ && expr |> Res_parsetree_viewer. isBracedExpr
1076
+ then ValueOrField
1077
+ else Value );
1078
+ }))
1064
1079
| Pexp_construct ({txt = Lident ("::" | "()" )} , _ ) ->
1065
1080
(* Ignore list expressions, used in JSX, unit, and more *) ()
1066
1081
| Pexp_construct (lid , eOpt ) -> (
@@ -1075,7 +1090,15 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1075
1090
if
1076
1091
eOpt = None && (not lid.loc.loc_ghost)
1077
1092
&& lid.loc |> Loc. hasPos ~pos: posBeforeCursor
1078
- then setResult (Cpath (CPId (lidPath, Value )))
1093
+ then
1094
+ setResult
1095
+ (Cpath
1096
+ (CPId
1097
+ {
1098
+ loc = expr.pexp_loc;
1099
+ path = lidPath;
1100
+ completionContext = Value ;
1101
+ }))
1079
1102
else
1080
1103
match eOpt with
1081
1104
| Some e when locHasCursor e.pexp_loc -> (
@@ -1106,7 +1129,12 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1106
1129
(* Case x.M.field ignore the x part *)
1107
1130
let contextPath =
1108
1131
Completable. CPField
1109
- ( CPId (Utils. flattenLongIdent id, Module ),
1132
+ ( CPId
1133
+ {
1134
+ loc = fieldName.loc;
1135
+ path = Utils. flattenLongIdent id;
1136
+ completionContext = Module ;
1137
+ },
1110
1138
if blankAfterCursor = Some '.' then
1111
1139
(* x.M. field ---> M. *) " "
1112
1140
else if name = " _" then " "
@@ -1149,7 +1177,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1149
1177
(match compNamePath with
1150
1178
| [prefix] when Char. lowercase_ascii prefix.[0 ] = prefix.[0 ] ->
1151
1179
ChtmlElement {prefix}
1152
- | _ -> Cpath (CPId (compNamePath, Module )))
1180
+ | _ ->
1181
+ Cpath
1182
+ (CPId
1183
+ {
1184
+ loc = compName.loc;
1185
+ path = compNamePath;
1186
+ completionContext = Module ;
1187
+ }))
1153
1188
else iterateJsxProps ~iterator jsxProps
1154
1189
| Pexp_apply
1155
1190
( {pexp_desc = Pexp_ident {txt = Lident (" |." | " |.u" )}},
@@ -1356,7 +1391,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1356
1391
(lidPath |> String .concat "." )
1357
1392
(Loc .toString lid .loc);
1358
1393
if lid .loc |> Loc .hasPos ~pos: posBeforeCursor then
1359
- setResult (Cpath (CPId (lidPath , Type )))
1394
+ setResult
1395
+ (Cpath
1396
+ (CPId {loc = lid.loc; path = lidPath; completionContext = Type }))
1360
1397
| _ -> ());
1361
1398
Ast_iterator. default_iterator.typ iterator core_type
1362
1399
in
@@ -1374,7 +1411,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1374
1411
Printf. printf " Ppat_construct %s:%s\n "
1375
1412
(lidPath |> String. concat " ." )
1376
1413
(Loc. toString lid.loc);
1377
- let completion = Completable. Cpath (CPId (lidPath, Value )) in
1414
+ let completion =
1415
+ Completable. Cpath
1416
+ (CPId {loc = lid.loc; path = lidPath; completionContext = Value })
1417
+ in
1378
1418
match ! result with
1379
1419
| Some (Completable. Cpattern p , scope ) ->
1380
1420
result := Some (Cpattern {p with fallback = Some completion}, scope)
@@ -1392,7 +1432,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1392
1432
(lidPath |> String. concat " ." )
1393
1433
(Loc. toString lid.loc);
1394
1434
found := true ;
1395
- setResult (Cpath (CPId (lidPath, Module )))
1435
+ setResult
1436
+ (Cpath
1437
+ (CPId {loc = lid.loc; path = lidPath; completionContext = Module }))
1396
1438
| _ -> () );
1397
1439
Ast_iterator. default_iterator.module_expr iterator me
1398
1440
in
@@ -1406,7 +1448,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1406
1448
(lidPath |> String. concat " ." )
1407
1449
(Loc. toString lid.loc);
1408
1450
found := true ;
1409
- setResult (Cpath (CPId (lidPath, Module )))
1451
+ setResult
1452
+ (Cpath
1453
+ (CPId {loc = lid.loc; path = lidPath; completionContext = Module }))
1410
1454
| _ -> () );
1411
1455
Ast_iterator. default_iterator.module_type iterator mt
1412
1456
in
@@ -1422,7 +1466,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1422
1466
Printf. printf " Ptype_variant unary %s:%s\n " decl.pcd_name.txt
1423
1467
(Loc. toString decl.pcd_name.loc);
1424
1468
found := true ;
1425
- setResult (Cpath (CPId ([decl.pcd_name.txt], Value )))
1469
+ setResult
1470
+ (Cpath
1471
+ (CPId
1472
+ {
1473
+ loc = decl.pcd_name.loc;
1474
+ path = [decl.pcd_name.txt];
1475
+ completionContext = Value ;
1476
+ }))
1426
1477
| _ -> () );
1427
1478
Ast_iterator. default_iterator.type_kind iterator type_kind
1428
1479
in
@@ -1459,7 +1510,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1459
1510
iterator .structure iterator str |> ignore ;
1460
1511
if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then (
1461
1512
scope := ! lastScopeBeforeCursor;
1462
- setResult (Cpath (CPId (["" ], Value ))));
1513
+ setResult
1514
+ (Cpath
1515
+ (CPId {loc = Location. none; path = [" " ]; completionContext = Value })));
1463
1516
if ! found = false then if debug then Printf .printf "XXX Not found!\n " ;
1464
1517
! result)
1465
1518
else if Filename .check_suffix path ".resi" then (
@@ -1468,7 +1521,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1468
1521
iterator .signature iterator signature |> ignore ;
1469
1522
if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then (
1470
1523
scope := ! lastScopeBeforeCursor;
1471
- setResult (Cpath (CPId (["" ], Type ))));
1524
+ setResult
1525
+ (Cpath
1526
+ (CPId {loc = Location. none; path = [" " ]; completionContext = Type })));
1472
1527
if ! found = false then if debug then Printf .printf "XXX Not found!\n " ;
1473
1528
! result)
1474
1529
else None
0 commit comments