-
-
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.
- Loading branch information
1 parent
1b755c7
commit f677826
Showing
3 changed files
with
20 additions
and
24 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,9 +1,11 @@ | ||
import { ensure } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { parseArgs } from "https://deno.land/[email protected]/cli/mod.ts"; | ||
import { pop } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { usingResource } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { Service } from "./service.ts"; | ||
import { Vim } from "./host/vim.ts"; | ||
import { Neovim } from "./host/nvim.ts"; | ||
import { isMeta } from "./util.ts"; | ||
|
||
type Host = typeof Vim | typeof Neovim; | ||
|
||
|
@@ -39,7 +41,8 @@ async function handleConn(conn: Deno.Conn): Promise<void> { | |
|
||
// Create host and service | ||
await usingResource(new hostClass(r2, writer), async (host) => { | ||
await usingResource(new Service(host), async (_service) => { | ||
const meta = ensure(await host.call("denops#_internal#meta#get"), isMeta); | ||
await usingResource(new Service(host, meta), async (_service) => { | ||
await host.call("execute", "doautocmd <nomodeline> User DenopsReady"); | ||
await host.waitClosed(); | ||
if (!quiet) { | ||
|
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,9 +1,5 @@ | ||
import { toFileUrl } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { | ||
assert, | ||
ensure, | ||
is, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { assert, is } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { | ||
Client, | ||
Session, | ||
|
@@ -17,7 +13,6 @@ import type { Host } from "./host/base.ts"; | |
import { Invoker } from "./host/invoker.ts"; | ||
import { errorDeserializer, errorSerializer } from "./error.ts"; | ||
import type { Meta } from "../@denops/mod.ts"; | ||
import { isMeta } from "./util.ts"; | ||
|
||
const workerScript = "./worker/script.ts"; | ||
|
||
|
@@ -33,26 +28,23 @@ type Plugin = { | |
*/ | ||
export class Service implements Disposable { | ||
#plugins: Map<string, Plugin>; | ||
host: Host; | ||
meta: Promise<Meta>; | ||
readonly host: Host; | ||
readonly meta: Meta; | ||
|
||
constructor(host: Host) { | ||
constructor(host: Host, meta: Meta) { | ||
this.#plugins = new Map(); | ||
this.host = host; | ||
this.host.register(new Invoker(this)); | ||
this.meta = host.call("denops#_internal#meta#get").then((m) => | ||
ensure(m, isMeta) | ||
); | ||
this.meta = meta; | ||
} | ||
|
||
async register( | ||
register( | ||
name: string, | ||
script: string, | ||
): Promise<void> { | ||
const meta = await this.meta; | ||
): void { | ||
const plugin = this.#plugins.get(name); | ||
if (plugin) { | ||
if (meta.mode === "debug") { | ||
if (this.meta.mode === "debug") { | ||
console.log(`A denops plugin '${name}' is already registered. Skip`); | ||
} | ||
return; | ||
|
@@ -68,7 +60,7 @@ export class Service implements Disposable { | |
// https://github.com/vim-denops/denops.vim/issues/227 | ||
const suffix = `#${performance.now()}`; | ||
const scriptUrl = resolveScriptUrl(script); | ||
worker.postMessage({ scriptUrl: `${scriptUrl}${suffix}`, meta }); | ||
worker.postMessage({ scriptUrl: `${scriptUrl}${suffix}`, meta: this.meta }); | ||
const session = buildServiceSession( | ||
name, | ||
readableStreamFromWorker(worker), | ||
|
@@ -83,16 +75,17 @@ export class Service implements Disposable { | |
}); | ||
} | ||
|
||
async reload(name: string): Promise<void> { | ||
const meta = await this.meta; | ||
reload(name: string): void { | ||
const plugin = this.#plugins.get(name); | ||
if (!plugin) { | ||
if (meta.mode === "debug") { | ||
if (this.meta.mode === "debug") { | ||
console.log(`A denops plugin '${name}' is not registered yet. Skip`); | ||
} | ||
return; | ||
} | ||
await disposePlugin(plugin); | ||
disposePlugin(plugin).catch(() => { | ||
// Do nothing | ||
}); | ||
this.#plugins.delete(name); | ||
this.register(name, plugin.script); | ||
} | ||
|