- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 36
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 #282 from vim-denops/minor-fixes
👍 Minor fixes
Showing
11 changed files
with
56 additions
and
66 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
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"; | ||
|
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
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,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"; | ||
|
||
|
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,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(); | ||
} | ||
} | ||
|
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,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( | ||
|