From 91e1c59ec7a13acbeb0642ea5862744ff7ee8656 Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Thu, 1 Dec 2022 14:27:31 +0100 Subject: [PATCH 1/3] Add failing completion test --- analysis/tests/src/Completion.res | 9 ++ .../tests/src/expected/Completion.res.txt | 134 +++++++++++++++++- 2 files changed, 139 insertions(+), 4 deletions(-) diff --git a/analysis/tests/src/Completion.res b/analysis/tests/src/Completion.res index 4f3f46c04..992d0f1cb 100644 --- a/analysis/tests/src/Completion.res +++ b/analysis/tests/src/Completion.res @@ -405,3 +405,12 @@ let header2 = ` // let _ = `color: ${r // ^com + +let onClick = evt => { + // ReactEvent. + // ^com + evt->ReactEvent.Synthetic.preventDefault + // ReactEvent. + // ^com + Js.log("Hello") +} diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 1ed3bd93f..f0bf30612 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1625,10 +1625,11 @@ Resolved opens 2 Completion.res Completion.res }] Complete src/Completion.res 405:22 -posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->408:0] -Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:22], ...[408:0->408:0]) -posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->405:22] -Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->405:22]) +posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->417:0] +Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->415:1], ...[417:0->417:0]) +posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->415:1] +Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->415:1]) +posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->415:1] posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->405:22] Pexp_ident r:[405:21->405:22] Completable: Cpath Value[r] @@ -1654,3 +1655,128 @@ Resolved opens 2 Completion.res Completion.res "documentation": null }] +Complete src/Completion.res 409:16 +posCursor:[409:16] posNoWhite:[409:15] Found expr:[408:14->415:1] +posCursor:[409:16] posNoWhite:[409:15] Found expr:[409:5->414:17] +posCursor:[409:16] posNoWhite:[409:15] Found expr:[409:5->411:42] +posCursor:[409:16] posNoWhite:[409:15] Found expr:[409:5->411:5] +Pexp_ident ReactEvent.:[409:5->411:5] +Completable: Cpath Value[ReactEvent, ""] +Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder +Resolved opens 2 Completion.res Completion.res +[{ + "label": "toSyntheticEvent", + "kind": 12, + "tags": [], + "detail": "synthetic<'a> => Synthetic.t", + "documentation": null + }, { + "label": "Touch", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Synthetic", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Pointer", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Animation", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Image", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Clipboard", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Keyboard", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Selection", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Media", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Transition", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Composition", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Mouse", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Focus", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "UI", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Wheel", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Form", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }] + +Complete src/Completion.res 412:16 +posCursor:[412:16] posNoWhite:[412:15] Found expr:[408:14->415:1] +posCursor:[412:16] posNoWhite:[412:15] Found expr:[411:2->414:17] +posCursor:[412:16] posNoWhite:[412:15] Found expr:[412:5->414:17] +Pexp_apply ...[412:5->414:8] (...[414:9->414:16]) +posCursor:[412:16] posNoWhite:[412:15] Found expr:[412:5->414:8] +Pexp_ident ReactEvent..log:[412:5->414:8] +Completable: Cpath Value[ReactEvent, "", log] +Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder +Resolved opens 2 Completion.res Completion.res +[] + From ff75aa18c17eacbdbc58d3899cb46989219aa8f6 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 1 Dec 2022 20:13:08 +0100 Subject: [PATCH 2/3] Fix issue with completing `foo. x` where `x` should not be part of the completion. --- CHANGELOG.md | 2 + analysis/src/Utils.ml | 11 +- .../tests/src/expected/Completion.res.txt | 108 +++++++++++++++++- 3 files changed, 115 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e06cba97f..3db548572 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ - Fix issue where create interface file would not work with certain JSX V4 components https://github.com/rescript-lang/rescript-vscode/issues/617 +- Fix issue with completing `foo. x` where `x` should not be part of the completion https://github.com/rescript-lang/rescript-vscode/pull/644 + ## v1.8.2 #### :rocket: New Feature diff --git a/analysis/src/Utils.ml b/analysis/src/Utils.ml index ff4299c7b..56533af89 100644 --- a/analysis/src/Utils.ml +++ b/analysis/src/Utils.ml @@ -58,15 +58,20 @@ let dumpPath path = Str.global_replace (Str.regexp_string "\\") "/" path let isUncurriedInternal path = startsWith (Path.name path) "Js.Fn.arity" let flattenLongIdent ?(jsx = false) ?(cutAtOffset = None) lid = + let extendPath s path = + match path with + | "" :: _ -> path + | _ -> s :: path + in let rec loop lid = match lid with | Longident.Lident txt -> ([txt], String.length txt) | Ldot (lid, txt) -> let path, offset = loop lid in - if Some offset = cutAtOffset then ("" :: path, offset + 1) + if Some offset = cutAtOffset then (extendPath "" path, offset + 1) else if jsx && txt = "createElement" then (path, offset) - else if txt = "_" then ("" :: path, offset + 1) - else (txt :: path, offset + 1 + String.length txt) + else if txt = "_" then (extendPath "" path, offset + 1) + else (extendPath txt path, offset + 1 + String.length txt) | Lapply _ -> ([], 0) in let path, _ = loop lid in diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index f0bf30612..a94604d7c 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1774,9 +1774,111 @@ posCursor:[412:16] posNoWhite:[412:15] Found expr:[411:2->414:17] posCursor:[412:16] posNoWhite:[412:15] Found expr:[412:5->414:17] Pexp_apply ...[412:5->414:8] (...[414:9->414:16]) posCursor:[412:16] posNoWhite:[412:15] Found expr:[412:5->414:8] -Pexp_ident ReactEvent..log:[412:5->414:8] -Completable: Cpath Value[ReactEvent, "", log] +Pexp_ident ReactEvent.:[412:5->414:8] +Completable: Cpath Value[ReactEvent, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res -[] +[{ + "label": "toSyntheticEvent", + "kind": 12, + "tags": [], + "detail": "synthetic<'a> => Synthetic.t", + "documentation": null + }, { + "label": "Touch", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Synthetic", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Pointer", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Animation", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Image", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Clipboard", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Keyboard", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Selection", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Media", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Transition", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Composition", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Mouse", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Focus", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "UI", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Wheel", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }, { + "label": "Form", + "kind": 9, + "tags": [], + "detail": "module", + "documentation": null + }] From 83b2338aa97fd87c02ca63d7340a76286785ebd3 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 1 Dec 2022 20:20:51 +0100 Subject: [PATCH 3/3] Smaller test output. --- analysis/tests/src/Completion.res | 8 +- .../tests/src/expected/Completion.res.txt | 228 ++---------------- 2 files changed, 28 insertions(+), 208 deletions(-) diff --git a/analysis/tests/src/Completion.res b/analysis/tests/src/Completion.res index 992d0f1cb..39b57c138 100644 --- a/analysis/tests/src/Completion.res +++ b/analysis/tests/src/Completion.res @@ -407,10 +407,10 @@ let header2 = ` // ^com let onClick = evt => { - // ReactEvent. - // ^com + // SomeLocalModule. + // ^com evt->ReactEvent.Synthetic.preventDefault - // ReactEvent. - // ^com + // SomeLocalModule. + // ^com Js.log("Hello") } diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index a94604d7c..1f0c66e56 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -1655,230 +1655,50 @@ Resolved opens 2 Completion.res Completion.res "documentation": null }] -Complete src/Completion.res 409:16 -posCursor:[409:16] posNoWhite:[409:15] Found expr:[408:14->415:1] -posCursor:[409:16] posNoWhite:[409:15] Found expr:[409:5->414:17] -posCursor:[409:16] posNoWhite:[409:15] Found expr:[409:5->411:42] -posCursor:[409:16] posNoWhite:[409:15] Found expr:[409:5->411:5] -Pexp_ident ReactEvent.:[409:5->411:5] -Completable: Cpath Value[ReactEvent, ""] +Complete src/Completion.res 409:21 +posCursor:[409:21] posNoWhite:[409:20] Found expr:[408:14->415:1] +posCursor:[409:21] posNoWhite:[409:20] Found expr:[409:5->414:17] +posCursor:[409:21] posNoWhite:[409:20] Found expr:[409:5->411:42] +posCursor:[409:21] posNoWhite:[409:20] Found expr:[409:5->411:5] +Pexp_ident SomeLocalModule.:[409:5->411:5] +Completable: Cpath Value[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res [{ - "label": "toSyntheticEvent", + "label": "bb", "kind": 12, "tags": [], - "detail": "synthetic<'a> => Synthetic.t", - "documentation": null - }, { - "label": "Touch", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Synthetic", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Pointer", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Animation", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Image", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Clipboard", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Keyboard", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Selection", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Media", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Transition", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Composition", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Mouse", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Focus", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "UI", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Wheel", - "kind": 9, - "tags": [], - "detail": "module", + "detail": "int", "documentation": null }, { - "label": "Form", - "kind": 9, + "label": "aa", + "kind": 12, "tags": [], - "detail": "module", + "detail": "int", "documentation": null }] -Complete src/Completion.res 412:16 -posCursor:[412:16] posNoWhite:[412:15] Found expr:[408:14->415:1] -posCursor:[412:16] posNoWhite:[412:15] Found expr:[411:2->414:17] -posCursor:[412:16] posNoWhite:[412:15] Found expr:[412:5->414:17] +Complete src/Completion.res 412:21 +posCursor:[412:21] posNoWhite:[412:20] Found expr:[408:14->415:1] +posCursor:[412:21] posNoWhite:[412:20] Found expr:[411:2->414:17] +posCursor:[412:21] posNoWhite:[412:20] Found expr:[412:5->414:17] Pexp_apply ...[412:5->414:8] (...[414:9->414:16]) -posCursor:[412:16] posNoWhite:[412:15] Found expr:[412:5->414:8] -Pexp_ident ReactEvent.:[412:5->414:8] -Completable: Cpath Value[ReactEvent, ""] +posCursor:[412:21] posNoWhite:[412:20] Found expr:[412:5->414:8] +Pexp_ident SomeLocalModule.:[412:5->414:8] +Completable: Cpath Value[SomeLocalModule, ""] Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder Resolved opens 2 Completion.res Completion.res [{ - "label": "toSyntheticEvent", + "label": "bb", "kind": 12, "tags": [], - "detail": "synthetic<'a> => Synthetic.t", - "documentation": null - }, { - "label": "Touch", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Synthetic", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Pointer", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Animation", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Image", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Clipboard", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Keyboard", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Selection", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Media", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Transition", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Composition", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Mouse", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Focus", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "UI", - "kind": 9, - "tags": [], - "detail": "module", - "documentation": null - }, { - "label": "Wheel", - "kind": 9, - "tags": [], - "detail": "module", + "detail": "int", "documentation": null }, { - "label": "Form", - "kind": 9, + "label": "aa", + "kind": 12, "tags": [], - "detail": "module", + "detail": "int", "documentation": null }]