-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.ts
165 lines (150 loc) · 4.18 KB
/
type.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* This module provides type interfaces for [denops.vim].
*
* [denops.vim]: https://github.com/vim-denops/denops.vim
*
* @module
*/
/**
* API dispatcher
*/
export type Dispatcher = {
[key: string]: (...args: unknown[]) => unknown;
};
/**
* Context that expands into the local namespace (l:)
*/
export type Context = Record<string, unknown>;
/**
* Environment meta information.
*/
export interface Meta {
/**
* Current denops mode.
* In "debug" or "test" mode, some features become enabled,
* which might impact performance.
*/
readonly mode: "release" | "debug" | "test";
/**
* Host program.
*/
readonly host: "vim" | "nvim";
/**
* Host program version.
*/
readonly version: string;
/**
* Host platform name.
*/
readonly platform: "windows" | "mac" | "linux";
}
/**
* Denops is a facade instance visible from each denops plugin.
*/
export interface Denops {
/**
* Denops instance name used to communicate with Vim.
*/
readonly name: string;
/**
* Environment meta information.
*/
readonly meta: Meta;
/**
* Context object for plugins.
*/
readonly context: Record<PropertyKey, unknown>;
/**
* AbortSignal instance that is triggered when the user invoke `denops#interrupt()`
*/
readonly interrupted?: AbortSignal;
/**
* User-defined API name and method map used to dispatch API requests.
*/
dispatcher: Dispatcher;
/**
* Redraw text and cursor on Vim.
*
* It is not equivalent to the `redraw` command in Vim script and does nothing on Neovim.
* Use `denops.cmd('redraw')` instead if you need to execute the `redraw` command.
*
* @param force: Clear the screen prior to redraw.
*/
redraw(force?: boolean): Promise<void>;
/**
* Call an arbitrary function of Vim/Neovim and return the result.
*
* @param fn: A function name of Vim/Neovim.
* @param args: Arguments of the function.
*
* Note that arguments after `undefined` in `args` will be dropped for convenience.
*/
call(fn: string, ...args: unknown[]): Promise<unknown>;
/**
* Call arbitrary functions of Vim/Neovim sequentially without redraw and
* return the results.
*
* It throws a BatchError when one of the functions fails. The `results` attribute
* of the error instance holds succeeded results of functions prior to the
* error.
*
* @param calls: A list of tuples ([fn, args]) to call Vim/Neovim functions.
*
* Note that arguments after `undefined` in `args` will be dropped for convenience.
*/
batch(...calls: [string, ...unknown[]][]): Promise<unknown[]>;
/**
* Execute an arbitrary command of Vim/Neovim under a given context.
*
* @param cmd: A command expression to be executed.
* @param ctx: A context object that expands into the local namespace (l:)
*/
cmd(cmd: string, ctx?: Context): Promise<void>;
/**
* Evaluate an arbitrary expression of Vim/Neovim under a given context and return the result.
*
* @param expr: An expression to be evaluated.
* @param ctx: A context object that expands into the local namespace (l:)
*/
eval(expr: string, ctx?: Context): Promise<unknown>;
/**
* Dispatch an arbitrary function of an arbitrary plugin and return the result.
*
* @param name: A plugin registration name.
* @param fn: A function name in the API registration.
* @param args: Arguments of the function.
*/
dispatch(name: string, fn: string, ...args: unknown[]): Promise<unknown>;
}
/**
* Denops's entrypoint definition.
*
* Use this type to ensure the `main` function is properly implemented like:
*
* ```ts
* import type { Entrypoint } from "jsr:@denops/core";
*
* export const main: Entrypoint = (denops) => {
* // ...
* }
* ```
*
* If an `AsyncDisposable` object is returned, resources can be disposed of
* asynchronously when the plugin is unloaded, like:
*
* ```ts
* import type { Entrypoint } from "jsr:@denops/core";
*
* export const main: Entrypoint = (denops) => {
* // ...
* return {
* [Symbol.asyncDispose]: async () => {
* // Dispose resources...
* }
* }
* }
* ```
*/
export type Entrypoint = (
denops: Denops,
) => void | AsyncDisposable | Promise<void | AsyncDisposable>;