Skip to content

Commit a61cc75

Browse files
fhammerschmidtcristianoc
andauthoredDec 1, 2022
Add failing completion test (#644)
* Add failing completion test * Fix issue with completing `foo. x` where `x` should not be part of the completion. * Smaller test output. Co-authored-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
1 parent 75bccdd commit a61cc75

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
- Fix issue where create interface file would not work with certain JSX V4 components https://github.com/rescript-lang/rescript-vscode/issues/617
3737

38+
- Fix issue with completing `foo. x` where `x` should not be part of the completion https://github.com/rescript-lang/rescript-vscode/pull/644
39+
3840
## v1.8.2
3941

4042
#### :rocket: New Feature

‎analysis/src/Utils.ml

+8-3
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ let dumpPath path = Str.global_replace (Str.regexp_string "\\") "/" path
5858
let isUncurriedInternal path = startsWith (Path.name path) "Js.Fn.arity"
5959

6060
let flattenLongIdent ?(jsx = false) ?(cutAtOffset = None) lid =
61+
let extendPath s path =
62+
match path with
63+
| "" :: _ -> path
64+
| _ -> s :: path
65+
in
6166
let rec loop lid =
6267
match lid with
6368
| Longident.Lident txt -> ([txt], String.length txt)
6469
| Ldot (lid, txt) ->
6570
let path, offset = loop lid in
66-
if Some offset = cutAtOffset then ("" :: path, offset + 1)
71+
if Some offset = cutAtOffset then (extendPath "" path, offset + 1)
6772
else if jsx && txt = "createElement" then (path, offset)
68-
else if txt = "_" then ("" :: path, offset + 1)
69-
else (txt :: path, offset + 1 + String.length txt)
73+
else if txt = "_" then (extendPath "" path, offset + 1)
74+
else (extendPath txt path, offset + 1 + String.length txt)
7075
| Lapply _ -> ([], 0)
7176
in
7277
let path, _ = loop lid in

‎analysis/tests/src/Completion.res

+9
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,12 @@ let header2 = `
405405

406406
// let _ = `color: ${r
407407
// ^com
408+
409+
let onClick = evt => {
410+
// SomeLocalModule.
411+
// ^com
412+
evt->ReactEvent.Synthetic.preventDefault
413+
// SomeLocalModule.
414+
// ^com
415+
Js.log("Hello")
416+
}

‎analysis/tests/src/expected/Completion.res.txt

+52-4
Original file line numberDiff line numberDiff line change
@@ -1625,10 +1625,11 @@ Resolved opens 2 Completion.res Completion.res
16251625
}]
16261626

16271627
Complete src/Completion.res 405:22
1628-
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->408:0]
1629-
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:22], ...[408:0->408:0])
1630-
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->405:22]
1631-
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->405:22])
1628+
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->417:0]
1629+
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->415:1], ...[417:0->417:0])
1630+
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->415:1]
1631+
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->415:1])
1632+
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->415:1]
16321633
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->405:22]
16331634
Pexp_ident r:[405:21->405:22]
16341635
Completable: Cpath Value[r]
@@ -1654,3 +1655,50 @@ Resolved opens 2 Completion.res Completion.res
16541655
"documentation": null
16551656
}]
16561657

1658+
Complete src/Completion.res 409:21
1659+
posCursor:[409:21] posNoWhite:[409:20] Found expr:[408:14->415:1]
1660+
posCursor:[409:21] posNoWhite:[409:20] Found expr:[409:5->414:17]
1661+
posCursor:[409:21] posNoWhite:[409:20] Found expr:[409:5->411:42]
1662+
posCursor:[409:21] posNoWhite:[409:20] Found expr:[409:5->411:5]
1663+
Pexp_ident SomeLocalModule.:[409:5->411:5]
1664+
Completable: Cpath Value[SomeLocalModule, ""]
1665+
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
1666+
Resolved opens 2 Completion.res Completion.res
1667+
[{
1668+
"label": "bb",
1669+
"kind": 12,
1670+
"tags": [],
1671+
"detail": "int",
1672+
"documentation": null
1673+
}, {
1674+
"label": "aa",
1675+
"kind": 12,
1676+
"tags": [],
1677+
"detail": "int",
1678+
"documentation": null
1679+
}]
1680+
1681+
Complete src/Completion.res 412:21
1682+
posCursor:[412:21] posNoWhite:[412:20] Found expr:[408:14->415:1]
1683+
posCursor:[412:21] posNoWhite:[412:20] Found expr:[411:2->414:17]
1684+
posCursor:[412:21] posNoWhite:[412:20] Found expr:[412:5->414:17]
1685+
Pexp_apply ...[412:5->414:8] (...[414:9->414:16])
1686+
posCursor:[412:21] posNoWhite:[412:20] Found expr:[412:5->414:8]
1687+
Pexp_ident SomeLocalModule.:[412:5->414:8]
1688+
Completable: Cpath Value[SomeLocalModule, ""]
1689+
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
1690+
Resolved opens 2 Completion.res Completion.res
1691+
[{
1692+
"label": "bb",
1693+
"kind": 12,
1694+
"tags": [],
1695+
"detail": "int",
1696+
"documentation": null
1697+
}, {
1698+
"label": "aa",
1699+
"kind": 12,
1700+
"tags": [],
1701+
"detail": "int",
1702+
"documentation": null
1703+
}]
1704+

0 commit comments

Comments
 (0)
Please sign in to comment.