Skip to content

Commit 6e67aef

Browse files
committed
Inspect patterns in the AST.
1 parent 46c2f30 commit 6e67aef

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,15 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
676676
| _ -> ());
677677
Ast_iterator.default_iterator.typ iterator core_type
678678
in
679+
let pat (iterator : Ast_iterator.iterator) (pat : Parsetree.pattern) =
680+
if pat.ppat_loc |> Loc.hasPos ~pos:posNoWhite then (
681+
found := true;
682+
if debug then
683+
Printf.printf "posCursor:[%s] posNoWhite:[%s] Found pattern:%s\n"
684+
(Pos.toString posCursor) (Pos.toString posNoWhite)
685+
(Loc.toString pat.ppat_loc);
686+
Ast_iterator.default_iterator.pat iterator pat)
687+
in
679688
let module_expr (iterator : Ast_iterator.iterator)
680689
(me : Parsetree.module_expr) =
681690
(match me.pmod_desc with
@@ -735,6 +744,7 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
735744
location;
736745
module_expr;
737746
module_type;
747+
pat;
738748
signature;
739749
signature_item;
740750
structure;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ Completable: Cpath Value[SomeLocal]
10321032
}]
10331033

10341034
Complete tests/src/Completion.res 271:20
1035+
posCursor:[271:20] posNoWhite:[271:19] Found pattern:[271:7->274:3]
10351036
posCursor:[271:20] posNoWhite:[271:19] Found type:[271:11->274:3]
10361037
Ptyp_constr SomeLocal:[271:11->274:3]
10371038
Completable: Cpath Type[SomeLocal]
@@ -1315,6 +1316,7 @@ posCursor:[336:26] posNoWhite:[336:25] Found expr:[334:13->346:23]
13151316
posCursor:[336:26] posNoWhite:[336:25] Found expr:[334:13->338:6]
13161317
posCursor:[336:26] posNoWhite:[336:25] Found expr:[335:6->338:5]
13171318
posCursor:[336:26] posNoWhite:[336:25] Found expr:[336:16->338:5]
1319+
posCursor:[336:26] posNoWhite:[336:25] Found pattern:[336:20->338:5]
13181320
posCursor:[336:26] posNoWhite:[336:25] Found type:[336:23->338:5]
13191321
Ptyp_constr Res:[336:23->338:5]
13201322
Completable: Cpath Type[Res]
@@ -1390,19 +1392,24 @@ posCursor:[362:8] posNoWhite:[362:7] Found expr:[360:8->365:3]
13901392
posCursor:[362:8] posNoWhite:[362:7] Found expr:[361:2->365:3]
13911393
XXX Pexp_match with 1 cases not handled
13921394
XXX first case pattern:[362:7->364:5] expression:[364:9->364:10]
1395+
posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5]
1396+
posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8]
13931397
[]
13941398

13951399
Complete tests/src/Completion.res 367:30
13961400
posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:11->376:3]
13971401
posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:16->376:3]
13981402
XXX Pexp_match with 1 cases not handled
13991403
XXX first case pattern:[367:29->367:30] expression:[370:0->376:3]
1404+
posCursor:[367:30] posNoWhite:[367:29] Found pattern:[367:29->367:30]
14001405
[]
14011406

14021407
Complete tests/src/Completion.res 372:8
14031408
posCursor:[372:8] posNoWhite:[372:7] Found expr:[370:8->376:3]
14041409
posCursor:[372:8] posNoWhite:[372:7] Found expr:[371:2->376:3]
14051410
XXX Pexp_match with 2 cases not handled
14061411
XXX first case pattern:[372:7->374:5] expression:[374:18->374:19]
1412+
posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->374:5]
1413+
posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->372:8]
14071414
[]
14081415

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ Completable: Cjsx([WithChildren], n, [n])
276276
}]
277277

278278
Complete tests/src/Jsx.res 94:18
279+
posCursor:[94:18] posNoWhite:[94:17] Found pattern:[94:7->94:18]
279280
posCursor:[94:18] posNoWhite:[94:17] Found type:[94:11->94:18]
280281
Ptyp_constr React.e:[94:11->94:18]
281282
Completable: Cpath Type[React, e]
@@ -288,6 +289,7 @@ Completable: Cpath Type[React, e]
288289
}]
289290

290291
Complete tests/src/Jsx.res 96:20
292+
posCursor:[96:20] posNoWhite:[96:19] Found pattern:[96:7->99:6]
291293
posCursor:[96:20] posNoWhite:[96:19] Found type:[96:11->99:6]
292294
Ptyp_constr ReactDOMR:[96:11->99:6]
293295
Completable: Cpath Type[ReactDOMR]

0 commit comments

Comments
 (0)