Skip to content

Commit 27de032

Browse files
committed
fix full variant completion item text
1 parent f759d83 commit 27de032

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,12 @@ type extractedType =
14871487
| Tuple of QueryEnv.t * Types.type_expr list
14881488
| Toption of QueryEnv.t * Types.type_expr
14891489
| Tbool of QueryEnv.t
1490-
| Tvariant of {env: QueryEnv.t; constructors: Constructor.t list}
1490+
| Tvariant of {
1491+
env: QueryEnv.t;
1492+
constructors: Constructor.t list;
1493+
variantDecl: Types.type_declaration;
1494+
variantName: string;
1495+
}
14911496

14921497
(* This is a more general extraction function for pulling out the type of a type_expr. We already have other similar functions, but they are all specialized on something (variants, records, etc). *)
14931498
let rec extractType ~env ~package (t : Types.type_expr) =
@@ -1503,8 +1508,10 @@ let rec extractType ~env ~package (t : Types.type_expr) =
15031508
match References.digConstructor ~env ~package path with
15041509
| Some (env, {item = {decl = {type_manifest = Some t1}}}) ->
15051510
extractType ~env ~package t1
1506-
| Some (env, {item = {kind = Type.Variant constructors}}) ->
1507-
Some (Tvariant {env; constructors})
1511+
| Some (env, {name; item = {decl; kind = Type.Variant constructors}}) ->
1512+
Some
1513+
(Tvariant
1514+
{env; constructors; variantName = name.txt; variantDecl = decl})
15081515
| _ -> None)
15091516
| Ttuple expressions -> Some (Tuple (env, expressions))
15101517
| _ -> None
@@ -1532,7 +1539,7 @@ let completeTypedValue ~env ~full ~prefix ~expandOption =
15321539
items
15331540
|> List.filter (fun (item : Completion.t) ->
15341541
Utils.startsWith item.name prefix)
1535-
| Some (Tvariant {env; constructors}) ->
1542+
| Some (Tvariant {env; constructors; variantDecl; variantName}) ->
15361543
let items =
15371544
constructors
15381545
|> List.filter_map (fun (constructor : Constructor.t) ->
@@ -1553,7 +1560,10 @@ let completeTypedValue ~env ~full ~prefix ~expandOption =
15531560
|> String.concat ", ")
15541561
^ ")"
15551562
else "")
1556-
~kind:(Constructor (constructor, "" (* TODO *)))
1563+
~kind:
1564+
(Constructor
1565+
( constructor,
1566+
variantDecl |> Shared.declToString variantName ))
15571567
~env))
15581568
in
15591569
items

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ Completable: Value[someFnTakingVariant](~config)
9494
"label": "One",
9595
"kind": 4,
9696
"tags": [],
97-
"detail": "One\n\n",
97+
"detail": "One\n\ntype someVariant = One | Two | Three(int, string)",
9898
"documentation": null
9999
}, {
100100
"label": "Two",
101101
"kind": 4,
102102
"tags": [],
103-
"detail": "Two\n\n",
103+
"detail": "Two\n\ntype someVariant = One | Two | Three(int, string)",
104104
"documentation": null
105105
}, {
106106
"label": "Three(_, _)",
107107
"kind": 4,
108108
"tags": [],
109-
"detail": "Three(int, string)\n\n",
109+
"detail": "Three(int, string)\n\ntype someVariant = One | Two | Three(int, string)",
110110
"documentation": null
111111
}]
112112

@@ -118,7 +118,7 @@ Completable: Value[someFnTakingVariant](~config=O)
118118
"label": "One",
119119
"kind": 4,
120120
"tags": [],
121-
"detail": "One\n\n",
121+
"detail": "One\n\ntype someVariant = One | Two | Three(int, string)",
122122
"documentation": null
123123
}, {
124124
"label": "OIncludeMeInCompletions",
@@ -148,7 +148,7 @@ Completable: Value[someFnTakingVariant](~configOpt2=O)
148148
"label": "One",
149149
"kind": 4,
150150
"tags": [],
151-
"detail": "One\n\n",
151+
"detail": "One\n\ntype someVariant = One | Two | Three(int, string)",
152152
"documentation": null
153153
}, {
154154
"label": "OIncludeMeInCompletions",

0 commit comments

Comments
 (0)