@@ -219,14 +219,24 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
219219 | [] -> None
220220 | exp :: _ -> exprToContextPath exp))
221221 | 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})
223225 | Pexp_field (e1 , {txt = Lident name } ) -> (
224226 match exprToContextPath e1 with
225227 | Some contextPath -> Some (CPField (contextPath, name))
226228 | _ -> None )
227- | Pexp_field (_ , {txt = Ldot (lid , name )} ) ->
229+ | Pexp_field (_ , {loc; txt = Ldot (lid , name )} ) ->
228230 (* 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 ))
230240 | Pexp_send (e1 , {txt} ) -> (
231241 match exprToContextPath e1 with
232242 | None -> None
@@ -411,8 +421,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
411421 let ctxPath =
412422 if contextPathToSave = None then
413423 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})
416427 | _ -> None
417428 else None
418429 in
@@ -1055,12 +1066,16 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
10551066 setResult
10561067 (Cpath
10571068 (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+ }))
10641079 | Pexp_construct ({txt = Lident ("::" | "()" )} , _ ) ->
10651080 (* Ignore list expressions, used in JSX, unit, and more *) ()
10661081 | Pexp_construct (lid , eOpt ) -> (
@@ -1075,7 +1090,15 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
10751090 if
10761091 eOpt = None && (not lid.loc.loc_ghost)
10771092 && 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+ }))
10791102 else
10801103 match eOpt with
10811104 | Some e when locHasCursor e.pexp_loc -> (
@@ -1106,7 +1129,12 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
11061129 (* Case x.M.field ignore the x part *)
11071130 let contextPath =
11081131 Completable. CPField
1109- ( CPId (Utils. flattenLongIdent id, Module ),
1132+ ( CPId
1133+ {
1134+ loc = fieldName.loc;
1135+ path = Utils. flattenLongIdent id;
1136+ completionContext = Module ;
1137+ },
11101138 if blankAfterCursor = Some '.' then
11111139 (* x.M. field ---> M. *) " "
11121140 else if name = " _" then " "
@@ -1149,7 +1177,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
11491177 (match compNamePath with
11501178 | [prefix] when Char. lowercase_ascii prefix.[0 ] = prefix.[0 ] ->
11511179 ChtmlElement {prefix}
1152- | _ -> Cpath (CPId (compNamePath, Module )))
1180+ | _ ->
1181+ Cpath
1182+ (CPId
1183+ {
1184+ loc = compName.loc;
1185+ path = compNamePath;
1186+ completionContext = Module ;
1187+ }))
11531188 else iterateJsxProps ~iterator jsxProps
11541189 | Pexp_apply
11551190 ( {pexp_desc = Pexp_ident {txt = Lident (" |." | " |.u" )}},
@@ -1356,7 +1391,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13561391 (lidPath |> String .concat "." )
13571392 (Loc .toString lid .loc);
13581393 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 }))
13601397 | _ -> ());
13611398 Ast_iterator. default_iterator.typ iterator core_type
13621399 in
@@ -1374,7 +1411,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13741411 Printf. printf " Ppat_construct %s:%s\n "
13751412 (lidPath |> String. concat " ." )
13761413 (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
13781418 match ! result with
13791419 | Some (Completable. Cpattern p , scope ) ->
13801420 result := Some (Cpattern {p with fallback = Some completion}, scope)
@@ -1392,7 +1432,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13921432 (lidPath |> String. concat " ." )
13931433 (Loc. toString lid.loc);
13941434 found := true ;
1395- setResult (Cpath (CPId (lidPath, Module )))
1435+ setResult
1436+ (Cpath
1437+ (CPId {loc = lid.loc; path = lidPath; completionContext = Module }))
13961438 | _ -> () );
13971439 Ast_iterator. default_iterator.module_expr iterator me
13981440 in
@@ -1406,7 +1448,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
14061448 (lidPath |> String. concat " ." )
14071449 (Loc. toString lid.loc);
14081450 found := true ;
1409- setResult (Cpath (CPId (lidPath, Module )))
1451+ setResult
1452+ (Cpath
1453+ (CPId {loc = lid.loc; path = lidPath; completionContext = Module }))
14101454 | _ -> () );
14111455 Ast_iterator. default_iterator.module_type iterator mt
14121456 in
@@ -1422,7 +1466,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
14221466 Printf. printf " Ptype_variant unary %s:%s\n " decl.pcd_name.txt
14231467 (Loc. toString decl.pcd_name.loc);
14241468 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+ }))
14261477 | _ -> () );
14271478 Ast_iterator. default_iterator.type_kind iterator type_kind
14281479 in
@@ -1459,7 +1510,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
14591510 iterator .structure iterator str |> ignore ;
14601511 if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then (
14611512 scope := ! lastScopeBeforeCursor;
1462- setResult (Cpath (CPId (["" ], Value ))));
1513+ setResult
1514+ (Cpath
1515+ (CPId {loc = Location. none; path = [" " ]; completionContext = Value })));
14631516 if ! found = false then if debug then Printf .printf "XXX Not found!\n " ;
14641517 ! result)
14651518 else if Filename .check_suffix path ".resi" then (
@@ -1468,7 +1521,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
14681521 iterator .signature iterator signature |> ignore ;
14691522 if blankAfterCursor = Some ' ' || blankAfterCursor = Some '\n' then (
14701523 scope := ! lastScopeBeforeCursor;
1471- setResult (Cpath (CPId (["" ], Type ))));
1524+ setResult
1525+ (Cpath
1526+ (CPId {loc = Location. none; path = [" " ]; completionContext = Type })));
14721527 if ! found = false then if debug then Printf .printf "XXX Not found!\n " ;
14731528 ! result)
14741529 else None
0 commit comments