Skip to content

Add failing completion test #644

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions analysis/src/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions analysis/tests/src/Completion.res
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,12 @@ let header2 = `

// let _ = `color: ${r
// ^com

let onClick = evt => {
// SomeLocalModule.
// ^com
evt->ReactEvent.Synthetic.preventDefault
// SomeLocalModule.
// ^com
Js.log("Hello")
}
56 changes: 52 additions & 4 deletions analysis/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
}]