-
Notifications
You must be signed in to change notification settings - Fork 2
/
denops.ts
54 lines (44 loc) · 1.37 KB
/
denops.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type {
Context,
Denops,
Dispatcher,
Meta,
} from "jsr:@denops/core@^7.0.0";
import type { Client } from "jsr:@lambdalisue/messagepack-rpc@^2.1.1";
export class DenopsImpl implements Denops {
readonly name: string;
readonly meta: Meta;
readonly context: Record<string | number | symbol, unknown> = {};
readonly interrupted = AbortSignal.any([]);
dispatcher: Dispatcher = {};
#client: Client;
constructor(
name: string,
meta: Meta,
client: Client,
) {
this.name = name;
this.meta = meta;
this.#client = client;
}
redraw(force?: boolean): Promise<void> {
return this.#client.call("invoke", "redraw", [force]) as Promise<void>;
}
call(fn: string, ...args: unknown[]): Promise<unknown> {
return this.#client.call("invoke", "call", [fn, ...args]);
}
batch(
...calls: [string, ...unknown[]][]
): Promise<unknown[]> {
return this.#client.call("invoke", "batch", calls) as Promise<unknown[]>;
}
cmd(cmd: string, ctx: Context = {}): Promise<void> {
return this.#client.call("invoke", "cmd", [cmd, ctx]) as Promise<void>;
}
eval(expr: string, ctx: Context = {}): Promise<unknown> {
return this.#client.call("invoke", "eval", [expr, ctx]);
}
dispatch(name: string, fn: string, ...args: unknown[]): Promise<unknown> {
return this.#client.call("invoke", "dispatch", [name, fn, ...args]);
}
}