Skip to content

Commit 5fd8fde

Browse files
committed
simple completion for tuples
1 parent fe57708 commit 5fd8fde

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ let rec extractType ~env ~package (t : Types.type_expr) =
15181518
(Tvariant
15191519
{env; constructors; variantName = name.txt; variantDecl = decl})
15201520
| _ -> None)
1521-
| Ttuple expressions -> Some (Tuple (env, expressions))
1521+
| Ttuple expressions -> Some (Tuple (env, expressions, t))
15221522
| _ -> None
15231523

15241524
let filterItems items ~prefix =
@@ -1585,6 +1585,14 @@ let completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
15851585
~env ~insertText:"Some(${1:_})" ();
15861586
]
15871587
|> filterItems ~prefix
1588+
| Some (Tuple (env, exprs, typ)) ->
1589+
let numExprs = List.length exprs in
1590+
[
1591+
Completion.createWithSnippet
1592+
~name:(printConstructorArgs numExprs ~asSnippet:false)
1593+
~insertText:(printConstructorArgs numExprs ~asSnippet:true)
1594+
~kind:(Value typ) ~env ();
1595+
]
15881596
| _ -> []
15891597
in
15901598
(* Include all values and modules in completion if there's a prefix, not otherwise *)

analysis/src/SharedTypes.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ module Completable = struct
569569

570570
(** An extracted type from a type expr *)
571571
type extractedType =
572-
| Tuple of QueryEnv.t * Types.type_expr list
572+
| Tuple of QueryEnv.t * Types.type_expr list * Types.type_expr
573573
| Toption of QueryEnv.t * Types.type_expr
574574
| Tbool of QueryEnv.t
575575
| Tvariant of {

analysis/tests/src/CompletionFunctionArguments.res

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@ let someFnTakingVariant = (
6969

7070
// let _ = 1->someOtherFn(1, t)
7171
// ^com
72+
73+
let fnTakingTuple = (arg: (int, int, float)) => {
74+
ignore(arg)
75+
}
76+
77+
// let _ = fnTakingTuple()
78+
// ^com

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ Completable: Cargument Value[someOtherFn]($0=f)
8484
"tags": [],
8585
"detail": "bool",
8686
"documentation": null
87+
}, {
88+
"label": "fnTakingTuple",
89+
"kind": 12,
90+
"tags": [],
91+
"detail": "((int, int, float)) => unit",
92+
"documentation": null
8793
}]
8894

8995
Complete src/CompletionFunctionArguments.res 51:39
@@ -223,3 +229,17 @@ Completable: Cargument Value[someOtherFn]($2=t)
223229
"documentation": null
224230
}]
225231

232+
Complete src/CompletionFunctionArguments.res 76:25
233+
posCursor:[76:25] posNoWhite:[76:24] Found expr:[76:11->76:26]
234+
Pexp_apply ...[76:11->76:24] (...[76:25->76:26])
235+
Completable: Cargument Value[fnTakingTuple]($0)
236+
[{
237+
"label": "(_, _, _)",
238+
"kind": 12,
239+
"tags": [],
240+
"detail": "(int, int, float)",
241+
"documentation": null,
242+
"insertText": "(${1:_}, ${2:_}, ${3:_})",
243+
"insertTextFormat": 2
244+
}]
245+

0 commit comments

Comments
 (0)