Skip to content

Commit 46a1349

Browse files
zthcristianoc
authored andcommitted
make Tarray work with both extracted and type expr types
1 parent 5fd0e27 commit 46a1349

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
709709
| Some (typ, env) ->
710710
[
711711
Completion.create "dummy" ~env
712-
~kind:(Completion.ExtractedType (Tarray (env, typ), `Type));
712+
~kind:
713+
(Completion.ExtractedType (Tarray (env, ExtractedType typ), `Type));
713714
])
714715
| Pipe ->
715716
(* Pipe completion with array just needs to know that it's an array, not
@@ -1314,11 +1315,14 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
13141315
~insertText:(if !Cfg.supportsSnippets then "[$0]" else "[]")
13151316
~sortText:"A"
13161317
~kind:
1317-
(ExtractedType
1318-
( typ,
1319-
match mode with
1320-
| Pattern _ -> `Type
1321-
| Expression -> `Value ))
1318+
(match typ with
1319+
| ExtractedType typ ->
1320+
ExtractedType
1321+
( typ,
1322+
match mode with
1323+
| Pattern _ -> `Type
1324+
| Expression -> `Value )
1325+
| TypeExpr typ -> Value typ)
13221326
~env ();
13231327
]
13241328
else []

analysis/src/SharedTypes.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ and completionType =
302302
| Texn of QueryEnv.t
303303
| Toption of QueryEnv.t * innerType
304304
| Tbool of QueryEnv.t
305-
| Tarray of QueryEnv.t * completionType
305+
| Tarray of QueryEnv.t * innerType
306306
| Tstring of QueryEnv.t
307307
| Tvariant of {
308308
env: QueryEnv.t;

analysis/src/TypeUtils.ml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ let rec extractType ~env ~package (t : Types.type_expr) =
114114
| Tconstr (Path.Pident {name = "option"}, [payloadTypeExpr], _) ->
115115
Some (Toption (env, TypeExpr payloadTypeExpr))
116116
| Tconstr (Path.Pident {name = "array"}, [payloadTypeExpr], _) ->
117-
payloadTypeExpr |> extractType ~env ~package
118-
|> Option.map (fun payloadTyp -> Tarray (env, payloadTyp))
117+
Some (Tarray (env, TypeExpr payloadTypeExpr))
119118
| Tconstr (Path.Pident {name = "bool"}, [], _) -> Some (Tbool env)
120119
| Tconstr (Path.Pident {name = "string"}, [], _) -> Some (Tstring env)
121120
| Tconstr (Path.Pident {name = "exn"}, [], _) -> Some (Texn env)
@@ -341,7 +340,13 @@ let rec resolveNested (typ : completionType) ~env ~full ~nested =
341340
|> extractType ~env ~package:full.package
342341
|> Utils.Option.flatMap (fun typ ->
343342
typ |> resolveNested ~env ~full ~nested)))
344-
| NArray, Tarray (env, typ) -> typ |> resolveNested ~env ~full ~nested
343+
| NArray, Tarray (env, ExtractedType typ) ->
344+
typ |> resolveNested ~env ~full ~nested
345+
| NArray, Tarray (env, TypeExpr typ) ->
346+
typ
347+
|> extractType ~env ~package:full.package
348+
|> Utils.Option.flatMap (fun typ ->
349+
typ |> resolveNested ~env ~full ~nested)
345350
| _ -> None)
346351

347352
let getArgs ~env (t : Types.type_expr) ~full =
@@ -417,7 +422,9 @@ let rec extractedTypeToString ?(inner = false) = function
417422
else Shared.typeToString typ
418423
| Tbool _ -> "bool"
419424
| Tstring _ -> "string"
420-
| Tarray (_, innerTyp) ->
425+
| Tarray (_, TypeExpr innerTyp) ->
426+
"array<" ^ Shared.typeToString innerTyp ^ ">"
427+
| Tarray (_, ExtractedType innerTyp) ->
421428
"array<" ^ extractedTypeToString ~inner:true innerTyp ^ ">"
422429
| Toption (_, TypeExpr innerTyp) ->
423430
"option<" ^ Shared.typeToString innerTyp ^ ">"

analysis/tests/src/expected/CompletionJsxProps.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] testAr
173173
"label": "[]",
174174
"kind": 12,
175175
"tags": [],
176-
"detail": "type testVariant = One | Two | Three(int)",
176+
"detail": "testVariant",
177177
"documentation": null,
178178
"sortText": "A",
179179
"insertText": "{[$0]}",

analysis/tests/src/expected/CompletionPattern.res.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ XXX Not found!
410410
Completable: Cpattern Value[c]
411411
[{
412412
"label": "[]",
413-
"kind": 22,
413+
"kind": 12,
414414
"tags": [],
415415
"detail": "bool",
416416
"documentation": null,
@@ -539,7 +539,7 @@ posCursor:[143:35] posNoWhite:[143:34] Found pattern:[143:20->143:38]
539539
Completable: Cpattern Value[p]->variantPayload::Test($3)
540540
[{
541541
"label": "[]",
542-
"kind": 22,
542+
"kind": 12,
543543
"tags": [],
544544
"detail": "bool",
545545
"documentation": null,
@@ -625,7 +625,7 @@ posCursor:[159:36] posNoWhite:[159:35] Found pattern:[159:21->159:38]
625625
Completable: Cpattern Value[v]->polyvariantPayload::test($3)
626626
[{
627627
"label": "[]",
628-
"kind": 22,
628+
"kind": 12,
629629
"tags": [],
630630
"detail": "bool",
631631
"documentation": null,

0 commit comments

Comments
 (0)