Skip to content

Commit 300a700

Browse files
committed
move Tarray to use completion type as well, plus clean up completion item kind output
1 parent 78d58c8 commit 300a700

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ let detail name (kind : Completion.kind) =
233233
^ ")")
234234
^ "\n\n" ^ s
235235
| Snippet s -> s
236-
| ExtractedType extractedType -> TypeUtils.extractedTypeToString extractedType
236+
| ExtractedType (extractedType, _) ->
237+
TypeUtils.extractedTypeToString extractedType
237238

238239
let findAllCompletions ~(env : QueryEnv.t) ~prefix ~exact ~namesUsed
239240
~(completionContext : Completable.completionContext) =
@@ -594,7 +595,7 @@ let completionsGetCompletionType ~full = function
594595
match TypeUtils.extractTypeFromResolvedType typ ~env ~full with
595596
| None -> None
596597
| Some extractedType -> Some (extractedType, env))
597-
| {Completion.kind = ExtractedType typ; env} :: _ -> Some (typ, env)
598+
| {Completion.kind = ExtractedType (typ, _); env} :: _ -> Some (typ, env)
598599
| _ -> None
599600

600601
let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
@@ -1112,7 +1113,14 @@ let rec completeTypedValue (t : SharedTypes.completionType) ~full ~prefix
11121113
[
11131114
Completion.createWithSnippet ~name:"{}"
11141115
~insertText:(if !Cfg.supportsSnippets then "{$0}" else "{}")
1115-
~sortText:"A" ~kind:(ExtractedType extractedType) ~env ();
1116+
~sortText:"A"
1117+
~kind:
1118+
(ExtractedType
1119+
( extractedType,
1120+
match mode with
1121+
| Pattern -> `Type
1122+
| Expression -> `Value ))
1123+
~env ();
11161124
]
11171125
else [])
11181126
| TinlineRecord {env; fields} -> (
@@ -1133,12 +1141,19 @@ let rec completeTypedValue (t : SharedTypes.completionType) ~full ~prefix
11331141
~sortText:"A" ~kind:(Label "Inline record") ~env ();
11341142
]
11351143
else [])
1136-
| Tarray (env, typeExpr) ->
1144+
| Tarray (env, typ) ->
11371145
if prefix = "" then
11381146
[
11391147
Completion.createWithSnippet ~name:"[]"
11401148
~insertText:(if !Cfg.supportsSnippets then "[$0]" else "[]")
1141-
~sortText:"A" ~kind:(Value typeExpr) ~env ();
1149+
~sortText:"A"
1150+
~kind:
1151+
(ExtractedType
1152+
( typ,
1153+
match mode with
1154+
| Pattern -> `Type
1155+
| Expression -> `Value ))
1156+
~env ();
11421157
]
11431158
else []
11441159
| Tstring env ->

analysis/src/SharedTypes.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ type completionType =
299299
| Tuple of QueryEnv.t * Types.type_expr list * Types.type_expr
300300
| Toption of QueryEnv.t * completionType
301301
| Tbool of QueryEnv.t
302-
| Tarray of QueryEnv.t * Types.type_expr
302+
| Tarray of QueryEnv.t * completionType
303303
| Tstring of QueryEnv.t
304304
| Tvariant of {
305305
env: QueryEnv.t;
@@ -336,7 +336,7 @@ module Completion = struct
336336
| Field of field * string
337337
| FileModule of string
338338
| Snippet of string
339-
| ExtractedType of completionType
339+
| ExtractedType of completionType * [`Value | `Type]
340340

341341
type t = {
342342
name: string;
@@ -387,8 +387,8 @@ module Completion = struct
387387
| ObjLabel _ -> 4
388388
| Label _ -> 4
389389
| Field (_, _) -> 5
390-
| Type _ | ExtractedType _ -> 22
391-
| Value _ -> 12
390+
| Type _ | ExtractedType (_, `Type) -> 22
391+
| Value _ | ExtractedType (_, `Value) -> 12
392392
| Snippet _ -> 15
393393
end
394394

analysis/src/TypeUtils.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ let rec extractType ~env ~package (t : Types.type_expr) =
115115
payloadTypeExpr |> extractType ~env ~package
116116
|> Option.map (fun payloadTyp -> Toption (env, payloadTyp))
117117
| Tconstr (Path.Pident {name = "array"}, [payloadTypeExpr], _) ->
118-
Some (Tarray (env, payloadTypeExpr))
118+
payloadTypeExpr |> extractType ~env ~package
119+
|> Option.map (fun payloadTyp -> Tarray (env, payloadTyp))
119120
| Tconstr (Path.Pident {name = "bool"}, [], _) -> Some (Tbool env)
120121
| Tconstr (Path.Pident {name = "string"}, [], _) -> Some (Tstring env)
121122
| Tconstr (path, _, _) -> (
@@ -335,11 +336,7 @@ let rec resolveNested (typ : completionType) ~env ~full ~nested =
335336
|> extractType ~env ~package:full.package
336337
|> Utils.Option.flatMap (fun typ ->
337338
typ |> resolveNested ~env ~full ~nested)))
338-
| NArray, Tarray (env, typ) ->
339-
typ
340-
|> extractType ~env ~package:full.package
341-
|> Utils.Option.flatMap (fun typ ->
342-
typ |> resolveNested ~env ~full ~nested)
339+
| NArray, Tarray (env, typ) -> typ |> resolveNested ~env ~full ~nested
343340
| _ -> None)
344341

345342
let getArgs ~env (t : Types.type_expr) ~full =
@@ -406,8 +403,8 @@ let rec extractedTypeToString = function
406403
Shared.typeToString typ
407404
| Tbool _ -> "bool"
408405
| Tstring _ -> "string"
409-
| Tarray (_, innerTyp) -> "array<" ^ Shared.typeToString innerTyp ^ ">"
410-
| Toption (_, typ) -> "option<" ^ extractedTypeToString typ ^ ">"
406+
| Tarray (_, innerTyp) -> "array<" ^ extractedTypeToString innerTyp ^ ">"
407+
| Toption (_, innerTyp) -> "option<" ^ extractedTypeToString innerTyp ^ ">"
411408
| Tvariant {variantDecl; variantName} ->
412409
Shared.declToString variantName variantDecl
413410
| Trecord {definition = `NameOnly name; fields} ->

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(nested
169169
"insertTextFormat": 2
170170
}, {
171171
"label": "Some({})",
172-
"kind": 22,
172+
"kind": 12,
173173
"tags": [],
174174
"detail": "otherRecord",
175175
"documentation": null,
@@ -264,7 +264,7 @@ Pexp_apply ...[56:11->56:25] (...[56:26->56:60])
264264
Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(polyvariant), polyvariantPayload::three($0)
265265
[{
266266
"label": "{}",
267-
"kind": 22,
267+
"kind": 12,
268268
"tags": [],
269269
"detail": "someRecord",
270270
"documentation": null,
@@ -590,7 +590,7 @@ Pexp_apply ...[135:11->135:31] (...[135:32->135:66])
590590
Completable: Cexpression CArgument Value[fnTakingInlineRecord]($0)->variantPayload::WithInlineRecord($0), recordField(nestedRecord)
591591
[{
592592
"label": "{}",
593-
"kind": 22,
593+
"kind": 12,
594594
"tags": [],
595595
"detail": "otherRecord",
596596
"documentation": null,

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": 12,
413+
"kind": 22,
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": 12,
542+
"kind": 22,
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": 12,
628+
"kind": 22,
629629
"tags": [],
630630
"detail": "bool",
631631
"documentation": null,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ XXX Not found!
33
Completable: Cexpression Type[someRecord]
44
[{
55
"label": "{}",
6-
"kind": 22,
6+
"kind": 12,
77
"tags": [],
88
"detail": "type someRecord = {age: int, name: string}",
99
"documentation": null,

0 commit comments

Comments
 (0)