Skip to content

Commit 5e1a22e

Browse files
committed
refactor: remove reference
1 parent 104e9a7 commit 5e1a22e

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

analysis/src/NewCompletions.ml

+15-18
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,7 @@ let rec extractRecordType ~env ~package (t : Types.type_expr) =
745745

746746
let rec extractObjectType ~env ~package (t : Types.type_expr) =
747747
match t.desc with
748-
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) ->
749-
extractObjectType ~env ~package t1
748+
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractObjectType ~env ~package t1
750749
| Tobject (tObj, _) -> Some (env, tObj)
751750
| Tconstr (path, _, _) -> (
752751
match References.digConstructor ~env ~package path with
@@ -1164,30 +1163,28 @@ let processCompletable ~findItems ~full ~package ~rawOpens
11641163
| Tvar None -> []
11651164
| _ -> []
11661165
in
1167-
let envRef = ref (QueryEnv.fromFile full.file) in
1168-
let getObjectFields (t : Types.type_expr) =
1169-
match t |> extractObjectType ~env:envRef.contents ~package with
1170-
| Some (env, tObj) ->
1171-
envRef := env;
1172-
getFields tObj
1173-
| None -> []
1174-
in
1175-
let fields =
1176-
match [lhs] |> findItems ~exact:true with
1177-
| {SharedTypes.item = Value typ} :: _ -> getObjectFields typ
1178-
| _ -> []
1166+
let getObjectFields ~env (t : Types.type_expr) =
1167+
match t |> extractObjectType ~env ~package with
1168+
| Some (env, tObj) -> (env, getFields tObj)
1169+
| None -> (env, [])
11791170
in
1180-
let rec resolvePath fields path =
1171+
let rec resolvePath ~env fields path =
11811172
match path with
11821173
| name :: restPath -> (
11831174
match fields |> List.find_opt (fun (n, _) -> n = name) with
11841175
| Some (_, fieldType) ->
1185-
let innerFields = getObjectFields fieldType in
1186-
resolvePath innerFields restPath
1176+
let env, innerFields = getObjectFields ~env fieldType in
1177+
resolvePath ~env innerFields restPath
11871178
| None -> [])
11881179
| [] -> fields
11891180
in
1190-
let labels = resolvePath fields path in
1181+
let env0 = QueryEnv.fromFile full.file in
1182+
let env, fields =
1183+
match [lhs] |> findItems ~exact:true with
1184+
| {SharedTypes.item = Value typ} :: _ -> getObjectFields ~env:env0 typ
1185+
| _ -> (env0, [])
1186+
in
1187+
let labels = resolvePath ~env fields path in
11911188
let mkLabel_ name typString =
11921189
mkItem ~name ~kind:4 ~deprecated:None ~detail:typString ~docstring:[]
11931190
in

0 commit comments

Comments
 (0)