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
13 changes: 9 additions & 4 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type labelled = {
}

type label = labelled option

type arg = {label : label; exp : Parsetree.expression}

let findNamedArgCompletable ~(args : arg list) ~endPos ~posBeforeCursor
Expand Down Expand Up @@ -561,10 +562,10 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
| Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident "|."}}, [_; _]) ->
()
| Pexp_apply (funExpr, args)
when not
(* Normally named arg completion fires when the cursor is right after the expression.
E.g in foo(~<---there
But it should not fire in foo(~a)<---there *)
when (* Normally named arg completion fires when the cursor is right after the expression.
E.g in foo(~<---there
But it should not fire in foo(~a)<---there *)
not
(Loc.end_ expr.pexp_loc = posCursor
&& charBeforeCursor = Some ')') ->
let args = extractExpApplyArgs ~args in
Expand Down Expand Up @@ -644,6 +645,10 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
iterator.expr iterator modBody;
scope := oldScope;
processed := true
| Pexp_match (_, cases) ->
Printf.printf "XXX Pexp_match with %d cases not handled\n"
(List.length cases);
()
| _ -> ());
if not !processed then Ast_iterator.default_iterator.expr iterator expr
in
Expand Down
20 changes: 20 additions & 0 deletions analysis/tests/src/Completion.res
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,23 @@ let _ = <div name="" />

// (let _ = ff(~opt1=3))
// ^com

type v = This | That

let _ = x =>
switch x {
// | T
// ^com
| _ => 4
}

// let _ = x => switch x { | T
// ^com

let _ = x =>
switch x {
// | T
// ^com
| _ if false => 4
| _ => 4
}
20 changes: 20 additions & 0 deletions analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,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
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 @@ -1332,6 +1333,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
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 @@ -1381,3 +1383,21 @@ posCursor:[355:23] posNoWhite:[355:22] Found expr:[0:-1->355:23]
posCursor:[355:23] posNoWhite:[355:22] Found expr:[355:12->355:23]
[]

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.

[]

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.

[]

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.

[]