Skip to content

Commit

Permalink
👍 Add g:denops#plugin_architecture_model option
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Nov 26, 2023
1 parent b5dcab8 commit cdae7e6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions autoload/denops.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ endfunction
call denops#_internal#conf#define('denops#disabled', 0)
call denops#_internal#conf#define('denops#deno', 'deno')
call denops#_internal#conf#define('denops#debug', 0)
call denops#_internal#conf#define('denops#plugin_architecture_model', 'worker')
call denops#_internal#conf#define('denops#disable_deprecation_warning_message', 0)

" Internal configuration
Expand Down
2 changes: 1 addition & 1 deletion denops/@denops-private/host/invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Invoker {
this.#service = service;
}

register(name: string, script: string): void {
register(name: string, script: string): Promise<void> {
return this.#service.register(name, script);
}

Expand Down
18 changes: 15 additions & 3 deletions denops/@denops-private/service.ts
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;

Expand All @@ -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),
);
}

Expand Down
13 changes: 13 additions & 0 deletions doc/denops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ VARIABLE *denops-variable*

Default: 0

*g:denops#plugin_architecture_model*
The name of internal plugin architecture model. One of the followings
are available.

"worker" Isolate each plugins in each worker process. This is
the default model.

"naive" Directly import each plugins in the main process. This
may improve performance of plugin loading. It is an
experimental feature and may cause unexpected errors.

Default: "worker"

*g:denops#disable_deprecation_warning_message*
Set 1 to disable deprecation warning messages.

Expand Down

0 comments on commit cdae7e6

Please sign in to comment.