Skip to content

Commit dfb0422

Browse files
committedJan 6, 2023
complete unsaved tuples
1 parent 467bc00 commit dfb0422

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed
 

‎analysis/src/CompletionBackEnd.ml

+19
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,25 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
14581458
})
14591459
| None -> [])
14601460
| None -> [])
1461+
| CTuple ctxPaths ->
1462+
(* Turn a list of context paths into a list of type expressions. *)
1463+
let typeExrps =
1464+
ctxPaths
1465+
|> List.map (fun contextPath ->
1466+
contextPath
1467+
|> getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles
1468+
~pos ~env ~exact:true ~scope)
1469+
|> List.filter_map (fun completionItems ->
1470+
match completionItems with
1471+
| {Completion.kind = Value typ} :: _ -> Some typ
1472+
| _ -> None)
1473+
in
1474+
if List.length ctxPaths = List.length typeExrps then
1475+
[
1476+
Completion.create ~name:"dummy" ~env
1477+
~kind:(Completion.Value (Ctype.newty (Ttuple typeExrps)));
1478+
]
1479+
else []
14611480

14621481
let getOpens ~debug ~rawOpens ~package ~env =
14631482
if debug && rawOpens <> [] then

‎analysis/src/CompletionFrontEnd.ml

+5
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ let rec exprToContextPath (e : Parsetree.expression) =
260260
match exprToContextPath e1 with
261261
| None -> None
262262
| Some contexPath -> Some (CPApply (contexPath, args |> List.map fst)))
263+
| Pexp_tuple exprs ->
264+
let exprsAsContextPaths = exprs |> List.filter_map exprToContextPath in
265+
if List.length exprs = List.length exprsAsContextPaths then
266+
Some (CTuple exprsAsContextPaths)
267+
else None
263268
| _ -> None
264269

265270
let rec getUnqualifiedName txt =

‎analysis/src/SharedTypes.ml

+5
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ module Completable = struct
549549
lhsLoc: Location.t;
550550
(** The loc item for the left hand side of the pipe. *)
551551
}
552+
| CTuple of contextPath list
552553

553554
(** Additional context for a pattern completion where needed. *)
554555
type patternContext = RecordField of {seenFields: string list}
@@ -648,6 +649,10 @@ module Completable = struct
648649
| CPField (cp, s) -> contextPathToString cp ^ "." ^ str s
649650
| CPObj (cp, s) -> contextPathToString cp ^ "[\"" ^ s ^ "\"]"
650651
| CPPipe {contextPath; id} -> contextPathToString contextPath ^ "->" ^ id
652+
| CTuple ctxPaths ->
653+
"CTuple("
654+
^ (ctxPaths |> List.map contextPathToString |> String.concat ", ")
655+
^ ")"
651656
in
652657

653658
function
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let s = true
2+
let f = Some([false])
3+
4+
// switch (s, f) { | }
5+
// ^com
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Complete src/CompletionExpressions.res 3:20
2+
XXX Not found!
3+
Completable: Cpattern CTuple(Value[s], Value[f])
4+
[{
5+
"label": "(_, _)",
6+
"kind": 12,
7+
"tags": [],
8+
"detail": "(bool, option<array<bool>>)",
9+
"documentation": null,
10+
"insertText": "(${1:_}, ${2:_})",
11+
"insertTextFormat": 2
12+
}]
13+

0 commit comments

Comments
 (0)
Please sign in to comment.