Skip to content

Commit 881edb1

Browse files
zthcristianoc
authored andcommitted
poc complete pattern of function parameter
1 parent 9641213 commit 881edb1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
456456
scope :=
457457
!scope |> Scope.addModule ~name:md.pmd_name.txt ~loc:md.pmd_name.loc
458458
in
459+
(* TODO: Can get rid of setLookingForPat soon *)
459460
let setLookingForPat ctxPath = lookingForPat := Some ctxPath in
460461
let inJsxContext = ref false in
461462

@@ -1032,8 +1033,12 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
10321033
(match defaultExpOpt with
10331034
| None -> ()
10341035
| Some defaultExp -> iterator.expr iterator defaultExp);
1035-
scopePattern ?contextPath:!currentCtxPath pat;
1036+
(match !currentCtxPath with
1037+
| None -> ()
1038+
| Some ctxPath -> setLookingForPat ctxPath);
10361039
completePattern pat;
1040+
unsetLookingForPat ();
1041+
scopePattern ?contextPath:!currentCtxPath pat;
10371042
iterator.pat iterator pat;
10381043
iterator.expr iterator e;
10391044
scope := oldScope;

analysis/tests/src/CompletionInferValues.res

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,11 @@ type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)}
9898
// Same as above, but follow in switch case
9999
// let x: otherNestedRecord; switch x { | {someTuple} => let (_, someInt) = someTuple; someInt->toS }
100100
// ^com
101+
102+
let fnWithRecordCallback = (cb: someRecord => unit) => {
103+
let _ = cb
104+
}
105+
106+
// Complete pattern of function parameter
107+
// fnWithRecordCallback(({}) => {()})
108+
// ^com

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,24 @@ Completable: Cpath Value[someInt]->toS
319319
"documentation": {"kind": "markdown", "value": "\n Converts a given `int` to a `string`. Uses the JavaScript `String` constructor under the hood.\n\n ```res example\n Js.log(Belt.Int.toString(1) === \"1\") /* true */\n ```\n"}
320320
}]
321321

322+
Complete src/CompletionInferValues.res 105:26
323+
posCursor:[105:26] posNoWhite:[105:25] Found expr:[105:3->105:37]
324+
Pexp_apply ...[105:3->105:23] (...[105:24->105:36])
325+
posCursor:[105:26] posNoWhite:[105:25] Found expr:[105:24->105:36]
326+
posCursor:[105:26] posNoWhite:[105:25] Found pattern:[105:25->105:27]
327+
posCursor:[105:26] posNoWhite:[105:25] Found pattern:[105:25->105:27]
328+
Completable: Cpattern CArgument CArgument Value[fnWithRecordCallback]($0)($0)->recordBody
329+
[{
330+
"label": "name",
331+
"kind": 5,
332+
"tags": [],
333+
"detail": "name: string\n\nsomeRecord",
334+
"documentation": null
335+
}, {
336+
"label": "age",
337+
"kind": 5,
338+
"tags": [],
339+
"detail": "age: int\n\nsomeRecord",
340+
"documentation": null
341+
}]
342+

0 commit comments

Comments
 (0)