diff --git a/autoload/denops.vim b/autoload/denops.vim index 160bfcd5..280aedc5 100644 --- a/autoload/denops.vim +++ b/autoload/denops.vim @@ -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 diff --git a/denops/@denops-private/host/invoker.ts b/denops/@denops-private/host/invoker.ts index 505c26d3..329d8b19 100644 --- a/denops/@denops-private/host/invoker.ts +++ b/denops/@denops-private/host/invoker.ts @@ -8,7 +8,7 @@ export class Invoker { this.#service = service; } - register(name: string, script: string): void { + register(name: string, script: string): Promise { return this.#service.register(name, script); } diff --git a/denops/@denops-private/service.ts b/denops/@denops-private/service.ts index d4adb9d7..67b23eb7 100644 --- a/denops/@denops-private/service.ts +++ b/denops/@denops-private/service.ts @@ -1,3 +1,4 @@ +import { ensure, is } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts"; import { toFileUrl } from "https://deno.land/std@0.208.0/path/mod.ts"; import type { Disposable } from "https://deno.land/x/disposable@v1.2.0/mod.ts"; import type { Host } from "./host/base.ts"; @@ -5,12 +6,14 @@ 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; + #model: Promise<"worker" | "naive">; readonly host: Host; readonly meta: Meta; @@ -19,12 +22,15 @@ 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 { + const model = await this.#model; const plugin = this.#plugins.get(name); if (plugin) { if (this.meta.mode === "debug") { @@ -32,9 +38,15 @@ export class Service implements Disposable { } 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), ); } diff --git a/doc/denops.txt b/doc/denops.txt index fc100906..31948f08 100644 --- a/doc/denops.txt +++ b/doc/denops.txt @@ -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.