Skip to content

Commit 47f9650

Browse files
committed
clarify record name field a bit
1 parent 45a5387 commit 47f9650

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

analysis/src/SharedTypes.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ type completionType =
315315
| Trecord of {
316316
env: QueryEnv.t;
317317
fields: field list;
318-
name: [`Str of string | `TypeExpr of Types.type_expr];
318+
definition:
319+
[ `NameOnly of string
320+
(** When we only have the name, like when pulling the record from a declared type. *)
321+
| `TypeExpr of Types.type_expr
322+
(** When we have the full type expr from the compiler. *) ];
319323
}
320324
| TinlineRecord of {env: QueryEnv.t; fields: field list}
321325
| Tfunction of {env: QueryEnv.t; args: typedFnArg list; typ: Types.type_expr}

analysis/src/TypeUtils.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ let rec extractType ~env ~package (t : Types.type_expr) =
126126
(Tvariant
127127
{env; constructors; variantName = name.txt; variantDecl = decl})
128128
| Some (env, {item = {kind = Record fields}}) ->
129-
Some (Trecord {env; fields; name = `TypeExpr t})
129+
Some (Trecord {env; fields; definition = `TypeExpr t})
130130
| _ -> None)
131131
| Ttuple expressions -> Some (Tuple (env, expressions, t))
132132
| Tvariant {row_fields} ->
@@ -245,7 +245,8 @@ let rec resolveTypeForPipeCompletion ~env ~package ~lhsLoc ~full
245245
let extractTypeFromResolvedType (typ : Type.t) ~env ~full =
246246
match typ.kind with
247247
| Tuple items -> Some (Tuple (env, items, Ctype.newty (Ttuple items)))
248-
| Record fields -> Some (Trecord {env; fields; name = `Str typ.name})
248+
| Record fields ->
249+
Some (Trecord {env; fields; definition = `NameOnly typ.name})
249250
| Variant constructors ->
250251
Some
251252
(Tvariant
@@ -282,13 +283,14 @@ let rec resolveNested (typ : completionType) ~env ~full ~nested =
282283
|> extractType ~env ~package:full.package
283284
|> Utils.Option.flatMap (fun typ ->
284285
typ |> resolveNested ~env ~full ~nested))
285-
| NRecordBody {seenFields}, Trecord {env; name = `TypeExpr typeExpr} ->
286+
| NRecordBody {seenFields}, Trecord {env; definition = `TypeExpr typeExpr}
287+
->
286288
typeExpr
287289
|> extractType ~env ~package:full.package
288290
|> Option.map (fun typ ->
289291
(typ, env, Some (Completable.RecordField {seenFields})))
290-
| NRecordBody {seenFields}, (Trecord {env; name = `Str _} as extractedType)
291-
->
292+
| ( NRecordBody {seenFields},
293+
(Trecord {env; definition = `NameOnly _} as extractedType) ) ->
292294
Some (extractedType, env, Some (Completable.RecordField {seenFields}))
293295
| NRecordBody {seenFields}, TinlineRecord {env; fields} ->
294296
Some
@@ -403,12 +405,13 @@ let extractedTypeToString = function
403405
| Toption (_, typ)
404406
| Tpolyvariant {typeExpr = typ}
405407
| Tfunction {typ}
406-
| Trecord {name = `TypeExpr typ} ->
408+
| Trecord {definition = `TypeExpr typ} ->
407409
Shared.typeToString typ
408410
| Tbool _ -> "bool"
409411
| Tstring _ -> "string"
410412
| Tarray (_, innerTyp) -> "array<" ^ Shared.typeToString innerTyp ^ ">"
411413
| Tvariant {variantDecl; variantName} ->
412414
Shared.declToString variantName variantDecl
413-
| Trecord {name = `Str name; fields} -> printRecordFromFields ~name fields
415+
| Trecord {definition = `NameOnly name; fields} ->
416+
printRecordFromFields ~name fields
414417
| TinlineRecord {fields} -> printRecordFromFields fields

0 commit comments

Comments
 (0)