From 1b0b75007909731532cb8b558fb67c7b2804ac79 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 08:34:42 +0200 Subject: [PATCH 01/12] Add example of missing complete for constructor in switch. See https://github.com/rescript-lang/rescript-vscode/issues/414 --- analysis/tests/src/Completion.res | 9 +++++++++ analysis/tests/src/expected/Completion.res.txt | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/analysis/tests/src/Completion.res b/analysis/tests/src/Completion.res index 389a91a2c..56132a461 100644 --- a/analysis/tests/src/Completion.res +++ b/analysis/tests/src/Completion.res @@ -355,3 +355,12 @@ let _ =
// (let _ = ff(~opt1=3)) // ^com + +type v = This | That + +let _ = x => + switch x { + // | T + // ^com + | _ => 4 + } diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index c51667981..fd866ee6b 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1381,3 +1381,8 @@ 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] +[] + From bea747257860fa9a1ba7783dd4033a06d015ca21 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 08:44:18 +0200 Subject: [PATCH 02/12] Add debug for Pexp_match. --- analysis/src/CompletionFrontEnd.ml | 13 +++++++++---- analysis/tests/src/expected/Completion.res.txt | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 079b52028..7958d5ba3 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -130,6 +130,7 @@ type labelled = { } type label = labelled option + type arg = {label : label; exp : Parsetree.expression} let findNamedArgCompletable ~(args : arg list) ~endPos ~posBeforeCursor @@ -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 @@ -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 diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index fd866ee6b..d8166559e 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -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]) @@ -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] @@ -1384,5 +1386,6 @@ 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 [] From 9d5b17c70bb148194d979592dd983957c3a5b6c9 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 08:47:03 +0200 Subject: [PATCH 03/12] Add one more test case. --- analysis/tests/src/Completion.res | 3 +++ analysis/tests/src/expected/Completion.res.txt | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/analysis/tests/src/Completion.res b/analysis/tests/src/Completion.res index 56132a461..cb18dcb0c 100644 --- a/analysis/tests/src/Completion.res +++ b/analysis/tests/src/Completion.res @@ -364,3 +364,6 @@ let _ = x => // ^com | _ => 4 } + +// let _ = x => switch x { | T +// ^com diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index d8166559e..528c5ec4e 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1389,3 +1389,9 @@ posCursor:[362:8] posNoWhite:[362:7] Found expr:[361:2->365:3] XXX Pexp_match with 1 cases not handled [] +Complete tests/src/Completion.res 367:30 +posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:11->367:30] +posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:16->367:30] +XXX Pexp_match with 1 cases not handled +[] + From e53b51e7fea556e9c0e28c6ae0f5716ef52beac4 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 08:48:53 +0200 Subject: [PATCH 04/12] One more test case. --- analysis/tests/src/Completion.res | 8 ++++++++ analysis/tests/src/expected/Completion.res.txt | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/analysis/tests/src/Completion.res b/analysis/tests/src/Completion.res index cb18dcb0c..b100fbe30 100644 --- a/analysis/tests/src/Completion.res +++ b/analysis/tests/src/Completion.res @@ -367,3 +367,11 @@ let _ = x => // let _ = x => switch x { | T // ^com + +let _ = x => + switch x { + // | T + // ^com + | _ if false => 4 + | _ => 4 + } diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 528c5ec4e..0e5484302 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1390,8 +1390,14 @@ XXX Pexp_match with 1 cases not handled [] Complete tests/src/Completion.res 367:30 -posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:11->367:30] -posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:16->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 [] +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 +[] + From 88cae8977805bced2470a8afbb48e97c538663fb Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 08:53:55 +0200 Subject: [PATCH 05/12] Show location of pattern and expression of first switch case. --- analysis/src/CompletionFrontEnd.ml | 9 +++++++-- analysis/tests/src/expected/Completion.res.txt | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 7958d5ba3..fa4d13d3f 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -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 diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 0e5484302..5d288e54a 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -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]) @@ -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] @@ -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 +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 +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 +XXX first case pattern:[372:7->374:5] expression:[374:18->374:19] [] From 9d59306d3ed59ce8e97ff5fcaeedd01efc7c4908 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 08:59:53 +0200 Subject: [PATCH 06/12] Inspect patterns in the AST. --- analysis/src/CompletionFrontEnd.ml | 10 ++++++++++ analysis/tests/src/expected/Completion.res.txt | 7 +++++++ analysis/tests/src/expected/Jsx.res.txt | 2 ++ 3 files changed, 19 insertions(+) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index fa4d13d3f..65d4a054c 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -676,6 +676,15 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text = | _ -> ()); Ast_iterator.default_iterator.typ iterator core_type in + let pat (iterator : Ast_iterator.iterator) (pat : Parsetree.pattern) = + if pat.ppat_loc |> Loc.hasPos ~pos:posNoWhite then ( + found := true; + if debug then + Printf.printf "posCursor:[%s] posNoWhite:[%s] Found pattern:%s\n" + (Pos.toString posCursor) (Pos.toString posNoWhite) + (Loc.toString pat.ppat_loc); + Ast_iterator.default_iterator.pat iterator pat) + in let module_expr (iterator : Ast_iterator.iterator) (me : Parsetree.module_expr) = (match me.pmod_desc with @@ -735,6 +744,7 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text = location; module_expr; module_type; + pat; signature; signature_item; structure; diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 5d288e54a..885e84854 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1032,6 +1032,7 @@ Completable: Cpath Value[SomeLocal] }] Complete tests/src/Completion.res 271:20 +posCursor:[271:20] posNoWhite:[271:19] Found pattern:[271:7->274:3] posCursor:[271:20] posNoWhite:[271:19] Found type:[271:11->274:3] Ptyp_constr SomeLocal:[271:11->274:3] Completable: Cpath Type[SomeLocal] @@ -1315,6 +1316,7 @@ posCursor:[336:26] posNoWhite:[336:25] Found expr:[334:13->346:23] posCursor:[336:26] posNoWhite:[336:25] Found expr:[334:13->338:6] posCursor:[336:26] posNoWhite:[336:25] Found expr:[335:6->338:5] posCursor:[336:26] posNoWhite:[336:25] Found expr:[336:16->338:5] +posCursor:[336:26] posNoWhite:[336:25] Found pattern:[336:20->338:5] posCursor:[336:26] posNoWhite:[336:25] Found type:[336:23->338:5] Ptyp_constr Res:[336:23->338:5] Completable: Cpath Type[Res] @@ -1390,6 +1392,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 XXX first case pattern:[362:7->364:5] expression:[364:9->364:10] +posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5] +posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8] [] Complete tests/src/Completion.res 367:30 @@ -1397,6 +1401,7 @@ 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 XXX first case pattern:[367:29->367:30] expression:[370:0->376:3] +posCursor:[367:30] posNoWhite:[367:29] Found pattern:[367:29->367:30] [] Complete tests/src/Completion.res 372:8 @@ -1404,5 +1409,7 @@ 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 XXX first case pattern:[372:7->374:5] expression:[374:18->374:19] +posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->374:5] +posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->372:8] [] diff --git a/analysis/tests/src/expected/Jsx.res.txt b/analysis/tests/src/expected/Jsx.res.txt index f91078652..d080052c6 100644 --- a/analysis/tests/src/expected/Jsx.res.txt +++ b/analysis/tests/src/expected/Jsx.res.txt @@ -276,6 +276,7 @@ Completable: Cjsx([WithChildren], n, [n]) }] Complete tests/src/Jsx.res 94:18 +posCursor:[94:18] posNoWhite:[94:17] Found pattern:[94:7->94:18] posCursor:[94:18] posNoWhite:[94:17] Found type:[94:11->94:18] Ptyp_constr React.e:[94:11->94:18] Completable: Cpath Type[React, e] @@ -288,6 +289,7 @@ Completable: Cpath Type[React, e] }] Complete tests/src/Jsx.res 96:20 +posCursor:[96:20] posNoWhite:[96:19] Found pattern:[96:7->99:6] posCursor:[96:20] posNoWhite:[96:19] Found type:[96:11->99:6] Ptyp_constr ReactDOMR:[96:11->99:6] Completable: Cpath Type[ReactDOMR] From 91f20b0ada117c480be407f176b44fdd01fecc8d Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 09:03:38 +0200 Subject: [PATCH 07/12] Print pattern constructor. --- analysis/src/CompletionFrontEnd.ml | 7 +++++++ analysis/tests/src/expected/Completion.res.txt | 3 +++ 2 files changed, 10 insertions(+) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 65d4a054c..d7c54a438 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -683,6 +683,13 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text = Printf.printf "posCursor:[%s] posNoWhite:[%s] Found pattern:%s\n" (Pos.toString posCursor) (Pos.toString posNoWhite) (Loc.toString pat.ppat_loc); + (match pat.ppat_desc with + | Ppat_construct (lid, _) -> + if debug then + Printf.printf "XXX Ppat_construct %s:%s\n" + (flattenLidCheckDot lid |> String.concat ".") + (Loc.toString lid.loc) + | _ -> ()); Ast_iterator.default_iterator.pat iterator pat) in let module_expr (iterator : Ast_iterator.iterator) diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 885e84854..26d82a9e1 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1394,6 +1394,7 @@ XXX Pexp_match with 1 cases not handled XXX first case pattern:[362:7->364:5] expression:[364:9->364:10] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8] +XXX Ppat_construct T:[362:7->362:8] [] Complete tests/src/Completion.res 367:30 @@ -1402,6 +1403,7 @@ posCursor:[367:30] posNoWhite:[367:29] Found expr:[367:16->376:3] XXX Pexp_match with 1 cases not handled XXX first case pattern:[367:29->367:30] expression:[370:0->376:3] posCursor:[367:30] posNoWhite:[367:29] Found pattern:[367:29->367:30] +XXX Ppat_construct T:[367:29->367:30] [] Complete tests/src/Completion.res 372:8 @@ -1411,5 +1413,6 @@ XXX Pexp_match with 2 cases not handled XXX first case pattern:[372:7->374:5] expression:[374:18->374:19] posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->374:5] posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->372:8] +XXX Ppat_construct T:[372:7->372:8] [] From 8eb112a7b3e749037dcc937392a945b385c1fbb4 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 09:05:28 +0200 Subject: [PATCH 08/12] Remove debugging of switched to clean up the output. --- analysis/src/CompletionFrontEnd.ml | 9 --------- analysis/tests/src/expected/Completion.res.txt | 10 ---------- 2 files changed, 19 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index d7c54a438..bb5864186 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -645,15 +645,6 @@ 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); - 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 diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 26d82a9e1..efebace6a 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -956,8 +956,6 @@ 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]) @@ -1336,8 +1334,6 @@ 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] @@ -1390,8 +1386,6 @@ 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 -XXX first case pattern:[362:7->364:5] expression:[364:9->364:10] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8] XXX Ppat_construct T:[362:7->362:8] @@ -1400,8 +1394,6 @@ XXX Ppat_construct T:[362:7->362:8] 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 -XXX first case pattern:[367:29->367:30] expression:[370:0->376:3] posCursor:[367:30] posNoWhite:[367:29] Found pattern:[367:29->367:30] XXX Ppat_construct T:[367:29->367:30] [] @@ -1409,8 +1401,6 @@ XXX Ppat_construct T:[367:29->367:30] 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 -XXX first case pattern:[372:7->374:5] expression:[374:18->374:19] posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->374:5] posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->372:8] XXX Ppat_construct T:[372:7->372:8] From 7a9b38a7840c917742aefdb3fb936e46ce8a34d8 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 09:05:51 +0200 Subject: [PATCH 09/12] Remove additional tests. --- analysis/tests/src/Completion.res | 11 ----------- analysis/tests/src/expected/Completion.res.txt | 15 --------------- 2 files changed, 26 deletions(-) diff --git a/analysis/tests/src/Completion.res b/analysis/tests/src/Completion.res index b100fbe30..56132a461 100644 --- a/analysis/tests/src/Completion.res +++ b/analysis/tests/src/Completion.res @@ -364,14 +364,3 @@ let _ = x => // ^com | _ => 4 } - -// let _ = x => switch x { | T -// ^com - -let _ = x => - switch x { - // | T - // ^com - | _ if false => 4 - | _ => 4 - } diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index efebace6a..5afba25f5 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1391,18 +1391,3 @@ posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8] XXX Ppat_construct T:[362:7->362:8] [] -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] -posCursor:[367:30] posNoWhite:[367:29] Found pattern:[367:29->367:30] -XXX Ppat_construct T:[367:29->367:30] -[] - -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] -posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->374:5] -posCursor:[372:8] posNoWhite:[372:7] Found pattern:[372:7->372:8] -XXX Ppat_construct T:[372:7->372:8] -[] - From 74c5a7b0dae7827421f7e907f12d0b442f3a7ba3 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 09:07:13 +0200 Subject: [PATCH 10/12] Add test with a more complex constructor path. --- analysis/tests/src/Completion.res | 11 +++++++++++ analysis/tests/src/expected/Completion.res.txt | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/analysis/tests/src/Completion.res b/analysis/tests/src/Completion.res index 56132a461..f364e964a 100644 --- a/analysis/tests/src/Completion.res +++ b/analysis/tests/src/Completion.res @@ -364,3 +364,14 @@ let _ = x => // ^com | _ => 4 } + +module AndThatOther = { + type v = And | ThatOther +} + +let _ = x => + switch x { + // | AndThatOther.T + // ^com + | _ => 4 + } diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 5afba25f5..38d0b5895 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1391,3 +1391,11 @@ posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8] XXX Ppat_construct T:[362:7->362:8] [] +Complete tests/src/Completion.res 373:21 +posCursor:[373:21] posNoWhite:[373:20] Found expr:[371:8->376:3] +posCursor:[373:21] posNoWhite:[373:20] Found expr:[372:2->376:3] +posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->375:5] +posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->373:21] +XXX Ppat_construct AndThatOther.T:[373:7->373:21] +[] + From 73bf47c73b51e004cdca5fcf6d2e0042e34e8845 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 09:10:00 +0200 Subject: [PATCH 11/12] Use the pattern path found to trigger completion. --- analysis/src/CompletionFrontEnd.ml | 6 ++-- .../tests/src/expected/Completion.res.txt | 36 +++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index bb5864186..b80234b68 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -676,10 +676,12 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text = (Loc.toString pat.ppat_loc); (match pat.ppat_desc with | Ppat_construct (lid, _) -> + let lidPath = flattenLidCheckDot lid in if debug then Printf.printf "XXX Ppat_construct %s:%s\n" - (flattenLidCheckDot lid |> String.concat ".") - (Loc.toString lid.loc) + (lidPath |> String.concat ".") + (Loc.toString lid.loc); + setResult (Cpath (CPId (lidPath, Value))) | _ -> ()); Ast_iterator.default_iterator.pat iterator pat) in diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 38d0b5895..699e032b6 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1389,7 +1389,32 @@ posCursor:[362:8] posNoWhite:[362:7] Found expr:[361:2->365:3] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8] XXX Ppat_construct T:[362:7->362:8] -[] +Completable: Cpath Value[T] +[{ + "label": "That", + "kind": 4, + "tags": [], + "detail": "That\n\ntype v = This | That", + "documentation": null + }, { + "label": "This", + "kind": 4, + "tags": [], + "detail": "This\n\ntype v = This | That", + "documentation": null + }, { + "label": "TableclothMap", + "kind": 9, + "tags": [], + "detail": "file module", + "documentation": null + }, { + "label": "TypeDefinition", + "kind": 9, + "tags": [], + "detail": "file module", + "documentation": null + }] Complete tests/src/Completion.res 373:21 posCursor:[373:21] posNoWhite:[373:20] Found expr:[371:8->376:3] @@ -1397,5 +1422,12 @@ posCursor:[373:21] posNoWhite:[373:20] Found expr:[372:2->376:3] posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->375:5] posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->373:21] XXX Ppat_construct AndThatOther.T:[373:7->373:21] -[] +Completable: Cpath Value[AndThatOther, T] +[{ + "label": "ThatOther", + "kind": 4, + "tags": [], + "detail": "ThatOther\n\ntype v = And | ThatOther", + "documentation": null + }] From 8ea472dc80b00b85b3eb4a79afb23924e07f7532 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 12 May 2022 09:14:11 +0200 Subject: [PATCH 12/12] Clean up debug output. Fixes https://github.com/rescript-lang/rescript-vscode/issues/414 --- analysis/src/CompletionFrontEnd.ml | 2 +- analysis/tests/src/expected/Completion.res.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index b80234b68..35c099463 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -678,7 +678,7 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text = | Ppat_construct (lid, _) -> let lidPath = flattenLidCheckDot lid in if debug then - Printf.printf "XXX Ppat_construct %s:%s\n" + Printf.printf "Ppat_construct %s:%s\n" (lidPath |> String.concat ".") (Loc.toString lid.loc); setResult (Cpath (CPId (lidPath, Value))) diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 699e032b6..5776927a6 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1388,7 +1388,7 @@ posCursor:[362:8] posNoWhite:[362:7] Found expr:[360:8->365:3] posCursor:[362:8] posNoWhite:[362:7] Found expr:[361:2->365:3] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->364:5] posCursor:[362:8] posNoWhite:[362:7] Found pattern:[362:7->362:8] -XXX Ppat_construct T:[362:7->362:8] +Ppat_construct T:[362:7->362:8] Completable: Cpath Value[T] [{ "label": "That", @@ -1421,7 +1421,7 @@ posCursor:[373:21] posNoWhite:[373:20] Found expr:[371:8->376:3] posCursor:[373:21] posNoWhite:[373:20] Found expr:[372:2->376:3] posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->375:5] posCursor:[373:21] posNoWhite:[373:20] Found pattern:[373:7->373:21] -XXX Ppat_construct AndThatOther.T:[373:7->373:21] +Ppat_construct AndThatOther.T:[373:7->373:21] Completable: Cpath Value[AndThatOther, T] [{ "label": "ThatOther",