Skip to content

Commit

Permalink
⚡ Asyncronous output stdout.
Browse files Browse the repository at this point in the history
  • Loading branch information
yukimemi committed Mar 15, 2021
1 parent 32d0f66 commit e5deef4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions denops/asyngrep/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import "https://deno.land/x/lodash@4.17.19/dist/lodash.js";
import * as path from "https://deno.land/std@0.90.0/path/mod.ts";
import { exists } from "https://deno.land/std@0.90.0/fs/mod.ts";
import { isWindows } from "https://deno.land/std@0.90.0/_util/os.ts";
import { parse } from "https://deno.land/std@0.90.0/encoding/toml.ts";
import { parse as flags } from "https://deno.land/std@0.90.0/flags/mod.ts";
import { parse } from "https://deno.land/std@0.90.0/encoding/toml.ts";
import { readLines } from "https://deno.land/std@0.90.0/io/mod.ts";
import { start } from "https://deno.land/x/denops_std@v0.3/mod.ts";
const _ = (self as any)._;

Expand Down Expand Up @@ -87,7 +88,19 @@ start(async (vim) => {
const cmd = [tool.cmd, ...toolArg, pattern] as string[];
const cwd = (await vim.call("getcwd")) as string;
clog({ cmd, cwd });
const p = Deno.run({ cmd, cwd, stderr: "piped", stdout: "piped" });
const p = Deno.run({ cmd, cwd, stdout: "piped", stderr: "piped" });

await vim.call("setqflist", [], "r");
await vim.call("setqflist", [], "a", {
title: `[Search results for ${pattern}]`,
});
await vim.execute("botright copen");

for await (const line of readLines(p.stdout)) {
clog({ line });
await vim.call("setqflist", [], "a", { lines: [line] });
}

const [status, stdoutArray, stderrArray] = await Promise.all([
p.status(),
p.output(),
Expand All @@ -98,12 +111,6 @@ start(async (vim) => {
p.close();

clog({ status, stdout, stderr });
await vim.call("setqflist", [], "r");
await vim.call("setqflist", [], "a", {
title: `[Search results for ${pattern}]`,
});
await vim.call("setqflist", [], "a", { lines: stdout.split("\n") });
await vim.execute("botright copen");
return await Promise.resolve();
},
});
Expand Down

0 comments on commit e5deef4

Please sign in to comment.