diff --git a/README.md b/README.md index 3bbcd080..0592eeeb 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,7 @@ It's heavily inspired from [ddskk](https://github.com/skk-dev/ddskk) and # Documentation -See -[doc](https://github.com/vim-skk/skkeleton/tree/main/doc/skkeleton.jax) +See [doc](https://github.com/vim-skk/skkeleton/tree/main/doc/skkeleton.jax) # Requirements diff --git a/denops/skkeleton/deps/std/streams.ts b/denops/skkeleton/deps/std/streams.ts index a38102eb..b1d28fe4 100644 --- a/denops/skkeleton/deps/std/streams.ts +++ b/denops/skkeleton/deps/std/streams.ts @@ -1 +1 @@ -export { iterateReader } from "https://deno.land/std@0.208.0/streams/mod.ts"; +export { TextLineStream } from "https://deno.land/std@0.208.0/streams/mod.ts"; diff --git a/denops/skkeleton/jisyo.ts b/denops/skkeleton/jisyo.ts index eeb93994..faa66b28 100644 --- a/denops/skkeleton/jisyo.ts +++ b/denops/skkeleton/jisyo.ts @@ -5,7 +5,7 @@ import { wrap } from "./deps/iterator_helpers.ts"; import { JpNum } from "./deps/japanese_numeral.ts"; import { RomanNum } from "./deps/roman.ts"; import { zip } from "./deps/std/collections.ts"; -import { iterateReader } from "./deps/std/streams.ts"; +import { TextLineStream } from "./deps/std/streams.ts"; import { assert, is } from "./deps/unknownutil.ts"; import { Encode } from "./types.ts"; import { jisyoschema, jsonschema, msgpack, yaml } from "./deps/jisyo.ts"; @@ -524,6 +524,25 @@ function decode(str: Uint8Array, encode: Encoding): string { return decoder.decode(str); } +async function* iterLine( + r: ReadableStream, + encoding: string, +): AsyncIterable { + const lines = r + .pipeThrough(new TextDecoderStream(encoding), { + preventAbort: true, + preventCancel: true, + preventClose: true, + }) + .pipeThrough(new TextLineStream()); + + for await (const line of lines) { + if ((line as string).length) { + yield line as string; + } + } +} + export class SkkServer implements Dictionary { #conn: Deno.Conn | undefined; responseEncoding: Encoding; @@ -545,8 +564,9 @@ export class SkkServer implements Dictionary { await this.#conn.write(encode(`1${word} `, this.requestEncoding)); const result: string[] = []; - for await (const res of iterateReader(this.#conn)) { - const str = decode(res, this.responseEncoding); + for await ( + const str of iterLine(this.#conn.readable, this.responseEncoding) + ) { result.push(...(str.at(0) === "4") ? [] : str.split("/").slice(1, -1)); if (str.endsWith("\n")) { @@ -590,8 +610,9 @@ export class SkkServer implements Dictionary { await this.#conn.write(encode(`4${prefix} `, this.requestEncoding)); const midashis: string[] = []; - for await (const res of iterateReader(this.#conn)) { - const str = decode(res, this.responseEncoding); + for await ( + const str of iterLine(this.#conn.readable, this.responseEncoding) + ) { midashis.push(...(str.at(0) === "4") ? [] : str.split("/").slice(1, -1)); if (str.endsWith("\n")) {