Skip to content

Commit

Permalink
Merge pull request #282 from vim-denops/minor-fixes
Browse files Browse the repository at this point in the history
👍 Minor fixes
lambdalisue authored Oct 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 68f607d + 6c023e4 commit e0d0a7a
Showing 11 changed files with 56 additions and 66 deletions.
4 changes: 2 additions & 2 deletions denops/@denops-private/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse } from "https://deno.land/std@0.194.0/flags/mod.ts";
import { parse } from "https://deno.land/std@0.204.0/flags/mod.ts";
import { pop } from "https://deno.land/x/[email protected]/mod.ts";
import { using as usingResource } from "https://deno.land/x/disposable@v1.1.1/mod.ts#^";
import { usingResource } from "https://deno.land/x/disposable@v1.2.0/mod.ts#^";
import { Service } from "./service.ts";
import { Vim } from "./host/vim.ts";
import { Neovim } from "./host/nvim.ts";
2 changes: 1 addition & 1 deletion denops/@denops-private/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { is } from "https://deno.land/x/unknownutil@v3.2.0/mod.ts#^";
import { is } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts#^";

export function errorSerializer(err: unknown): unknown {
if (err instanceof Error) {
2 changes: 1 addition & 1 deletion denops/@denops-private/host/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Disposable } from "https://deno.land/x/disposable@v1.1.1/mod.ts#^";
import type { Disposable } from "https://deno.land/x/disposable@v1.2.0/mod.ts#^";
import { Invoker } from "./invoker.ts";

/**
2 changes: 1 addition & 1 deletion denops/@denops-private/host/invoker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { is } from "https://deno.land/x/unknownutil@v3.2.0/mod.ts#^";
import { is } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts#^";
import { Service } from "../service.ts";
import type { Meta } from "../../@denops/mod.ts";

16 changes: 9 additions & 7 deletions denops/@denops-private/host/nvim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, is } from "https://deno.land/x/unknownutil@v3.2.0/mod.ts#^";
import { assert, is } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts#^";
import {
Client,
Session,
@@ -84,10 +84,8 @@ export class Neovim implements Host {
},

async invoke(method: unknown, args: unknown): Promise<unknown> {
assert(method, isInvokerMethod, {
message: `method '${method}' must be a key of Invoker`,
});
assert(args, is.Array, { message: `args '${args}' must be an array` });
assert(method, isInvokerMethod);
assert(args, is.Array);
// deno-lint-ignore no-explicit-any
return await (invoker[method] as any)(...args);
},
@@ -98,7 +96,11 @@ export class Neovim implements Host {
await this.#session.wait();
}

dispose(): void {
this.#session.shutdown();
async dispose(): Promise<void> {
try {
await this.#session.shutdown();
} catch {
// Do nothing
}
}
}
8 changes: 6 additions & 2 deletions denops/@denops-private/host/vim.ts
Original file line number Diff line number Diff line change
@@ -65,8 +65,12 @@ export class Vim implements Host {
return this.#session.wait();
}

dispose(): void {
this.#session.shutdown();
async dispose(): Promise<void> {
try {
await this.#session.shutdown();
} catch {
// Do nothing
}
}
}

4 changes: 2 additions & 2 deletions denops/@denops-private/impl_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as path from "https://deno.land/std@0.194.0/path/mod.ts";
import * as path from "https://deno.land/std@0.204.0/path/mod.ts";
import {
assertEquals,
assertRejects,
} from "https://deno.land/std@0.194.0/testing/asserts.ts";
} from "https://deno.land/std@0.204.0/assert/mod.ts";
import { test } from "https://deno.land/x/[email protected]/mod.ts#^";
import { BatchError } from "../@denops/mod.ts";

23 changes: 13 additions & 10 deletions denops/@denops-private/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { toFileUrl } from "https://deno.land/std@0.194.0/path/mod.ts";
import { assert, is } from "https://deno.land/x/unknownutil@v3.2.0/mod.ts#^";
import { toFileUrl } from "https://deno.land/std@0.204.0/path/mod.ts";
import { assert, is } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts#^";
import {
Client,
Session,
@@ -8,7 +8,7 @@ import {
readableStreamFromWorker,
writableStreamFromWorker,
} from "https://deno.land/x/[email protected]/mod.ts#^";
import { Disposable } from "https://deno.land/x/disposable@v1.1.1/mod.ts#^";
import { Disposable } from "https://deno.land/x/disposable@v1.2.0/mod.ts#^";
import { Host } from "./host/base.ts";
import { Invoker, RegisterOptions, ReloadOptions } from "./host/invoker.ts";
import { traceReadableStream, traceWritableStream } from "./trace_stream.ts";
@@ -67,8 +67,11 @@ export class Service implements Disposable {
type: "module",
},
);
// Import module with fragment so that reload works properly
// https://github.com/vim-denops/denops.vim/issues/227
const suffix = `#${performance.now()}`;
const scriptUrl = resolveScriptUrl(script);
worker.postMessage({ scriptUrl, meta, trace });
worker.postMessage({ scriptUrl: `${scriptUrl}${suffix}`, meta, trace });
const session = buildServiceSession(
name,
meta,
@@ -121,13 +124,13 @@ export class Service implements Disposable {
}
}

dispose(): void {
// Dispose all sessions
for (const plugin of this.#plugins.values()) {
plugin.session.shutdown();
}
// Terminate all workers
async dispose(): Promise<void> {
for (const plugin of this.#plugins.values()) {
try {
await plugin.session.shutdown();
} catch {
// Do nothing
}
plugin.worker.terminate();
}
}
4 changes: 2 additions & 2 deletions denops/@denops-private/version.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
dirname,
fromFileUrl,
} from "https://deno.land/std@0.197.0/path/mod.ts";
import { parse, SemVer } from "https://deno.land/std@0.197.0/semver/mod.ts";
} from "https://deno.land/std@0.204.0/path/mod.ts";
import { parse, SemVer } from "https://deno.land/std@0.204.0/semver/mod.ts";

const decoder = new TextDecoder();

2 changes: 2 additions & 0 deletions denops/@denops-private/worker/patch_console.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ export function patchConsole(
if (console[marker]) {
return;
}
// Mark
console[marker] = true;
// Patch simple methods
const simpleTargets = [
"debug",
55 changes: 17 additions & 38 deletions denops/@denops-private/worker/script.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { assert, is } from "https://deno.land/x/[email protected]/mod.ts#^";
import {
assert,
is,
Predicate,
} from "https://deno.land/x/[email protected]/mod.ts#^";
import {
Client,
Session,
@@ -15,6 +19,13 @@ import { errorDeserializer, errorSerializer } from "../error.ts";

const worker = self as unknown as Worker & { name: string };

const isMeta: Predicate<Meta> = is.ObjectOf({
mode: is.LiteralOneOf(["release", "debug", "test"] as const),
host: is.LiteralOneOf(["vim", "nvim"] as const),
version: is.String,
platform: is.LiteralOneOf(["windows", "mac", "linux"] as const),
});

async function main(
scriptUrl: string,
meta: Meta,
@@ -66,9 +77,7 @@ async function main(
},
});
try {
// Import module with fragment so that reload works properly
// https://github.com/vim-denops/denops.vim/issues/227
const mod = await import(`${scriptUrl}#${performance.now()}`);
const mod = await import(scriptUrl);
await denops.cmd(
`doautocmd <nomodeline> User DenopsSystemPluginPre:${worker.name}`,
)
@@ -102,45 +111,15 @@ async function main(
self.close();
}

function isMeta(v: unknown): v is Meta {
if (!is.Record(v)) {
return false;
}
if (!is.String(v.mode) || !["release", "debug", "test"].includes(v.mode)) {
return false;
}
if (!is.String(v.host) || !["vim", "nvim"].includes(v.host)) {
return false;
}
if (!is.String(v.version)) {
return false;
}
if (
!is.String(v.platform) || !["windows", "mac", "linux"].includes(v.platform)
) {
return false;
}
return true;
}

// Patch console with worker name for easy debugging
patchConsole(`(${worker.name})`);

// Wait startup arguments and start 'main'
worker.addEventListener("message", (event: MessageEvent<unknown>) => {
assert(event.data, is.Record, {
message: `event.data '${event.data}' must be Record`,
});
assert(event.data.scriptUrl, is.String, {
message: `event.data.scriptUrl '${event.data.scriptUrl}' must be String`,
});
assert(event.data.meta, isMeta, {
message: `event.data.meta '${event.data.meta}' must be Meta`,
});
assert(event.data.trace, is.OneOf([is.Undefined, is.Boolean]), {
message:
`event.data.trace '${event.data.trace}' must be undefined or boolean`,
});
assert(event.data, is.Record);
assert(event.data.scriptUrl, is.String);
assert(event.data.meta, isMeta);
assert(event.data.trace, is.OneOf([is.Undefined, is.Boolean]));
const { scriptUrl, meta, trace } = event.data;
main(scriptUrl, meta, trace ?? false).catch((e) => {
console.error(

0 comments on commit e0d0a7a

Please sign in to comment.