Skip to content

Commit 9641213

Browse files
zthcristianoc
authored andcommitted
handle switches
1 parent b277f33 commit 9641213

File tree

7 files changed

+34
-75
lines changed

7 files changed

+34
-75
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
534534
| false, false -> ()))
535535
| _ -> unsetLookingForPat ()
536536
in
537-
538-
let case (iterator : Ast_iterator.iterator) (case : Parsetree.case) =
539-
let oldScope = !scope in
540-
scopePattern ?contextPath:!currentCtxPath case.pc_lhs;
541-
completePattern case.pc_lhs;
542-
Ast_iterator.default_iterator.case iterator case;
543-
scope := oldScope
544-
in
545537
let structure (iterator : Ast_iterator.iterator)
546538
(structure : Parsetree.structure) =
547539
let oldScope = !scope in
@@ -787,6 +779,18 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
787779
in
788780
typedCompletionExpr expr;
789781
match expr.pexp_desc with
782+
| Pexp_match (_expr, []) -> ()
783+
| Pexp_match (expr, cases) ->
784+
let ctxPath = exprToContextPath expr in
785+
let oldCtxPath = !currentCtxPath in
786+
cases
787+
|> List.iter (fun (case : Parsetree.case) ->
788+
let oldScope = !scope in
789+
scopePattern ?contextPath:ctxPath case.pc_lhs;
790+
completePattern case.pc_lhs;
791+
Ast_iterator.default_iterator.case iterator case;
792+
scope := oldScope);
793+
resetCurrentCtxPath oldCtxPath
790794
| Pexp_apply
791795
( {pexp_desc = Pexp_ident {txt = Lident "|."; loc = opLoc}},
792796
[
@@ -1157,7 +1161,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
11571161
{
11581162
Ast_iterator.default_iterator with
11591163
attribute;
1160-
case;
11611164
expr;
11621165
location;
11631166
module_expr;

analysis/tests/src/CompletionInferValues.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ type otherNestedRecord = {someRecord: someRecord, someTuple: (someVariant, int)}
9494
// Follow tuples
9595
// let x: otherNestedRecord = Obj.magic(); let {someTuple} = x; let (_, someInt) = someTuple; someInt->toS
9696
// ^com
97+
98+
// Same as above, but follow in switch case
99+
// let x: otherNestedRecord; switch x { | {someTuple} => let (_, someInt) = someTuple; someInt->toS }
100+
// ^com

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ Completable: CnamedArg(Value[someFn], isOff, [isOff])
55
[]
66

77
Complete src/BrokenParserCases.res 6:17
8-
posCursor:[6:17] posNoWhite:[6:16] Found expr:[6:3->6:21]
98
posCursor:[6:17] posNoWhite:[6:16] Found pattern:[6:16->6:19]
109
Completable: Cpattern Value[s]=t
1110
[]
1211

1312
Complete src/BrokenParserCases.res 10:29
14-
posCursor:[10:29] posNoWhite:[10:27] Found expr:[10:11->10:41]
1513
posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:39]
1614
posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:28]
1715
Ppat_construct None:[10:24->10:28]

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,6 @@ Resolved opens 2 Completion.res Completion.res
965965
[]
966966

967967
Complete src/Completion.res 243:8
968-
posCursor:[243:8] posNoWhite:[243:7] Found expr:[241:8->246:1]
969968
posCursor:[243:8] posNoWhite:[243:7] Found expr:[242:14->243:8]
970969
Pexp_apply ...[243:3->243:4] (...[242:14->242:15], ...[243:5->243:8])
971970
posCursor:[243:8] posNoWhite:[243:7] Found expr:[243:5->243:8]
@@ -1385,7 +1384,6 @@ Resolved opens 2 Completion.res Completion.res
13851384
}]
13861385

13871386
Complete src/Completion.res 343:57
1388-
posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:10->346:23]
13891387
posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:53->346:23]
13901388
posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:53->343:57]
13911389
Pexp_ident this:[343:53->343:57]
@@ -1445,7 +1443,6 @@ posCursor:[355:23] posNoWhite:[355:22] Found expr:[355:12->355:23]
14451443

14461444
Complete src/Completion.res 362:8
14471445
posCursor:[362:8] posNoWhite:[362:7] Found expr:[360:8->365:3]
1448-
posCursor:[362:8] posNoWhite:[362:7] Found expr:[361:2->365:3]
14491446
posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5]
14501447
posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8]
14511448
Ppat_construct T:[362:7->362:8]
@@ -1482,7 +1479,6 @@ Resolved opens 2 Completion.res Completion.res
14821479

14831480
Complete src/Completion.res 373:21
14841481
posCursor:[373:21] posNoWhite:[373:20] Found expr:[371:8->376:3]
1485-
posCursor:[373:21] posNoWhite:[373:20] Found expr:[372:2->376:3]
14861482
posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->375:5]
14871483
posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->373:21]
14881484
Ppat_construct AndThatOther.T:[373:7->373:21]

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,8 @@ Complete src/CompletionFunctionArguments.res 21:27
5757
posCursor:[21:27] posNoWhite:[21:26] Found expr:[19:8->25:1]
5858
Pexp_apply ...[19:8->19:14] (~isOn20:3->20:7=...[21:7->23:8])
5959
posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->23:8]
60-
posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->21:28]
61-
posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:14->21:28]
62-
Pexp_apply ...[21:14->21:20] (~isOn21:22->21:26=...__ghost__[0:-1->0:-1])
63-
Completable: Cexpression CArgument Value[someFn](~isOn)
64-
[{
65-
"label": "true",
66-
"kind": 4,
67-
"tags": [],
68-
"detail": "bool",
69-
"documentation": null
70-
}, {
71-
"label": "false",
72-
"kind": 4,
73-
"tags": [],
74-
"detail": "bool",
75-
"documentation": null
76-
}]
60+
posCursor:[21:27] posNoWhite:[21:26] Found expr:[21:7->23:8]
61+
[]
7762

7863
Complete src/CompletionFunctionArguments.res 34:24
7964
posCursor:[34:24] posNoWhite:[34:23] Found expr:[34:11->34:25]

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Completable: Cpath Value[x].""
222222

223223
Complete src/CompletionInferValues.res 74:78
224224
posCursor:[74:78] posNoWhite:[74:77] Found expr:[74:70->74:78]
225-
Pexp_field [74:70->74:77] _:[97:0->74:78]
225+
Pexp_field [74:70->74:77] _:[101:0->74:78]
226226
Completable: Cpath Value[srecord].""
227227
[{
228228
"label": "name",
@@ -240,7 +240,7 @@ Completable: Cpath Value[srecord].""
240240

241241
Complete src/CompletionInferValues.res 78:86
242242
posCursor:[78:86] posNoWhite:[78:85] Found expr:[78:78->78:86]
243-
Pexp_field [78:78->78:85] _:[97:0->78:86]
243+
Pexp_field [78:78->78:85] _:[101:0->78:86]
244244
Completable: Cpath Value[aliased].""
245245
[{
246246
"label": "someRecord",
@@ -252,7 +252,7 @@ Completable: Cpath Value[aliased].""
252252

253253
Complete src/CompletionInferValues.res 82:103
254254
posCursor:[82:103] posNoWhite:[82:102] Found expr:[82:92->82:103]
255-
Pexp_field [82:92->82:102] _:[97:0->82:103]
255+
Pexp_field [82:92->82:102] _:[101:0->82:103]
256256
Completable: Cpath Value[someRecord].""
257257
[{
258258
"label": "name",
@@ -307,3 +307,15 @@ Completable: Cpath Value[someInt]->toS
307307
"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"}
308308
}]
309309

310+
Complete src/CompletionInferValues.res 98:99
311+
posCursor:[98:99] posNoWhite:[98:98] Found expr:[98:57->98:99]
312+
posCursor:[98:99] posNoWhite:[98:98] Found expr:[98:87->98:99]
313+
Completable: Cpath Value[someInt]->toS
314+
[{
315+
"label": "Belt.Int.toString",
316+
"kind": 12,
317+
"tags": [],
318+
"detail": "int => string",
319+
"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"}
320+
}]
321+

0 commit comments

Comments
 (0)