Skip to content
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

Additional completion tests #1062

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
22 changes: 22 additions & 0 deletions analysis/tests/src/CompletionMultipleEditorCompleteFrom.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@@warning("-26")
@@warning("-27")
@@warning("-110")

module A = {
@editor.completeFrom(B) @editor.completeFrom(C)
type a
}

module B = {
let b = (a: A.a) => 1
}

module C = {
open A
let c = (a: a) => {'c'}
}

let a : A.a = %todo
// a.
// ^com
// B.b and C.c should be completed
23 changes: 23 additions & 0 deletions analysis/tests/src/CompletionPipeProperty.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module ObservablePoint = {
type op = {
mutable x: int,
mutable y: int,
}

@send
external setBoth: (op, float) => unit = "set"

@send
external set: (op, float, float) => unit = "set"
}

module Sprite = {
type s = {
anchor: ObservablePoint.op,
}
}

let sprite : Sprite.s = %todo

// sprite.anchor.
// ^com
51 changes: 51 additions & 0 deletions analysis/tests/src/Rxjs.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// These are bindings used in RxjsCompletion.res
// We are using a separate file to test complication for modules of external files.
type target

module Subscriber = {
type t<'t> = {next: 't => unit}
}

module Observable = {
// Complete items defined inside the parent module.
@editor.completeFrom(Rxjs)
type t<'t>

type dispose = unit => unit

@new @module("rxjs")
external make: (Subscriber.t<'t> => dispose) => t<'t> = "Observable"

type subscription

@send
external subscribe: (t<'t>, 't => unit) => subscription = "subscribe"
}

@module("rxjs")
external fromEvent: (target, string) => Observable.t<'t> = "fromEvent"

type operation<'t, 'u>

@send
external pipe: (Observable.t<'t>, operation<'t, 'u>) => Observable.t<'u> = "pipe"

@send
external pipe2: (Observable.t<'t>, operation<'t, 'u>, operation<'u, 'i>) => Observable.t<'i> =
"pipe"

@module("rxjs")
external map: ('t => 'u) => operation<'t, 'u> = "map"

@module("rxjs")
external distinctUntilChanged: unit => operation<'t, 't> = "distinctUntilChanged"

@module("rxjs")
external merge: (Observable.t<'t>, Observable.t<'t>) => Observable.t<'t> = "merge"

@module("rxjs")
external scan: (('acc, 't) => 'acc, 'acc) => operation<'t, 'acc> = "scan"

@module("rxjs")
external combineLatest: (Observable.t<'a>, Observable.t<'b>) => Observable.t<('a, 'b)> =
"combineLatest"
39 changes: 39 additions & 0 deletions analysis/tests/src/RxjsCompletion.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@@warning("-26")
@@warning("-110")

type keyPress =
| Up(string)
| Down(string)

@val
external window: {..} = "window"

let main = async () => {
let keyMapObservable = {
open Rxjs

let keydown =
fromEvent(Obj.magic(window), "keydown")->pipe2(
map(event => Down(event["key"])),
distinctUntilChanged(),
)

let keyup =
fromEvent(Obj.magic(window), "keyup")->pipe2(
map(event => Up(event["key"])),
distinctUntilChanged(),
)

// merge(keydown, keyup).
// ^com

// Rxjs.Observable.subscribe, Rxjs.pipe and Rxjs.pipe2 should be completed
}

let (a,b) : ( Rxjs.Observable.t<string> , Rxjs.Observable.t<string>) = %todo

// Rxjs.combineLatest(a, b).
// ^com

// Rxjs.Observable.subscribe, Rxjs.pipe and Rxjs.pipe2 should be completed
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Complete src/CompletionMultipleEditorCompleteFrom.res 19:5
posCursor:[19:5] posNoWhite:[19:4] Found expr:[19:3->19:5]
Pexp_field [19:3->19:4] _:[22:0->19:5]
Completable: Cpath Value[a].""
Package opens Pervasives.JsxModules.place holder
Resolved opens 1 pervasives
ContextPath Value[a].""
ContextPath Value[a]
Path a
CPPipe pathFromEnv:A found:true
Path A.
Path B.
[]

50 changes: 50 additions & 0 deletions analysis/tests/src/expected/CompletionPipeProperty.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Complete src/CompletionPipeProperty.res 21:17
posCursor:[21:17] posNoWhite:[21:16] Found expr:[21:3->21:17]
Pexp_field [21:3->21:16] _:[23:0->21:17]
Completable: Cpath Value[sprite].anchor.""
Package opens Pervasives.JsxModules.place holder
Resolved opens 1 pervasives
ContextPath Value[sprite].anchor.""
ContextPath Value[sprite].anchor
ContextPath Value[sprite]
Path sprite
CPPipe pathFromEnv:Sprite found:true
Path Sprite.anchor
CPPipe pathFromEnv:ObservablePoint found:true
Path ObservablePoint.
[{
"label": "->ObservablePoint.setBoth",
"kind": 12,
"tags": [],
"detail": "(op, float) => unit",
"documentation": null,
"sortText": "setBoth",
"textEdit": {
"range": {"start": {"line": 21, "character": 16}, "end": {"line": 21, "character": 16}},
"newText": "->ObservablePoint.setBoth"
}
}, {
"label": "->ObservablePoint.set",
"kind": 12,
"tags": [],
"detail": "(op, float, float) => unit",
"documentation": null,
"sortText": "set",
"textEdit": {
"range": {"start": {"line": 21, "character": 16}, "end": {"line": 21, "character": 16}},
"newText": "->ObservablePoint.set"
}
}, {
"label": "x",
"kind": 5,
"tags": [],
"detail": "int",
"documentation": {"kind": "markdown", "value": "```rescript\nx: int\n```\n\n```rescript\ntype op = {mutable x: int, mutable y: int}\n```"}
}, {
"label": "y",
"kind": 5,
"tags": [],
"detail": "int",
"documentation": {"kind": "markdown", "value": "```rescript\ny: int\n```\n\n```rescript\ntype op = {mutable x: int, mutable y: int}\n```"}
}]

Empty file.
62 changes: 62 additions & 0 deletions analysis/tests/src/expected/RxjsCompletion.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Complete src/RxjsCompletion.res 26:29
posCursor:[26:29] posNoWhite:[26:28] Found expr:[10:17->38:1]
posCursor:[26:29] posNoWhite:[26:28] Found expr:[11:2->32:78]
posCursor:[26:29] posNoWhite:[26:28] Found expr:[12:4->26:29]
posCursor:[26:29] posNoWhite:[26:28] Found expr:[14:4->26:29]
posCursor:[26:29] posNoWhite:[26:28] Found expr:[20:4->26:29]
posCursor:[26:29] posNoWhite:[26:28] Found expr:[26:7->26:29]
Pexp_field [26:7->26:28] _:[30:2->26:29]
Completable: Cpath Value[merge](Nolabel, Nolabel).""
Raw opens: 1 Rxjs.place holder
Package opens Pervasives.JsxModules.place holder
Resolved opens 2 pervasives Rxjs.res
ContextPath Value[merge](Nolabel, Nolabel).""
ContextPath Value[merge](Nolabel, Nolabel)
ContextPath Value[merge]
Path merge
CPPipe pathFromEnv:Observable found:true
Path Rxjs.Observable.
Path Rxjs.
[{
"label": "->Observable.subscribe",
"kind": 12,
"tags": [],
"detail": "(t<'t>, 't => unit) => subscription",
"documentation": null,
"sortText": "subscribe",
"textEdit": {
"range": {"start": {"line": 26, "character": 28}, "end": {"line": 26, "character": 28}},
"newText": "->Observable.subscribe"
}
}]

Complete src/RxjsCompletion.res 34:30
posCursor:[34:30] posNoWhite:[34:29] Found expr:[10:17->38:1]
posCursor:[34:30] posNoWhite:[34:29] Found expr:[10:11->38:1]
posCursor:[34:30] posNoWhite:[34:29] Found expr:[11:2->34:30]
posCursor:[34:30] posNoWhite:[34:29] Found expr:[32:2->34:30]
posCursor:[34:30] posNoWhite:[34:29] Found expr:[34:5->34:30]
Pexp_field [34:5->34:29] _:[38:0->34:30]
Completable: Cpath Value[Rxjs, combineLatest](Nolabel, Nolabel).""
Package opens Pervasives.JsxModules.place holder
Resolved opens 1 pervasives
ContextPath Value[Rxjs, combineLatest](Nolabel, Nolabel).""
ContextPath Value[Rxjs, combineLatest](Nolabel, Nolabel)
ContextPath Value[Rxjs, combineLatest]
Path Rxjs.combineLatest
CPPipe pathFromEnv:Observable found:true
Path Rxjs.Observable.
Path Rxjs.
[{
"label": "->Rxjs.Observable.subscribe",
"kind": 12,
"tags": [],
"detail": "(t<'t>, 't => unit) => subscription",
"documentation": null,
"sortText": "subscribe",
"textEdit": {
"range": {"start": {"line": 34, "character": 29}, "end": {"line": 34, "character": 29}},
"newText": "->Rxjs.Observable.subscribe"
}
}]