Skip to content

Commit 46e0dcb

Browse files
committed
remove old resolveNested entirely
1 parent 94506da commit 46e0dcb

File tree

2 files changed

+4
-114
lines changed

2 files changed

+4
-114
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,8 +1841,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
18411841
typ
18421842
|> TypeUtils.extractType2 ~env ~package:full.package
18431843
|> Utils.Option.flatMap (fun (typ, typeArgContext) ->
1844-
typ
1845-
|> TypeUtils.resolveNested2 ?typeArgContext ~env ~full ~nested)
1844+
typ |> TypeUtils.resolveNested ?typeArgContext ~env ~full ~nested)
18461845
with
18471846
| None -> fallbackOrEmpty ()
18481847
| Some (typ, _env, completionContext, typeArgContext) ->
@@ -1875,7 +1874,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
18751874
print_endline "--> could not get completions for context path";
18761875
regularCompletions
18771876
| Some (typ, env) -> (
1878-
match typ |> TypeUtils.resolveNested2 ~env ~full ~nested with
1877+
match typ |> TypeUtils.resolveNested ~env ~full ~nested with
18791878
| None ->
18801879
if Debug.verbose () then
18811880
print_endline "--> could not resolve nested expression path";

analysis/src/TypeUtils.ml

Lines changed: 2 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ let maybeSetTypeArgCtx ?typeArgContextFromTypeManifest ~typeParams ~typeArgs env
243243
(debugLogTypeArgContext typeArgContext));
244244
typeArgContext
245245

246+
(* TODO(env-stuff) Maybe this could be removed entirely if we can guarantee that we don't have to look up functions from in here. *)
246247
let rec extractFunctionType2 ?typeArgContext ~env ~package typ =
247248
let rec loop ?typeArgContext ~env acc (t : Types.type_expr) =
248249
match t.desc with
@@ -608,119 +609,9 @@ let extractTypeFromResolvedType (typ : Type.t) ~env ~full =
608609
(** The context we just came from as we resolve the nested structure. *)
609610
type ctx = Rfield of string (** A record field of name *)
610611

611-
(** This moves through a nested path via a set of instructions, trying to resolve the type at the end of the path. *)
612-
let rec resolveNested ~env ~full ~nested ?ctx (typ : completionType) =
613-
match nested with
614-
| [] ->
615-
Some
616-
( typ,
617-
env,
618-
match ctx with
619-
| None -> None
620-
| Some (Rfield fieldName) ->
621-
Some (Completable.CameFromRecordField fieldName) )
622-
| patternPath :: nested -> (
623-
match (patternPath, typ) with
624-
| Completable.NTupleItem {itemNum}, Tuple (env, tupleItems, _) -> (
625-
match List.nth_opt tupleItems itemNum with
626-
| None -> None
627-
| Some typ ->
628-
typ
629-
|> extractType ~env ~package:full.package
630-
|> Utils.Option.flatMap (fun typ ->
631-
typ |> resolveNested ~env ~full ~nested))
632-
| ( NFollowRecordField {fieldName},
633-
(TinlineRecord {env; fields} | Trecord {env; fields}) ) -> (
634-
match
635-
fields
636-
|> List.find_opt (fun (field : field) -> field.fname.txt = fieldName)
637-
with
638-
| None -> None
639-
| Some {typ; optional} ->
640-
let typ = if optional then Utils.unwrapIfOption typ else typ in
641-
642-
typ
643-
|> extractType ~env ~package:full.package
644-
|> Utils.Option.flatMap (fun typ ->
645-
typ |> resolveNested ~ctx:(Rfield fieldName) ~env ~full ~nested))
646-
| NRecordBody {seenFields}, Trecord {env; definition = `TypeExpr typeExpr}
647-
->
648-
typeExpr
649-
|> extractType ~env ~package:full.package
650-
|> Option.map (fun typ ->
651-
(typ, env, Some (Completable.RecordField {seenFields})))
652-
| ( NRecordBody {seenFields},
653-
(Trecord {env; definition = `NameOnly _} as extractedType) ) ->
654-
Some (extractedType, env, Some (Completable.RecordField {seenFields}))
655-
| NRecordBody {seenFields}, TinlineRecord {env; fields} ->
656-
Some
657-
( TinlineRecord {fields; env},
658-
env,
659-
Some (Completable.RecordField {seenFields}) )
660-
| ( NVariantPayload {constructorName = "Some"; itemNum = 0},
661-
Toption (env, ExtractedType typ) ) ->
662-
typ |> resolveNested ~env ~full ~nested
663-
| ( NVariantPayload {constructorName = "Some"; itemNum = 0},
664-
Toption (env, TypeExpr typ) ) ->
665-
typ
666-
|> extractType ~env ~package:full.package
667-
|> Utils.Option.flatMap (fun t -> t |> resolveNested ~env ~full ~nested)
668-
| NVariantPayload {constructorName = "Ok"; itemNum = 0}, Tresult {okType} ->
669-
okType
670-
|> extractType ~env ~package:full.package
671-
|> Utils.Option.flatMap (fun t -> t |> resolveNested ~env ~full ~nested)
672-
| ( NVariantPayload {constructorName = "Error"; itemNum = 0},
673-
Tresult {errorType} ) ->
674-
errorType
675-
|> extractType ~env ~package:full.package
676-
|> Utils.Option.flatMap (fun t -> t |> resolveNested ~env ~full ~nested)
677-
| NVariantPayload {constructorName; itemNum}, Tvariant {env; constructors}
678-
-> (
679-
match
680-
constructors
681-
|> List.find_opt (fun (c : Constructor.t) ->
682-
c.cname.txt = constructorName)
683-
with
684-
| Some {args = Args args} -> (
685-
match List.nth_opt args itemNum with
686-
| None -> None
687-
| Some (typ, _) ->
688-
typ
689-
|> extractType ~env ~package:full.package
690-
|> Utils.Option.flatMap (fun typ ->
691-
typ |> resolveNested ~env ~full ~nested))
692-
| Some {args = InlineRecord fields} when itemNum = 0 ->
693-
TinlineRecord {env; fields} |> resolveNested ~env ~full ~nested
694-
| _ -> None)
695-
| ( NPolyvariantPayload {constructorName; itemNum},
696-
Tpolyvariant {env; constructors} ) -> (
697-
match
698-
constructors
699-
|> List.find_opt (fun (c : polyVariantConstructor) ->
700-
c.name = constructorName)
701-
with
702-
| None -> None
703-
| Some constructor -> (
704-
match List.nth_opt constructor.args itemNum with
705-
| None -> None
706-
| Some typ ->
707-
typ
708-
|> extractType ~env ~package:full.package
709-
|> Utils.Option.flatMap (fun typ ->
710-
typ |> resolveNested ~env ~full ~nested)))
711-
| NArray, Tarray (env, ExtractedType typ) ->
712-
typ |> resolveNested ~env ~full ~nested
713-
| NArray, Tarray (env, TypeExpr typ) ->
714-
typ
715-
|> extractType ~env ~package:full.package
716-
|> Utils.Option.flatMap (fun typ ->
717-
typ |> resolveNested ~env ~full ~nested)
718-
| _ -> None)
719-
720-
let rec resolveNested2 ?typeArgContext ~env ~full ~nested ?ctx
612+
let rec resolveNested ?typeArgContext ~env ~full ~nested ?ctx
721613
(typ : completionType) =
722614
let extractType = extractType2 ?typeArgContext in
723-
let resolveNested = resolveNested2 in
724615
if Debug.verbose () then
725616
Printf.printf
726617
"[nested]--> running nested in env: %s. Has type arg ctx: %b\n"

0 commit comments

Comments
 (0)