@@ -222,21 +222,26 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
222222 | Pexp_ident {txt; loc} ->
223223 Some
224224 (CPId {path = Utils. flattenLongIdent txt; completionContext = Value ; loc})
225- | Pexp_field (e1 , {txt = Lident name } ) -> (
225+ | Pexp_field (e1 , {txt = Lident name ; loc } ) -> (
226226 match exprToContextPath e1 with
227- | Some contextPath -> Some (CPField (contextPath, name))
227+ | Some contextPath ->
228+ Some (CPField {contextPath; fieldName = name; fieldNameLoc = loc})
228229 | _ -> None )
229230 | Pexp_field (_ , {loc; txt = Ldot (lid , name )} ) ->
230231 (* Case x.M.field ignore the x part *)
231232 Some
232233 (CPField
233- ( CPId
234- {
235- path = Utils. flattenLongIdent lid;
236- completionContext = Module ;
237- loc;
238- },
239- name ))
234+ {
235+ contextPath =
236+ CPId
237+ {
238+ path = Utils. flattenLongIdent lid;
239+ completionContext = Module ;
240+ loc;
241+ };
242+ fieldName = name;
243+ fieldNameLoc = loc;
244+ })
240245 | Pexp_send (e1 , {txt} ) -> (
241246 match exprToContextPath e1 with
242247 | None -> None
@@ -1130,29 +1135,54 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
11301135 | Lident name -> (
11311136 match exprToContextPath e with
11321137 | Some contextPath ->
1133- let contextPath = Completable. CPField (contextPath, name) in
1138+ let contextPath =
1139+ Completable. CPField
1140+ {
1141+ contextPath;
1142+ fieldName = name;
1143+ fieldNameLoc = fieldName.loc;
1144+ }
1145+ in
11341146 setResult (Cpath contextPath)
11351147 | None -> () )
11361148 | Ldot (id , name ) ->
11371149 (* Case x.M.field ignore the x part *)
11381150 let contextPath =
11391151 Completable. CPField
1140- ( CPId
1141- {
1142- loc = fieldName.loc;
1143- path = Utils. flattenLongIdent id;
1144- completionContext = Module ;
1145- },
1146- if blankAfterCursor = Some '.' then
1147- (* x.M. field ---> M. *) " "
1148- else if name = " _" then " "
1149- else name )
1152+ {
1153+ contextPath =
1154+ CPId
1155+ {
1156+ loc = fieldName.loc;
1157+ path = Utils. flattenLongIdent id;
1158+ completionContext = Module ;
1159+ };
1160+ fieldName =
1161+ (if blankAfterCursor = Some '.' then
1162+ (* x.M. field ---> M. *) " "
1163+ else if name = " _" then " "
1164+ else name);
1165+ fieldNameLoc = fieldName.loc;
1166+ }
11501167 in
11511168 setResult (Cpath contextPath)
11521169 | Lapply _ -> ()
11531170 else if Loc. end_ e.pexp_loc = posBeforeCursor then
11541171 match exprToContextPath e with
1155- | Some contextPath -> setResult (Cpath (CPField (contextPath, " " )))
1172+ | Some contextPath ->
1173+ setResult
1174+ (Cpath
1175+ (CPField
1176+ {
1177+ contextPath;
1178+ fieldName = " " ;
1179+ fieldNameLoc =
1180+ {
1181+ loc_start = e.pexp_loc.loc_end;
1182+ loc_end = e.pexp_loc.loc_end;
1183+ loc_ghost = false ;
1184+ };
1185+ }))
11561186 | None -> () )
11571187 | Pexp_apply ({pexp_desc = Pexp_ident compName}, args)
11581188 when Res_parsetree_viewer. is_jsx_expression expr ->
0 commit comments