-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from vim-denops/stream
👍 Use Streams API instead
- Loading branch information
Showing
11 changed files
with
65 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
deno.lock | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"lock": false, | ||
"tasks": { | ||
"test": "deno test --no-lock --unstable -A --doc --parallel --shuffle", | ||
"check": "deno check --no-lock --unstable $(find . -name '*.ts')", | ||
"upgrade": "deno run --no-lock -A https://deno.land/x/udd/main.ts $(find . -name '*.ts')" | ||
"test": "deno test --unstable -A --doc --parallel --shuffle --coverage=.coverage", | ||
"check": "deno check --unstable $(find . -name '*.ts')", | ||
"coverage": "deno coverage --unstable .coverage", | ||
"upgrade": "deno run -A https://deno.land/x/udd/main.ts $(find . -name '*.ts')" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
import { copy } from "https://deno.land/[email protected]/streams/copy.ts"; | ||
import { | ||
WorkerReader, | ||
WorkerWriter, | ||
} from "https://deno.land/x/workerio@v1.4.4/mod.ts#^"; | ||
readableStreamFromWorker, | ||
writableStreamFromWorker, | ||
} from "https://deno.land/x/workerio@v3.1.0/mod.ts#^"; | ||
import { orElse } from "./or_else.ts"; | ||
|
||
const worker = self as unknown as Worker; | ||
const reader = new WorkerReader(worker); | ||
const writer = new WorkerWriter(worker); | ||
const reader = readableStreamFromWorker(worker); | ||
const writer = writableStreamFromWorker(worker); | ||
|
||
const addr = JSON.parse(orElse(Deno.env.get("DENOPS_TEST_ADDRESS"), () => { | ||
throw new Error("Environment variable `DENOPS_TEST_ADDRESS` is required"); | ||
})); | ||
const conn = await Deno.connect(addr); | ||
|
||
await Promise.race([ | ||
copy(conn, writer).finally(() => conn.close()), | ||
copy(reader, conn), | ||
reader.pipeTo(conn.writable), | ||
conn.readable.pipeTo(writer), | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { sample } from "https://deno.land/std@0.186.0/collections/sample.ts"; | ||
import { sample } from "https://deno.land/std@0.187.0/collections/sample.ts"; | ||
import type { Denops } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import type { RunMode } from "./runner.ts"; | ||
import { withDenops } from "./with.ts"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { Session } from "https://deno.land/x/[email protected]/mod.ts#^"; | ||
import { using } from "https://deno.land/x/[email protected]/mod.ts#^"; | ||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { | ||
Client, | ||
Session, | ||
} from "https://deno.land/x/[email protected]/mod.ts#^"; | ||
import type { | ||
Denops, | ||
Meta, | ||
|
@@ -78,39 +80,37 @@ export async function withDenops( | |
}); | ||
const conn = await listener.accept(); | ||
try { | ||
await using( | ||
new Session(conn, conn, {}, { | ||
errorCallback(e) { | ||
if (e.name === "Interrupted") { | ||
return; | ||
} | ||
console.error("Unexpected error occurred", e); | ||
}, | ||
}), | ||
async (session) => { | ||
const meta = await session.call( | ||
"call", | ||
"denops#_internal#meta#get", | ||
) as Meta; | ||
const denops = await newDenopsImpl(meta, session, pluginName); | ||
// Workaround for unexpected "leaking async ops" | ||
// https://github.com/denoland/deno/issues/15425#issuecomment-1368245954 | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
await main(denops); | ||
}, | ||
); | ||
const session = new Session(conn.readable, conn.writable); | ||
session.onInvalidMessage = (message) => { | ||
console.error("Unexpected message:", message); | ||
}; | ||
session.onMessageError = (error, message) => { | ||
console.error(`Unexpected error occured for message ${message}:`, error); | ||
}; | ||
session.start(); | ||
const client = new Client(session); | ||
const meta = await client.call( | ||
"call", | ||
"denops#_internal#meta#get", | ||
) as Meta; | ||
const denops = await newDenopsImpl(meta, session, client, pluginName); | ||
// Workaround for unexpected "leaking async ops" | ||
// https://github.com/denoland/deno/issues/15425#issuecomment-1368245954 | ||
await new Promise((resolve) => setTimeout(resolve, 0)); | ||
await main(denops); | ||
await session.shutdown(); | ||
} finally { | ||
proc.stdin.close(); | ||
proc.kill(); | ||
await proc.status; | ||
conn.close(); | ||
listener.close(); | ||
} | ||
} | ||
|
||
async function newDenopsImpl( | ||
meta: Meta, | ||
session: Session, | ||
client: Client, | ||
pluginName: string, | ||
): Promise<Denops> { | ||
const url = path.toFileUrl(path.join( | ||
|
@@ -120,5 +120,19 @@ async function newDenopsImpl( | |
"impl.ts", | ||
)); | ||
const { DenopsImpl } = await import(url.href); | ||
return new DenopsImpl(pluginName, meta, session); | ||
return new DenopsImpl(pluginName, meta, { | ||
get dispatcher() { | ||
return session.dispatcher; | ||
}, | ||
set dispatcher(dispatcher) { | ||
session.dispatcher = dispatcher; | ||
}, | ||
call(method: string, ...params: unknown[]): Promise<unknown> { | ||
return client.call(method, ...params); | ||
}, | ||
notify(method: string, ...params: unknown[]): Promise<void> { | ||
client.notify(method, ...params); | ||
return Promise.resolve(); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters