Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete switch constructor #415

Merged
merged 12 commits into from
May 12, 2022
Prev Previous commit
Next Next commit
Show location of pattern and expression of first switch case.
  • Loading branch information
cristianoc committed May 12, 2022
commit 88cae8977805bced2470a8afbb48e97c538663fb
9 changes: 7 additions & 2 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,15 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
iterator.expr iterator modBody;
scope := oldScope;
processed := true
| Pexp_match (_, cases) ->
| Pexp_match (_, cases) -> (
Printf.printf "XXX Pexp_match with %d cases not handled\n"
(List.length cases);
()
match cases with
| {pc_lhs; pc_rhs} :: _ ->
Printf.printf "XXX first case pattern:%s expression:%s\n"
(Loc.toString pc_lhs.ppat_loc)
(Loc.toString pc_rhs.pexp_loc)
| _ -> ())
| _ -> ());
if not !processed then Ast_iterator.default_iterator.expr iterator expr
in
Expand Down
5 changes: 5 additions & 0 deletions analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ Completable: Cnone
Complete tests/src/Completion.res 243:8
posCursor:[243:8] posNoWhite:[243:7] Found expr:[241:8->246:1]
XXX Pexp_match with 1 cases not handled
XXX first case pattern:[242:2->242:10] expression:[242:14->245:8]
posCursor:[243:8] posNoWhite:[243:7] Found expr:[242:14->245:8]
posCursor:[243:8] posNoWhite:[243:7] Found expr:[242:14->245:1]
Pexp_apply ...[243:3->243:4] (...[242:14->242:15], ...[243:5->245:1])
Expand Down Expand Up @@ -1334,6 +1335,7 @@ Completable: Cpath Type[Res]
Complete tests/src/Completion.res 343:57
posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:10->346:23]
XXX Pexp_match with 1 cases not handled
XXX first case pattern:[343:29->343:49] expression:[343:53->346:23]
posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:53->346:23]
posCursor:[343:57] posNoWhite:[343:56] Found expr:[343:53->343:57]
Pexp_ident this:[343:53->343:57]
Expand Down Expand Up @@ -1387,17 +1389,20 @@ Complete tests/src/Completion.res 362:8
posCursor:[362:8] posNoWhite:[362:7] Found expr:[360:8->365:3]
posCursor:[362:8] posNoWhite:[362:7] Found expr:[361:2->365:3]
XXX Pexp_match with 1 cases not handled
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows that parser recovery leads to a single case being considered in the switch.

XXX first case pattern:[362:7->364:5] expression:[364:9->364:10]
[]

Complete tests/src/Completion.res 367:30
posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:11->376:3]
posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:16->376:3]
XXX Pexp_match with 1 cases not handled
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows that parser recovery also gives 1 case when no more cases others follow.

XXX first case pattern:[367:29->367:30] expression:[370:0->376:3]
[]

Complete tests/src/Completion.res 372:8
posCursor:[372:8] posNoWhite:[372:7] Found expr:[370:8->376:3]
posCursor:[372:8] posNoWhite:[372:7] Found expr:[371:2->376:3]
XXX Pexp_match with 2 cases not handled
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example confirms that the first 2 cases are squashed into one.

XXX first case pattern:[372:7->374:5] expression:[374:18->374:19]
[]