-
-
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.
👍 Add
g:denops#plugin_architecture_model
option
- Loading branch information
1 parent
b5dcab8
commit cdae7e6
Showing
4 changed files
with
30 additions
and
4 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
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,16 +1,19 @@ | ||
import { ensure, is } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { toFileUrl } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import type { Disposable } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import type { Host } from "./host/base.ts"; | ||
import { Invoker } from "./host/invoker.ts"; | ||
import type { Meta } from "../@denops/mod.ts"; | ||
import type { Plugin } from "./plugin/base.ts"; | ||
import { WorkerPlugin } from "./plugin/worker/plugin.ts"; | ||
import { NaivePlugin } from "./plugin/naive/plugin.ts"; | ||
|
||
/** | ||
* Service manage plugins and is visible from the host (Vim/Neovim) through `invoke()` function. | ||
*/ | ||
export class Service implements Disposable { | ||
#plugins: Map<string, Plugin>; | ||
#model: Promise<"worker" | "naive">; | ||
readonly host: Host; | ||
readonly meta: Meta; | ||
|
||
|
@@ -19,22 +22,31 @@ export class Service implements Disposable { | |
this.host = host; | ||
this.host.register(new Invoker(this)); | ||
this.meta = meta; | ||
this.#model = this.host.call("eval", "g:denops#plugin_architecture_model") | ||
.then((m) => ensure(m, is.LiteralOneOf(["worker", "naive"] as const))); | ||
} | ||
|
||
register( | ||
async register( | ||
name: string, | ||
script: string, | ||
): void { | ||
): Promise<void> { | ||
const model = await this.#model; | ||
const plugin = this.#plugins.get(name); | ||
if (plugin) { | ||
if (this.meta.mode === "debug") { | ||
console.log(`A denops plugin '${name}' is already registered. Skip`); | ||
} | ||
return; | ||
} | ||
const PluginCls = model === "worker" ? WorkerPlugin : NaivePlugin; | ||
if (this.meta.mode === "debug") { | ||
console.log( | ||
`Register a denops plugin '${name}' with '${PluginCls.name}' model`, | ||
); | ||
} | ||
this.#plugins.set( | ||
name, | ||
new WorkerPlugin(name, resolveScriptUrl(script), this), | ||
new PluginCls(name, resolveScriptUrl(script), this), | ||
); | ||
} | ||
|
||
|
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