Skip to content

Commit 40ac61b

Browse files
authored
Additional completion tests (#1062)
* Add Rxjs completion test * Add Rxjs binding example * Extend Rxjs test with fully qualified access * Add@editor.completeFrom and incomplete test output * Add passing test for property completion * Test still works when types are not named t. * Add test for @editor.completeFrom
1 parent ec9dab9 commit 40ac61b

8 files changed

+261
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@@warning("-26")
2+
@@warning("-27")
3+
@@warning("-110")
4+
5+
module A = {
6+
@editor.completeFrom(B) @editor.completeFrom(C)
7+
type a
8+
}
9+
10+
module B = {
11+
let b = (a: A.a) => 1
12+
}
13+
14+
module C = {
15+
open A
16+
let c = (a: a) => {'c'}
17+
}
18+
19+
let a : A.a = %todo
20+
// a.
21+
// ^com
22+
// B.b and C.c should be completed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module ObservablePoint = {
2+
type op = {
3+
mutable x: int,
4+
mutable y: int,
5+
}
6+
7+
@send
8+
external setBoth: (op, float) => unit = "set"
9+
10+
@send
11+
external set: (op, float, float) => unit = "set"
12+
}
13+
14+
module Sprite = {
15+
type s = {
16+
anchor: ObservablePoint.op,
17+
}
18+
}
19+
20+
let sprite : Sprite.s = %todo
21+
22+
// sprite.anchor.
23+
// ^com

analysis/tests/src/Rxjs.res

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// These are bindings used in RxjsCompletion.res
2+
// We are using a separate file to test complication for modules of external files.
3+
type target
4+
5+
module Subscriber = {
6+
type t<'t> = {next: 't => unit}
7+
}
8+
9+
module Observable = {
10+
// Complete items defined inside the parent module.
11+
@editor.completeFrom(Rxjs)
12+
type t<'t>
13+
14+
type dispose = unit => unit
15+
16+
@new @module("rxjs")
17+
external make: (Subscriber.t<'t> => dispose) => t<'t> = "Observable"
18+
19+
type subscription
20+
21+
@send
22+
external subscribe: (t<'t>, 't => unit) => subscription = "subscribe"
23+
}
24+
25+
@module("rxjs")
26+
external fromEvent: (target, string) => Observable.t<'t> = "fromEvent"
27+
28+
type operation<'t, 'u>
29+
30+
@send
31+
external pipe: (Observable.t<'t>, operation<'t, 'u>) => Observable.t<'u> = "pipe"
32+
33+
@send
34+
external pipe2: (Observable.t<'t>, operation<'t, 'u>, operation<'u, 'i>) => Observable.t<'i> =
35+
"pipe"
36+
37+
@module("rxjs")
38+
external map: ('t => 'u) => operation<'t, 'u> = "map"
39+
40+
@module("rxjs")
41+
external distinctUntilChanged: unit => operation<'t, 't> = "distinctUntilChanged"
42+
43+
@module("rxjs")
44+
external merge: (Observable.t<'t>, Observable.t<'t>) => Observable.t<'t> = "merge"
45+
46+
@module("rxjs")
47+
external scan: (('acc, 't) => 'acc, 'acc) => operation<'t, 'acc> = "scan"
48+
49+
@module("rxjs")
50+
external combineLatest: (Observable.t<'a>, Observable.t<'b>) => Observable.t<('a, 'b)> =
51+
"combineLatest"

analysis/tests/src/RxjsCompletion.res

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@@warning("-26")
2+
@@warning("-110")
3+
4+
type keyPress =
5+
| Up(string)
6+
| Down(string)
7+
8+
@val
9+
external window: {..} = "window"
10+
11+
let main = async () => {
12+
let keyMapObservable = {
13+
open Rxjs
14+
15+
let keydown =
16+
fromEvent(Obj.magic(window), "keydown")->pipe2(
17+
map(event => Down(event["key"])),
18+
distinctUntilChanged(),
19+
)
20+
21+
let keyup =
22+
fromEvent(Obj.magic(window), "keyup")->pipe2(
23+
map(event => Up(event["key"])),
24+
distinctUntilChanged(),
25+
)
26+
27+
// merge(keydown, keyup).
28+
// ^com
29+
30+
// Rxjs.Observable.subscribe, Rxjs.pipe and Rxjs.pipe2 should be completed
31+
}
32+
33+
let (a,b) : ( Rxjs.Observable.t<string> , Rxjs.Observable.t<string>) = %todo
34+
35+
// Rxjs.combineLatest(a, b).
36+
// ^com
37+
38+
// Rxjs.Observable.subscribe, Rxjs.pipe and Rxjs.pipe2 should be completed
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Complete src/CompletionMultipleEditorCompleteFrom.res 19:5
2+
posCursor:[19:5] posNoWhite:[19:4] Found expr:[19:3->19:5]
3+
Pexp_field [19:3->19:4] _:[22:0->19:5]
4+
Completable: Cpath Value[a].""
5+
Package opens Pervasives.JsxModules.place holder
6+
Resolved opens 1 pervasives
7+
ContextPath Value[a].""
8+
ContextPath Value[a]
9+
Path a
10+
CPPipe pathFromEnv:A found:true
11+
Path A.
12+
Path B.
13+
[]
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Complete src/CompletionPipeProperty.res 21:17
2+
posCursor:[21:17] posNoWhite:[21:16] Found expr:[21:3->21:17]
3+
Pexp_field [21:3->21:16] _:[23:0->21:17]
4+
Completable: Cpath Value[sprite].anchor.""
5+
Package opens Pervasives.JsxModules.place holder
6+
Resolved opens 1 pervasives
7+
ContextPath Value[sprite].anchor.""
8+
ContextPath Value[sprite].anchor
9+
ContextPath Value[sprite]
10+
Path sprite
11+
CPPipe pathFromEnv:Sprite found:true
12+
Path Sprite.anchor
13+
CPPipe pathFromEnv:ObservablePoint found:true
14+
Path ObservablePoint.
15+
[{
16+
"label": "->ObservablePoint.setBoth",
17+
"kind": 12,
18+
"tags": [],
19+
"detail": "(op, float) => unit",
20+
"documentation": null,
21+
"sortText": "setBoth",
22+
"textEdit": {
23+
"range": {"start": {"line": 21, "character": 16}, "end": {"line": 21, "character": 16}},
24+
"newText": "->ObservablePoint.setBoth"
25+
}
26+
}, {
27+
"label": "->ObservablePoint.set",
28+
"kind": 12,
29+
"tags": [],
30+
"detail": "(op, float, float) => unit",
31+
"documentation": null,
32+
"sortText": "set",
33+
"textEdit": {
34+
"range": {"start": {"line": 21, "character": 16}, "end": {"line": 21, "character": 16}},
35+
"newText": "->ObservablePoint.set"
36+
}
37+
}, {
38+
"label": "x",
39+
"kind": 5,
40+
"tags": [],
41+
"detail": "int",
42+
"documentation": {"kind": "markdown", "value": "```rescript\nx: int\n```\n\n```rescript\ntype op = {mutable x: int, mutable y: int}\n```"}
43+
}, {
44+
"label": "y",
45+
"kind": 5,
46+
"tags": [],
47+
"detail": "int",
48+
"documentation": {"kind": "markdown", "value": "```rescript\ny: int\n```\n\n```rescript\ntype op = {mutable x: int, mutable y: int}\n```"}
49+
}]
50+

analysis/tests/src/expected/Rxjs.res.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Complete src/RxjsCompletion.res 26:29
2+
posCursor:[26:29] posNoWhite:[26:28] Found expr:[10:17->38:1]
3+
posCursor:[26:29] posNoWhite:[26:28] Found expr:[11:2->32:78]
4+
posCursor:[26:29] posNoWhite:[26:28] Found expr:[12:4->26:29]
5+
posCursor:[26:29] posNoWhite:[26:28] Found expr:[14:4->26:29]
6+
posCursor:[26:29] posNoWhite:[26:28] Found expr:[20:4->26:29]
7+
posCursor:[26:29] posNoWhite:[26:28] Found expr:[26:7->26:29]
8+
Pexp_field [26:7->26:28] _:[30:2->26:29]
9+
Completable: Cpath Value[merge](Nolabel, Nolabel).""
10+
Raw opens: 1 Rxjs.place holder
11+
Package opens Pervasives.JsxModules.place holder
12+
Resolved opens 2 pervasives Rxjs.res
13+
ContextPath Value[merge](Nolabel, Nolabel).""
14+
ContextPath Value[merge](Nolabel, Nolabel)
15+
ContextPath Value[merge]
16+
Path merge
17+
CPPipe pathFromEnv:Observable found:true
18+
Path Rxjs.Observable.
19+
Path Rxjs.
20+
[{
21+
"label": "->Observable.subscribe",
22+
"kind": 12,
23+
"tags": [],
24+
"detail": "(t<'t>, 't => unit) => subscription",
25+
"documentation": null,
26+
"sortText": "subscribe",
27+
"textEdit": {
28+
"range": {"start": {"line": 26, "character": 28}, "end": {"line": 26, "character": 28}},
29+
"newText": "->Observable.subscribe"
30+
}
31+
}]
32+
33+
Complete src/RxjsCompletion.res 34:30
34+
posCursor:[34:30] posNoWhite:[34:29] Found expr:[10:17->38:1]
35+
posCursor:[34:30] posNoWhite:[34:29] Found expr:[10:11->38:1]
36+
posCursor:[34:30] posNoWhite:[34:29] Found expr:[11:2->34:30]
37+
posCursor:[34:30] posNoWhite:[34:29] Found expr:[32:2->34:30]
38+
posCursor:[34:30] posNoWhite:[34:29] Found expr:[34:5->34:30]
39+
Pexp_field [34:5->34:29] _:[38:0->34:30]
40+
Completable: Cpath Value[Rxjs, combineLatest](Nolabel, Nolabel).""
41+
Package opens Pervasives.JsxModules.place holder
42+
Resolved opens 1 pervasives
43+
ContextPath Value[Rxjs, combineLatest](Nolabel, Nolabel).""
44+
ContextPath Value[Rxjs, combineLatest](Nolabel, Nolabel)
45+
ContextPath Value[Rxjs, combineLatest]
46+
Path Rxjs.combineLatest
47+
CPPipe pathFromEnv:Observable found:true
48+
Path Rxjs.Observable.
49+
Path Rxjs.
50+
[{
51+
"label": "->Rxjs.Observable.subscribe",
52+
"kind": 12,
53+
"tags": [],
54+
"detail": "(t<'t>, 't => unit) => subscription",
55+
"documentation": null,
56+
"sortText": "subscribe",
57+
"textEdit": {
58+
"range": {"start": {"line": 34, "character": 29}, "end": {"line": 34, "character": 29}},
59+
"newText": "->Rxjs.Observable.subscribe"
60+
}
61+
}]
62+

0 commit comments

Comments
 (0)