Skip to content

Commit 656512f

Browse files
committed
Add documentation of public interfaces
1 parent 7a9e0e8 commit 656512f

File tree

2 files changed

+70
-16
lines changed

2 files changed

+70
-16
lines changed

vim/execute.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { Context, Denops } from "../deps.ts";
55
*/
66
export async function execute(
77
denops: Denops,
8-
command: string | string[],
9-
context: Context = {},
8+
script: string | string[],
9+
ctx: Context = {},
1010
): Promise<void> {
11-
if (Array.isArray(command)) {
12-
context = {
13-
...context,
14-
__denops_internal_command: command
11+
if (Array.isArray(script)) {
12+
ctx = {
13+
...ctx,
14+
__denops_internal_command: script
1515
.map((x) => x.replace(/^\s+|\s+$/g, ""))
1616
.filter((x) => !!x),
1717
};
18-
await denops.cmd("call execute(l:__denops_internal_command, '')", context);
18+
await denops.cmd("call execute(l:__denops_internal_command, '')", ctx);
1919
return;
2020
}
21-
command = command.replace(/\r?\n\s*\\/g, "");
22-
await execute(denops, command.split(/\r?\n/g), context);
21+
script = script.replace(/\r?\n\s*\\/g, "");
22+
await execute(denops, script.split(/\r?\n/g), ctx);
2323
}

vim/vim.ts

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { autocmd, AutocmdHelper } from "./autocmd.ts";
44
import { VariableHelper } from "./variable.ts";
55
import { load } from "./load.ts";
66

7+
/**
8+
* Vim is a facade instance visible from each denops plugins for
9+
*
10+
* 1. Communicate with other plugins
11+
* 2. Communicate with the host (Vim/Neovim)
12+
* 3. Register them msgpack-rpc APIs
13+
*
14+
*/
715
export class Vim {
816
private static instance?: Vim;
917

@@ -24,47 +32,93 @@ export class Vim {
2432
this.v = new VariableHelper(denops, "v");
2533
}
2634

35+
/**
36+
* Get thread-local Vim instance.
37+
*/
2738
static get(): Vim {
2839
if (!Vim.instance) {
2940
Vim.instance = new Vim(Denops.get());
3041
}
3142
return Vim.instance;
3243
}
3344

45+
/**
46+
* Plugin name
47+
*/
3448
get name(): string {
3549
return this.#denops.name;
3650
}
3751

52+
/**
53+
* Call an arbitrary function of Vim/Neovim and return the result
54+
*
55+
* @param fn: A function name of Vim/Neovim.
56+
* @param args: Arguments of the function.
57+
*/
3858
async call(func: string, ...args: unknown[]): Promise<unknown> {
3959
return await this.#denops.call(func, ...args);
4060
}
4161

42-
async cmd(cmd: string, context: Context = {}): Promise<void> {
43-
await this.#denops.cmd(cmd, context);
62+
/**
63+
* Execute an arbitrary command of Vim/Neovim under a given context.
64+
*
65+
* @param cmd: A command expression to be executed.
66+
* @param ctx: A context object which is expanded to the local namespace (l:)
67+
*/
68+
async cmd(cmd: string, ctx: Context = {}): Promise<void> {
69+
await this.#denops.cmd(cmd, ctx);
4470
}
4571

46-
async eval(expr: string, context: Context = {}): Promise<unknown> {
47-
return await this.#denops.eval(expr, context);
72+
/**
73+
* Evaluate an arbitrary expression of Vim/Neovim under a given context and return the result.
74+
*
75+
* @param expr: An expression to be evaluated.
76+
* @param ctx: A context object which is expanded to the local namespace (l:)
77+
*/
78+
async eval(expr: string, ctx: Context = {}): Promise<unknown> {
79+
return await this.#denops.eval(expr, ctx);
4880
}
4981

82+
/**
83+
* Execute an arbitrary Vim script under a given context.
84+
*
85+
* @param script: A script to be executed. Can be string or string list.
86+
* @param ctx: A context object which is expanded to the local namespace (l:)
87+
*/
5088
async execute(
51-
command: string | string[],
52-
context: Context = {},
89+
script: string | string[],
90+
ctx: Context = {},
5391
): Promise<void> {
54-
await execute(this.#denops, command, context);
92+
await execute(this.#denops, script, ctx);
5593
}
5694

95+
/**
96+
* Define autocmd in autocmd group.
97+
*
98+
* @param group: An autocmd group name.
99+
* @param main: A function which is used to define autocmds.
100+
*/
57101
async autocmd(
58102
group: string,
59103
main: (helper: AutocmdHelper) => void,
60104
): Promise<void> {
61105
await autocmd(this.#denops, group, main);
62106
}
63107

108+
/**
109+
* Load an arbitrary Vim script from local or remote.
110+
*
111+
* @param url: An URL to locate the target Vim script.
112+
*/
64113
async load(url: URL): Promise<void> {
65114
await load(this.#denops, url);
66115
}
67116

117+
/**
118+
* Register plugin APIs
119+
*
120+
* @param dispatcher: A collection of the plugin APIs
121+
*/
68122
register(dispatcher: Dispatcher): void {
69123
this.#denops.extendDispatcher(dispatcher);
70124
}

0 commit comments

Comments
 (0)