@@ -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,11 @@ 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
+ {loc = lid.loc; path = lidPath; completionContext = Value }))
1079
1098
else
1080
1099
match eOpt with
1081
1100
| Some e when locHasCursor e.pexp_loc -> (
@@ -1106,7 +1125,12 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1106
1125
(* Case x.M.field ignore the x part *)
1107
1126
let contextPath =
1108
1127
Completable. CPField
1109
- ( CPId (Utils. flattenLongIdent id, Module ),
1128
+ ( CPId
1129
+ {
1130
+ loc = fieldName.loc;
1131
+ path = Utils. flattenLongIdent id;
1132
+ completionContext = Module ;
1133
+ },
1110
1134
if blankAfterCursor = Some '.' then
1111
1135
(* x.M. field ---> M. *) " "
1112
1136
else if name = " _" then " "
@@ -1149,7 +1173,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1149
1173
(match compNamePath with
1150
1174
| [prefix] when Char. lowercase_ascii prefix.[0 ] = prefix.[0 ] ->
1151
1175
ChtmlElement {prefix}
1152
- | _ -> Cpath (CPId (compNamePath, Module )))
1176
+ | _ ->
1177
+ Cpath
1178
+ (CPId
1179
+ {
1180
+ loc = compName.loc;
1181
+ path = compNamePath;
1182
+ completionContext = Module ;
1183
+ }))
1153
1184
else iterateJsxProps ~iterator jsxProps
1154
1185
| Pexp_apply
1155
1186
( {pexp_desc = Pexp_ident {txt = Lident (" |." | " |.u" )}},
@@ -1356,7 +1387,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1356
1387
(lidPath |> String .concat "." )
1357
1388
(Loc .toString lid .loc);
1358
1389
if lid .loc |> Loc .hasPos ~pos: posBeforeCursor then
1359
- setResult (Cpath (CPId (lidPath , Type )))
1390
+ setResult
1391
+ (Cpath
1392
+ (CPId {loc = lid.loc; path = lidPath; completionContext = Type }))
1360
1393
| _ -> ());
1361
1394
Ast_iterator. default_iterator.typ iterator core_type
1362
1395
in
@@ -1374,7 +1407,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1374
1407
Printf. printf " Ppat_construct %s:%s\n "
1375
1408
(lidPath |> String. concat " ." )
1376
1409
(Loc. toString lid.loc);
1377
- let completion = Completable. Cpath (CPId (lidPath, Value )) in
1410
+ let completion =
1411
+ Completable. Cpath
1412
+ (CPId {loc = lid.loc; path = lidPath; completionContext = Value })
1413
+ in
1378
1414
match ! result with
1379
1415
| Some (Completable. Cpattern p , scope ) ->
1380
1416
result := Some (Cpattern {p with fallback = Some completion}, scope)
@@ -1392,7 +1428,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1392
1428
(lidPath |> String. concat " ." )
1393
1429
(Loc. toString lid.loc);
1394
1430
found := true ;
1395
- setResult (Cpath (CPId (lidPath, Module )))
1431
+ setResult
1432
+ (Cpath
1433
+ (CPId {loc = lid.loc; path = lidPath; completionContext = Module }))
1396
1434
| _ -> () );
1397
1435
Ast_iterator. default_iterator.module_expr iterator me
1398
1436
in
@@ -1406,7 +1444,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1406
1444
(lidPath |> String. concat " ." )
1407
1445
(Loc. toString lid.loc);
1408
1446
found := true ;
1409
- setResult (Cpath (CPId (lidPath, Module )))
1447
+ setResult
1448
+ (Cpath
1449
+ (CPId {loc = lid.loc; path = lidPath; completionContext = Module }))
1410
1450
| _ -> () );
1411
1451
Ast_iterator. default_iterator.module_type iterator mt
1412
1452
in
@@ -1422,7 +1462,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1422
1462
Printf. printf " Ptype_variant unary %s:%s\n " decl.pcd_name.txt
1423
1463
(Loc. toString decl.pcd_name.loc);
1424
1464
found := true ;
1425
- setResult (Cpath (CPId ([decl.pcd_name.txt], Value )))
1465
+ setResult
1466
+ (Cpath
1467
+ (CPId
1468
+ {
1469
+ loc = decl.pcd_name.loc;
1470
+ path = [decl.pcd_name.txt];
1471
+ completionContext = Value ;
1472
+ }))
1426
1473
| _ -> () );
1427
1474
Ast_iterator. default_iterator.type_kind iterator type_kind
1428
1475
in
@@ -1459,7 +1506,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1459
1506
iterator .structure iterator str |> ignore ;
1460
1507
if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then (
1461
1508
scope := ! lastScopeBeforeCursor;
1462
- setResult (Cpath (CPId (["" ], Value ))));
1509
+ setResult
1510
+ (Cpath
1511
+ (CPId {loc = Location. none; path = [" " ]; completionContext = Value })));
1463
1512
if ! found = false then if debug then Printf .printf "XXX Not found!\n " ;
1464
1513
! result)
1465
1514
else if Filename .check_suffix path ".resi" then (
@@ -1468,7 +1517,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
1468
1517
iterator .signature iterator signature |> ignore ;
1469
1518
if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then (
1470
1519
scope := ! lastScopeBeforeCursor;
1471
- setResult (Cpath (CPId (["" ], Type ))));
1520
+ setResult
1521
+ (Cpath
1522
+ (CPId {loc = Location. none; path = [" " ]; completionContext = Type })));
1472
1523
if ! found = false then if debug then Printf .printf "XXX Not found!\n " ;
1473
1524
! result)
1474
1525
else None
0 commit comments