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/Completion.res b/analysis/tests/src/Completion.res index 4f3f46c04..39b57c138 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 => { + // SomeLocalModule. + // ^com + evt->ReactEvent.Synthetic.preventDefault + // SomeLocalModule. + // ^com + Js.log("Hello") +} diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 1ed3bd93f..1f0c66e56 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,50 @@ Resolved opens 2 Completion.res Completion.res "documentation": null }] +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": "bb", + "kind": 12, + "tags": [], + "detail": "int", + "documentation": null + }, { + "label": "aa", + "kind": 12, + "tags": [], + "detail": "int", + "documentation": null + }] + +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: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": "bb", + "kind": 12, + "tags": [], + "detail": "int", + "documentation": null + }, { + "label": "aa", + "kind": 12, + "tags": [], + "detail": "int", + "documentation": null + }] +