Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from vim-denops/service-dispatch
Browse files Browse the repository at this point in the history
Add `dispatch` to dispatch other plugin's API
  • Loading branch information
lambdalisue authored Apr 18, 2021
2 parents 6d7e418 + ef38d59 commit 835b6cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 8 additions & 3 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ export interface Context {
*/
export interface Api {
/**
* Call {func} with given {args} and return the result
* Dispatch {method} of {name} plugin with given {params} directly and return the result
*/
dispatch(name: string, method: string, params: unknown[]): Promise<unknown>;

/**
* Call {func} of Vim/Nevoim with given {args} and return the result
*/
call(func: string, ...args: unknown[]): Promise<unknown>;

/**
* Execute {cmd} under the {context}
* Execute {cmd} of Vim/Neovim under the {context}
*/
cmd(cmd: string, context: Context): Promise<void>;

/**
* Evaluate {expr} under the {context} and return result
* Evaluate {expr} of Vim/Neovim under the {context} and return result
*/
eval(expr: string, context: Context): Promise<unknown>;
}
Expand Down
16 changes: 12 additions & 4 deletions denops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ export class Denops implements Api {
return this.#name;
}

async dispatch(
name: string,
method: string,
params: unknown[],
): Promise<unknown> {
return await this.#session.call("dispatch", name, method, params);
}

async call(func: string, ...args: unknown[]): Promise<unknown> {
return await this.#session.call("call", func, ...args);
}

async cmd(cmd: string, context: Context = {}): Promise<void> {
await this.#session.call("cmd", cmd, context);
}
Expand All @@ -70,10 +82,6 @@ export class Denops implements Api {
return await this.#session.call("eval", expr, context);
}

async call(func: string, ...args: unknown[]): Promise<unknown> {
return await this.#session.call("call", func, ...args);
}

/**
* Extend dispatcher of the internal msgpack_rpc session
*/
Expand Down

0 comments on commit 835b6cd

Please sign in to comment.