|
| 1 | +import { Context, Denops, Dispatcher } from "./deps.ts"; |
| 2 | +import { execute } from "./execute.ts"; |
| 3 | +import { autocmd, AutocmdHelper } from "./autocmd.ts"; |
| 4 | +import { VariableHelper } from "./variable.ts"; |
| 5 | + |
| 6 | +export class Vim { |
| 7 | + #denops: Denops; |
| 8 | + |
| 9 | + readonly g: VariableHelper; |
| 10 | + readonly b: VariableHelper; |
| 11 | + readonly w: VariableHelper; |
| 12 | + readonly t: VariableHelper; |
| 13 | + readonly v: VariableHelper; |
| 14 | + readonly env: VariableHelper; |
| 15 | + |
| 16 | + constructor(denops: Denops) { |
| 17 | + this.#denops = denops; |
| 18 | + this.g = new VariableHelper(denops, "g"); |
| 19 | + this.b = new VariableHelper(denops, "b"); |
| 20 | + this.w = new VariableHelper(denops, "w"); |
| 21 | + this.t = new VariableHelper(denops, "t"); |
| 22 | + this.v = new VariableHelper(denops, "v"); |
| 23 | + this.env = new VariableHelper(denops, "env"); |
| 24 | + } |
| 25 | + |
| 26 | + get name(): string { |
| 27 | + return this.#denops.name; |
| 28 | + } |
| 29 | + |
| 30 | + async call(func: string, ...args: unknown[]): Promise<unknown> { |
| 31 | + return await this.#denops.call(func, ...args); |
| 32 | + } |
| 33 | + |
| 34 | + async cmd(cmd: string, context: Context = {}): Promise<void> { |
| 35 | + await this.#denops.cmd(cmd, context); |
| 36 | + } |
| 37 | + |
| 38 | + async eval(expr: string, context: Context = {}): Promise<void> { |
| 39 | + await this.#denops.eval(expr, context); |
| 40 | + } |
| 41 | + |
| 42 | + async execute(command: string | string[]): Promise<void> { |
| 43 | + await execute(this.#denops, command); |
| 44 | + } |
| 45 | + |
| 46 | + async autocmd( |
| 47 | + group: string, |
| 48 | + main: (helper: AutocmdHelper) => void, |
| 49 | + ): Promise<void> { |
| 50 | + await autocmd(this.#denops, group, main); |
| 51 | + } |
| 52 | + |
| 53 | + register(dispatcher: Dispatcher): void { |
| 54 | + this.#denops.extendDispatcher(dispatcher); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +export function start(main: (vim: Vim) => Promise<void>) { |
| 59 | + Denops.start(async (denops) => { |
| 60 | + const vim = new Vim(denops); |
| 61 | + await main(vim); |
| 62 | + }); |
| 63 | +} |
0 commit comments