rsvim-types 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitmodules +3 -0
- package/LICENSE.txt +78 -0
- package/README.md +75 -0
- package/package.json +22 -0
- package/runtime/00__web.ts +669 -0
- package/runtime/01__rsvim.ts +2003 -0
- package/tsconfig.json +40 -0
- package/types/00__web.d.ts +252 -0
- package/types/01__rsvim.d.ts +1335 -0
- package/types/index.d.ts +2 -0
|
@@ -0,0 +1,1335 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* ---
|
|
4
|
+
* title: Rsvim API
|
|
5
|
+
* sidebar_position: 2
|
|
6
|
+
* ---
|
|
7
|
+
*
|
|
8
|
+
* The `Rsvim` global object, it contains two groups:
|
|
9
|
+
* - General APIs.
|
|
10
|
+
* - Editor APIs.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*
|
|
14
|
+
* @categoryDescription Global Object
|
|
15
|
+
* The global object.
|
|
16
|
+
*
|
|
17
|
+
* @categoryDescription Editor APIs
|
|
18
|
+
* These APIs are specific for editor, such as buffers, windows, key mappings, etc.
|
|
19
|
+
*
|
|
20
|
+
* @categoryDescription General APIs
|
|
21
|
+
* These APIs are general for common javascript-based runtime, similar to [Deno APIs](https://docs.deno.com/api/deno/).
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The `Rsvim.buf` global object for Vim buffers.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```javascript
|
|
28
|
+
* // Create a alias to 'Rsvim.buf'.
|
|
29
|
+
* const buf = Rsvim.buf;
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @category Editor APIs
|
|
33
|
+
*/
|
|
34
|
+
export declare namespace RsvimBuf {
|
|
35
|
+
/**
|
|
36
|
+
* Get current buffer's ID.
|
|
37
|
+
*
|
|
38
|
+
* The "current" buffer is the buffer that the window where your cursor is
|
|
39
|
+
* located is binded to.
|
|
40
|
+
*
|
|
41
|
+
* :::warning
|
|
42
|
+
* When the editor is not initialized, i.e. there's no buffer/window created. It
|
|
43
|
+
* will return `undefined`. Once the editor is initialized, there will always have a
|
|
44
|
+
* valid buffer binded to the "current" window (where your cursor is). It will return
|
|
45
|
+
* the valid buffer ID.
|
|
46
|
+
* :::
|
|
47
|
+
*
|
|
48
|
+
* @returns {(number | undefined)} It returns a valid buffer ID if the editor is initialized.
|
|
49
|
+
* Otherwise it returns `undefined` if the editor is not initialized.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```javascript
|
|
53
|
+
* const bufId = Rsvim.buf.current();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function current(): number | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* List all buffers' IDs.
|
|
59
|
+
*
|
|
60
|
+
* :::warning
|
|
61
|
+
* When the editor is not initialized, i.e. there's no buffer/window created. It
|
|
62
|
+
* will return an empty array. Once the editor is initialized, there will have at least 1
|
|
63
|
+
* buffer binded to the "current" window (where your cursor is). It will return all the
|
|
64
|
+
* buffer IDs as an array.
|
|
65
|
+
* :::
|
|
66
|
+
*
|
|
67
|
+
* @returns {number[]} All the buffers' IDs as an array. If there's no
|
|
68
|
+
* buffer (i.e. the editor is not initialized), it returns an empty array.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```javascript
|
|
72
|
+
* const bufIds = Rsvim.buf.list();
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
function list(): number[];
|
|
76
|
+
/**
|
|
77
|
+
* Write (save) buffer's text contents to local filesystem synchronizely.
|
|
78
|
+
*
|
|
79
|
+
* @param {number} bufId - The buffer's ID that you want to write to filesystem.
|
|
80
|
+
*
|
|
81
|
+
* @returns {number} It returns a positive integer to indicate how many bytes
|
|
82
|
+
* have been written to the file, if written successfully.
|
|
83
|
+
*
|
|
84
|
+
* @throws Throws {@link !TypeError} if the parameter is invalid, or {@link !Error} if failed to write buffer to file system.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```javascript
|
|
88
|
+
* const bufId = Rsvim.buf.currentBufferId();
|
|
89
|
+
* try {
|
|
90
|
+
* const bytes = Rsvim.buf.writeSync(bufId);
|
|
91
|
+
* Rsvim.cmd.echo(`Buffer ${bufId} has been saved, ${bytes} bytes written`);
|
|
92
|
+
* } catch (e) {
|
|
93
|
+
* Rsvim.cmd.echo(`Error: failed to save buffer ${bufId}, exception: ${e}`);
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
function writeSync(bufId: number): number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The `Rsvim.cmd` global object for Ex commands.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```javascript
|
|
104
|
+
* // Create a alias to 'Rsvim.cmd'.
|
|
105
|
+
* const cmd = Rsvim.cmd;
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @category Editor APIs
|
|
109
|
+
*/
|
|
110
|
+
export declare namespace RsvimCmd {
|
|
111
|
+
/**
|
|
112
|
+
* Create a ex command with a callback function.
|
|
113
|
+
*
|
|
114
|
+
* :::warning
|
|
115
|
+
* The builtin command `js` cannot be override.
|
|
116
|
+
* :::
|
|
117
|
+
*
|
|
118
|
+
* @param {string} name - Command name that is going to create. Only letters (`a-z` and `A-Z`), digits (`0-9`), underscore (`_`) and exclamation (`!`) are allowed in a command name. Command name must not begin with a digit.
|
|
119
|
+
* @param {RsvimCmd.CommandCallback} callback - Async callback function that implements the command. It accepts an `ctx` parameter that contains all the information when user is running it. See {@link RsvimCmd.CommandCallback}.
|
|
120
|
+
* @param {RsvimCmd.CommandAttributes} attributes - (Optional) Attributes that control the command behavior, by default is `{bang:false, nargs:"0"}`, see {@link RsvimCmd.CommandAttributes}.
|
|
121
|
+
* @param {RsvimCmd.CommandOptions} options - (Optional) Options that control how the command is created, by default is `{force:true}`, see {@link RsvimCmd.CommandOptions}.
|
|
122
|
+
* @returns {(RsvimCmd.CommandDefinition | undefined)} It returns `undefined` is the command is newly created. Or it returns a command definition that was defined previously.
|
|
123
|
+
*
|
|
124
|
+
* @throws Throws {@link !TypeError} if any parameters are invalid. Or throws {@link Error} if command name or alias already exists, but `force` option is not set to override existing command forcibly.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```javascript
|
|
128
|
+
* async function write(ctx: RsvimCmd.CommandContext): void {
|
|
129
|
+
* try {
|
|
130
|
+
* const bytes = Rsvim.buf.writeSync(ctx.currentBufferId);
|
|
131
|
+
*
|
|
132
|
+
* // Call other async APIs
|
|
133
|
+
* const file = await Rsvim.fs.open("message.txt");
|
|
134
|
+
* const buffer = new Uint8Array(100);
|
|
135
|
+
* const read = await file.read(buffer);
|
|
136
|
+
* const message = new TextDecoder().decode(buffer);
|
|
137
|
+
*
|
|
138
|
+
* Rsvim.cmd.echo(`Buffer ${bufId} has been saved, ${bytes} bytes written with message: ${message}`);
|
|
139
|
+
* } catch (e) {
|
|
140
|
+
* Rsvim.cmd.echo(`Error: failed to save buffer ${bufId}, exception: ${e}`);
|
|
141
|
+
* }
|
|
142
|
+
* }
|
|
143
|
+
* Rsvim.cmd.create("write", write);
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
function create(name: string, callback: RsvimCmd.CommandCallback, attributes?: RsvimCmd.CommandAttributes, options?: RsvimCmd.CommandOptions): RsvimCmd.CommandDefinition | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Echo message to the command-line.
|
|
149
|
+
*
|
|
150
|
+
* @param {any} message - It accepts string and other primitive types, except `null` and `undefined`.
|
|
151
|
+
*
|
|
152
|
+
* @throws Throws {@link !TypeError} if the parameter is `null` or `undefined` or no parameter provided.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```javascript
|
|
156
|
+
* Rsvim.cmd.echo("Hello Rsvim!");
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
function echo(message: any): void;
|
|
160
|
+
/**
|
|
161
|
+
* List all registered ex command names.
|
|
162
|
+
*
|
|
163
|
+
* :::warning
|
|
164
|
+
* The builtin `js` command will not be listed here.
|
|
165
|
+
* :::
|
|
166
|
+
*
|
|
167
|
+
* @returns {string[]} Returns all registered ex command names, except the `js` command.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```javascript
|
|
171
|
+
* Rsvim.cmd.list().forEach((name) => {
|
|
172
|
+
* Rsvim.cmd.echo(`Command: ${name}`);
|
|
173
|
+
* });
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
function list(): string[];
|
|
177
|
+
/**
|
|
178
|
+
* Get ex command definition by name.
|
|
179
|
+
*
|
|
180
|
+
* :::warning
|
|
181
|
+
* The builtin `js` command cannot be get.
|
|
182
|
+
* :::
|
|
183
|
+
*
|
|
184
|
+
* @returns {(RsvimCmd.CommandDefinition | undefined)} Returns command definition by its name, except the `js` command.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```javascript
|
|
188
|
+
* const def = Rsvim.cmd.get("write");
|
|
189
|
+
* Rsvim.cmd.echo(`Command: ${def.name}`);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
function get(name: string): RsvimCmd.CommandDefinition | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* Remove an ex command by name.
|
|
195
|
+
*
|
|
196
|
+
* :::warning
|
|
197
|
+
* The builtin command `js` cannot be removed.
|
|
198
|
+
* :::
|
|
199
|
+
*
|
|
200
|
+
* @param {string} name - The command name to be removed.
|
|
201
|
+
* @returns {(RsvimCmd.CommandDefinition | undefined)} Returns the removed {@link RsvimCmd.CommandDefinition}, or `undefined` if no command is been removed.
|
|
202
|
+
*
|
|
203
|
+
* @throws Throws {@link !TypeError} if name is not a string.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```javascript
|
|
207
|
+
* Rsvim.cmd.list().forEach((cmd) => {
|
|
208
|
+
* // Remove all registered commands.
|
|
209
|
+
* Rsvim.cmd.remove(cmd.name);
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
function remove(name: string): RsvimCmd.CommandDefinition | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Command attributes.
|
|
216
|
+
*
|
|
217
|
+
* @see {@link RsvimCmd.create}
|
|
218
|
+
*/
|
|
219
|
+
type CommandAttributes = {
|
|
220
|
+
/**
|
|
221
|
+
* Whether the command can take a `!` modifier, for example: `:w!`, `:qall!`.
|
|
222
|
+
*
|
|
223
|
+
* @defaultValue `false`
|
|
224
|
+
, */
|
|
225
|
+
bang?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Whether The command can take any arguments, and how many it can take:
|
|
228
|
+
*
|
|
229
|
+
* - `0`: No arguments are allowed.
|
|
230
|
+
* - `1`: Exactly 1 argument is required.
|
|
231
|
+
* - `*`: Any number of arguments are allowed, i.e. 0, 1 or more.
|
|
232
|
+
* - `?`: 0 or 1 arguments are allowed.
|
|
233
|
+
* - `+`: At least 1 arguments are required.
|
|
234
|
+
*
|
|
235
|
+
* @defaultValue `0`
|
|
236
|
+
, */
|
|
237
|
+
nargs?: "0" | "1" | "*" | "+" | "?";
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Command options when creating a command.
|
|
241
|
+
*
|
|
242
|
+
* @see {@link RsvimCmd.create}
|
|
243
|
+
*/
|
|
244
|
+
type CommandOptions = {
|
|
245
|
+
/**
|
|
246
|
+
* Whether force override the command if there's already an existing one.
|
|
247
|
+
*
|
|
248
|
+
* @defaultValue `true`
|
|
249
|
+
*/
|
|
250
|
+
force?: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Command alias, i.e. short name.
|
|
253
|
+
*
|
|
254
|
+
* For example, the `w` is alias for `write`.
|
|
255
|
+
*
|
|
256
|
+
* @defaultValue `undefined`
|
|
257
|
+
*/
|
|
258
|
+
alias?: string;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Command callback function, this is the backend logic that implements a user ex command.
|
|
262
|
+
*
|
|
263
|
+
* It accepts a `ctx` parameter that indicates runtime information when the command is executed.
|
|
264
|
+
*
|
|
265
|
+
* @see {@link RsvimCmd.create}
|
|
266
|
+
* @see {@link CommandContext}
|
|
267
|
+
, */
|
|
268
|
+
type CommandCallback = (ctx: CommandContext) => Promise<void>;
|
|
269
|
+
/**
|
|
270
|
+
* Command definition.
|
|
271
|
+
*/
|
|
272
|
+
type CommandDefinition = {
|
|
273
|
+
name: string;
|
|
274
|
+
callback: CommandCallback;
|
|
275
|
+
attributes: CommandAttributes;
|
|
276
|
+
options: CommandOptions;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Command runtime context.
|
|
280
|
+
*
|
|
281
|
+
* When a command is been execute, runtime information will be passed to the command callback function.
|
|
282
|
+
*/
|
|
283
|
+
type CommandContext = {
|
|
284
|
+
/**
|
|
285
|
+
* Whether the command is executed with a bang "!".
|
|
286
|
+
*/
|
|
287
|
+
bang: boolean;
|
|
288
|
+
/**
|
|
289
|
+
* Arguments that are passed to the command when executed.
|
|
290
|
+
*/
|
|
291
|
+
args: string[];
|
|
292
|
+
/**
|
|
293
|
+
* Current buffer ID when the command is executed.
|
|
294
|
+
*/
|
|
295
|
+
currentBufferId: number;
|
|
296
|
+
/**
|
|
297
|
+
* Current window ID when the command is executed.
|
|
298
|
+
*/
|
|
299
|
+
currentWindowId: number;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The `Rsvim.fs` global object for file system and file IO.
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```javascript
|
|
307
|
+
* // Create a alias to 'Rsvim.fs'.
|
|
308
|
+
* const fs = Rsvim.fs;
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* @category General APIs
|
|
312
|
+
*/
|
|
313
|
+
export declare namespace RsvimFs {
|
|
314
|
+
/**
|
|
315
|
+
* Open a file and resolve to an instance of {@link RsvimFs.File}. The file does not need to previously exist if using the `create` or `createNew` open options.
|
|
316
|
+
* The caller have to close the file to prevent resource leaking, see {@link RsvimFs.File.close}.
|
|
317
|
+
*
|
|
318
|
+
* @param {string} path - File path.
|
|
319
|
+
* @param {RsvimFs.OpenOptions} options - (Optional) Open options, by default is `{read: true}`. See {@link RsvimFs.OpenOptions}.
|
|
320
|
+
* @returns {Promise<RsvimFs.File>} It resolves to an instance of {@link RsvimFs.File}.
|
|
321
|
+
*
|
|
322
|
+
* @throws Throws {@link !TypeError} if any parameters are invalid. Or throws {@link Error} if failed to open/create the file.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```javascript
|
|
326
|
+
* const file = await Rsvim.fs.open("README.md");
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
function open(path: string, options?: RsvimFs.OpenOptions): Promise<RsvimFs.File>;
|
|
330
|
+
/**
|
|
331
|
+
* The sync version of {@link open}.
|
|
332
|
+
*
|
|
333
|
+
* @param {string} path
|
|
334
|
+
* @param {RsvimFs.OpenOptions} options
|
|
335
|
+
* @returns {RsvimFs.File}
|
|
336
|
+
*
|
|
337
|
+
* @throws
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```javascript
|
|
341
|
+
* const file = Rsvim.fs.openSync("README.md");
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
function openSync(path: string, options?: RsvimFs.OpenOptions): RsvimFs.File;
|
|
345
|
+
/**
|
|
346
|
+
* Read a file in binary mode, i.e. into an array of bytes buffer, without open/close a file descriptor/handle.
|
|
347
|
+
*
|
|
348
|
+
* @param {string} path - File path to read.
|
|
349
|
+
* @returns {Promise<Uint8Array>} It resolves to {@link !Uint8Array} that contains all the file contents as bytes array.
|
|
350
|
+
*
|
|
351
|
+
* @throws Throws {@link !TypeError} if the file name is invalid. Or throws {@link Error} if failed to read the file.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```javascript
|
|
355
|
+
* const buffer = await Rsvim.fs.readFile("README.md");
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
function readFile(path: string): Promise<Uint8Array>;
|
|
359
|
+
/**
|
|
360
|
+
* The sync version of {@link readFile}.
|
|
361
|
+
*
|
|
362
|
+
* @param {string} path
|
|
363
|
+
* @returns {Uint8Array}
|
|
364
|
+
*
|
|
365
|
+
* @throws
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```javascript
|
|
369
|
+
* const buffer = Rsvim.fs.readFileSync("README.md");
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
function readFileSync(path: string): Uint8Array;
|
|
373
|
+
/**
|
|
374
|
+
* Read a file in text mode, i.e. into a string, without open/close a file descriptor/handle.
|
|
375
|
+
*
|
|
376
|
+
* @param {string} path - File path to read.
|
|
377
|
+
* @returns {Promise<string>} It resolves to text string that contains all the file contents.
|
|
378
|
+
*
|
|
379
|
+
* @throws Throws {@link !TypeError} if the file name is invalid. Or throws {@link Error} if failed to read the file.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```javascript
|
|
383
|
+
* const payload = await Rsvim.fs.readTextFile("README.md");
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
function readTextFile(path: string): Promise<string>;
|
|
387
|
+
/**
|
|
388
|
+
* The sync version of {@link readTextFile}.
|
|
389
|
+
*
|
|
390
|
+
* @param {string} path
|
|
391
|
+
* @returns {string}
|
|
392
|
+
*
|
|
393
|
+
* @throws
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```javascript
|
|
397
|
+
* const payload = Rsvim.fs.readTextFileSync("README.md");
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
function readTextFileSync(path: string): string;
|
|
401
|
+
/**
|
|
402
|
+
* Open options.
|
|
403
|
+
*
|
|
404
|
+
* :::tip
|
|
405
|
+
* It is same with [std::fs::OpenOptions](https://doc.rust-lang.org/std/fs/struct.OpenOptions.html) in rust std library.
|
|
406
|
+
* :::
|
|
407
|
+
*
|
|
408
|
+
* @see {@link RsvimFs.open}
|
|
409
|
+
*/
|
|
410
|
+
type OpenOptions = {
|
|
411
|
+
/**
|
|
412
|
+
* Set the file for append mode.
|
|
413
|
+
*
|
|
414
|
+
* @defaultValue `false`
|
|
415
|
+
, */
|
|
416
|
+
append?: boolean;
|
|
417
|
+
/**
|
|
418
|
+
* Create a new file or open it if it already exists.
|
|
419
|
+
*
|
|
420
|
+
* In order for the file to be created, `write` or `append` access must be used.
|
|
421
|
+
*
|
|
422
|
+
* @defaultValue `false`
|
|
423
|
+
, */
|
|
424
|
+
create?: boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Create a new file, failing if it already exists.
|
|
427
|
+
*
|
|
428
|
+
* If this option is set, `create` and `truncate` options are ignored.
|
|
429
|
+
*
|
|
430
|
+
* @defaultValue `false`
|
|
431
|
+
, */
|
|
432
|
+
createNew?: boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Set the file for read access.
|
|
435
|
+
*
|
|
436
|
+
* @defaultValue `false`
|
|
437
|
+
, */
|
|
438
|
+
read?: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Open the file and truncate the file to `0` length if it already exists.
|
|
441
|
+
*
|
|
442
|
+
* @defaultValue `false`
|
|
443
|
+
, */
|
|
444
|
+
truncate?: boolean;
|
|
445
|
+
/**
|
|
446
|
+
* Set the file for write access. If the file already exists, any "write" calls on it will
|
|
447
|
+
* overwrite the contents, without truncating it.
|
|
448
|
+
*
|
|
449
|
+
* @defaultValue `false`
|
|
450
|
+
, */
|
|
451
|
+
write?: boolean;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* The File object that access to an open file on filesystem.
|
|
455
|
+
*
|
|
456
|
+
* @see {@link RsvimFs.open}
|
|
457
|
+
*/
|
|
458
|
+
class File {
|
|
459
|
+
#private;
|
|
460
|
+
/** @hidden */
|
|
461
|
+
constructor(rid: number);
|
|
462
|
+
/**
|
|
463
|
+
* Close the file.
|
|
464
|
+
*
|
|
465
|
+
* @throws Throws {@link !Error} if the file is already been closed.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```javascript
|
|
469
|
+
* const file = await Rsvim.fs.open("README.md");
|
|
470
|
+
* // do work with the `file` object
|
|
471
|
+
* file.close();
|
|
472
|
+
*
|
|
473
|
+
* // Or
|
|
474
|
+
*
|
|
475
|
+
* using file = await Rsvim.fs.open("README.md");
|
|
476
|
+
* // do work with the `file` object
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
close(): void;
|
|
480
|
+
/**
|
|
481
|
+
* Close the file with `using` API instead of `close`.
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```javascript
|
|
485
|
+
* using file = await Rsvim.fs.open("README.md");
|
|
486
|
+
* // do work with the `file` object
|
|
487
|
+
* ```
|
|
488
|
+
*
|
|
489
|
+
* @see {@link close}
|
|
490
|
+
*/
|
|
491
|
+
[Symbol.dispose](): void;
|
|
492
|
+
/**
|
|
493
|
+
* File is already been closed.
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```javascript
|
|
497
|
+
* const file = await Rsvim.fs.open("README.md");
|
|
498
|
+
* if (!file.isDisposed()) {
|
|
499
|
+
* file.close();
|
|
500
|
+
* }
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
get isDisposed(): boolean;
|
|
504
|
+
/**
|
|
505
|
+
* Read a file into a buffer.
|
|
506
|
+
*
|
|
507
|
+
* :::warning
|
|
508
|
+
* It is not guaranteed that the full buffer will be read in a single call.
|
|
509
|
+
* :::
|
|
510
|
+
*
|
|
511
|
+
* @param {Uint8Array} buf - Read bytes into buffer.
|
|
512
|
+
* @returns {Promise<number>} It resolves to either the number of bytes read during the operation or `0`(EOF) if there was no more to read.
|
|
513
|
+
*
|
|
514
|
+
* @throws Throws {@link !TypeError} if buf is not a Uint8Array.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```javascript
|
|
518
|
+
* using file = await Rsvim.fs.open("README.md");
|
|
519
|
+
* const buf = new Uint8Array(100);
|
|
520
|
+
* const n = await file.read(buf); // read 11 bytes
|
|
521
|
+
* const text = new TextDecoder().decode(buf); // decode into UTF-8 string "hello world"
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
read(buf: Uint8Array): Promise<number>;
|
|
525
|
+
/**
|
|
526
|
+
* The sync version of {@link read}.
|
|
527
|
+
*
|
|
528
|
+
* @param {Uint8Array} buf
|
|
529
|
+
* @returns {number}
|
|
530
|
+
*
|
|
531
|
+
* @throws
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```javascript
|
|
535
|
+
* using file = await Rsvim.fs.open("README.md");
|
|
536
|
+
* const buf = new Uint8Array(100);
|
|
537
|
+
* const n = file.readSync(buf); // read 11 bytes
|
|
538
|
+
* const text = new TextDecoder().decode(buf); // decode into UTF-8 string "hello world"
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
readSync(buf: Uint8Array): number;
|
|
542
|
+
/**
|
|
543
|
+
* Write a buffer into a file.
|
|
544
|
+
*
|
|
545
|
+
* :::warning
|
|
546
|
+
* It is not guaranteed that the full buffer will be written in a single call.
|
|
547
|
+
* :::
|
|
548
|
+
*
|
|
549
|
+
* @param {Uint8Array} buf - Read bytes into buffer.
|
|
550
|
+
* @returns {Promise<number>} It resolves to either the number of bytes written during the operation or `0` if there was nothing to write.
|
|
551
|
+
*
|
|
552
|
+
* @throws Throws {@link !TypeError} if buf is not a Uint8Array.
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```javascript
|
|
556
|
+
* using file = await Rsvim.fs.open("README.md", {write:true,create:true});
|
|
557
|
+
* const buf = new TextEncoder().encode("hello world");
|
|
558
|
+
* const n = await file.write(buf); // write 11 bytes
|
|
559
|
+
* ```
|
|
560
|
+
*/
|
|
561
|
+
write(buf: Uint8Array): Promise<number>;
|
|
562
|
+
/**
|
|
563
|
+
* The sync version of {@link write}.
|
|
564
|
+
*
|
|
565
|
+
* @param {Uint8Array} buf
|
|
566
|
+
* @returns {number}
|
|
567
|
+
*
|
|
568
|
+
* @throws
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```javascript
|
|
572
|
+
* using file = await Rsvim.fs.open("README.md", {write:true,create:true});
|
|
573
|
+
* const buf = new TextEncoder().encode("hello world");
|
|
574
|
+
* const n = file.writeSync(buf); // write 11 bytes
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
writeSync(buf: Uint8Array): number;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
export declare namespace RsvimOpt {
|
|
581
|
+
/**
|
|
582
|
+
* @see {@link RsvimOpt.fileEncoding}
|
|
583
|
+
* @inline
|
|
584
|
+
* */
|
|
585
|
+
type FileEncodingOption = "utf-8";
|
|
586
|
+
/**
|
|
587
|
+
* @see {@link RsvimOpt.fileFormat}
|
|
588
|
+
* @inline
|
|
589
|
+
*/
|
|
590
|
+
type FileFormatOption = "dos" | "unix" | "mac";
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* The `Rsvim.opt` global object for global editor options. These options will change the editor's behavior
|
|
594
|
+
* and suit user's personal habits.
|
|
595
|
+
*
|
|
596
|
+
* There are 3 kinds of editor option:
|
|
597
|
+
* - Global options: Options that are global that you use one value for all Rsvim component instances such
|
|
598
|
+
* as buffer, window, statusline, etc. When you change the option, it will take effect immediately and
|
|
599
|
+
* affect all existing instances.
|
|
600
|
+
* - Local options: Options that only apply to one component instance, each instance has its own copy of
|
|
601
|
+
* this option, thus each can have its own value. This allow you to set an option in one instance, without
|
|
602
|
+
* modifying other instances.
|
|
603
|
+
* - Global local options: Options that are global, and will be copy to a newly created Rsvim component
|
|
604
|
+
* instance. A global-local-option always has its corresponding local-option. When you change the option,
|
|
605
|
+
* it only will apply to the newly created instances, but cannot modify existing instances.
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```javascript
|
|
609
|
+
* // Create a alias to 'Rsvim.opt'.
|
|
610
|
+
* const opt = Rsvim.opt;
|
|
611
|
+
* ```
|
|
612
|
+
*
|
|
613
|
+
* @category Editor APIs
|
|
614
|
+
* @hideconstructor
|
|
615
|
+
*/
|
|
616
|
+
export declare class RsvimOpt {
|
|
617
|
+
/**
|
|
618
|
+
* Get the _expand-tab_ option. Local to buffer.
|
|
619
|
+
*
|
|
620
|
+
* When in insert mode, inserts [spaces](https://en.wikipedia.org/wiki/Whitespace_character) (ASCII `32`)
|
|
621
|
+
* instead of a [horizontal tab](https://en.wikipedia.org/wiki/Tab_key) (ASCII `9`).
|
|
622
|
+
*
|
|
623
|
+
* See {@link shiftWidth} to get the number of spaces when inserting.
|
|
624
|
+
*
|
|
625
|
+
* @returns {boolean}
|
|
626
|
+
*
|
|
627
|
+
* @defaultValue `false`
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
* ```javascript
|
|
631
|
+
* // Get the 'expand-tab' option.
|
|
632
|
+
* const value = Rsvim.opt.expandTab;
|
|
633
|
+
* ```
|
|
634
|
+
*/
|
|
635
|
+
get expandTab(): boolean;
|
|
636
|
+
/**
|
|
637
|
+
* Set the _expand-tab_ option.
|
|
638
|
+
*
|
|
639
|
+
* @param {boolean} value - The _expand-tab_ option.
|
|
640
|
+
* @throws Throws {@link !TypeError} if value is not a boolean.
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```javascript
|
|
644
|
+
* // Set the 'expand-tab' option.
|
|
645
|
+
* Rsvim.opt.expandTab = true;
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
648
|
+
set expandTab(value: boolean);
|
|
649
|
+
/**
|
|
650
|
+
* Get the _file-encoding_ option. Local to buffer.
|
|
651
|
+
*
|
|
652
|
+
* Sets the [character encoding](https://en.wikipedia.org/wiki/Character_encoding) for the file of this buffer.
|
|
653
|
+
* This will determine which character encoding is used when RSVIM read/write a file from file system.
|
|
654
|
+
*
|
|
655
|
+
* :::warning
|
|
656
|
+
* For now, only **utf-8** encoding is supported.
|
|
657
|
+
* :::
|
|
658
|
+
*
|
|
659
|
+
* @returns {RsvimOpt.FileEncodingOption}
|
|
660
|
+
*
|
|
661
|
+
* @defaultValue `"utf-8"`
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```javascript
|
|
665
|
+
* // Get the 'file-encoding' option.
|
|
666
|
+
* const value = Rsvim.opt.fileEncoding;
|
|
667
|
+
* ```
|
|
668
|
+
*/
|
|
669
|
+
get fileEncoding(): RsvimOpt.FileEncodingOption;
|
|
670
|
+
/**
|
|
671
|
+
* Set the _file-encoding_ option.
|
|
672
|
+
*
|
|
673
|
+
* @param {RsvimOpt.FileEncodingOption} value - The _file-encoding_ option.
|
|
674
|
+
* @throws Throws {@link !RangeError} if value is an invalid option.
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
677
|
+
* ```javascript
|
|
678
|
+
* // Set the 'file-encoding' option.
|
|
679
|
+
* Rsvim.opt.fileEncoding = "utf-8";
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
set fileEncoding(value: RsvimOpt.FileEncodingOption);
|
|
683
|
+
/**
|
|
684
|
+
* Get the _file-format_ option. Local to buffer.
|
|
685
|
+
*
|
|
686
|
+
* Sets the [line end](https://en.wikipedia.org/wiki/Newline) for the buffer. There are 3 kinds of line end:
|
|
687
|
+
* - `CRLF`: used by [Windows](https://www.microsoft.com/windows).
|
|
688
|
+
* - `LF`: used by [Linux](https://en.wikipedia.org/wiki/Linux) and [Unix](https://en.wikipedia.org/wiki/Unix) (include [MacOS](https://www.apple.com/macos/)).
|
|
689
|
+
* - `CR`: used by [classic MacOS](https://en.wikipedia.org/wiki/Classic_Mac_OS).
|
|
690
|
+
*
|
|
691
|
+
* :::warning
|
|
692
|
+
* Today's Mac also uses `LF` as line end, you should never use `CR` any more.
|
|
693
|
+
* :::
|
|
694
|
+
*
|
|
695
|
+
* For this option, it has below choices:
|
|
696
|
+
* - `"dos"`: equivalent to `CRLF` line end.
|
|
697
|
+
* - `"unix"`: equivalent to `LF` line end.
|
|
698
|
+
* - `"mac"`: equivalent to `CR` line end.
|
|
699
|
+
*
|
|
700
|
+
* @returns {RsvimOpt.FileFormatOption}
|
|
701
|
+
*
|
|
702
|
+
* @defaultValue `"dos"` for Windows/MS-DOS, `"unix"` for Linux/Unix/MacOS.
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* ```javascript
|
|
706
|
+
* // Get the 'file-format' option.
|
|
707
|
+
* const value = Rsvim.opt.fileFormat;
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
710
|
+
get fileFormat(): RsvimOpt.FileFormatOption;
|
|
711
|
+
/**
|
|
712
|
+
* Set the _file-format_ option.
|
|
713
|
+
*
|
|
714
|
+
* @param {RsvimOpt.FileFormatOption} value - The _file-format_ option.
|
|
715
|
+
* @throws Throws {@link !RangeError} if value is an invalid option.
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
* ```javascript
|
|
719
|
+
* // Set the 'file-format' option.
|
|
720
|
+
* Rsvim.opt.fileFormat = "unix";
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
set fileFormat(value: RsvimOpt.FileFormatOption);
|
|
724
|
+
/**
|
|
725
|
+
* Get the _fix-end-of-line_ option. Local to buffer.
|
|
726
|
+
*
|
|
727
|
+
* WHen writing a file and this options is enabled, `EOL` (`LF`, `CR`, `CRLF`) at the end of file will be restored if missing. Disable this option if you want to preserve the situation from the original file.
|
|
728
|
+
*
|
|
729
|
+
* @see {@link fileFormat}
|
|
730
|
+
*
|
|
731
|
+
* @returns {boolean}
|
|
732
|
+
*
|
|
733
|
+
* @defaultValue `true`
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* ```javascript
|
|
737
|
+
* // Get the 'fix-end-of-line' option.
|
|
738
|
+
* const value = Rsvim.opt.fixEndOfLine;
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
get fixEndOfLine(): boolean;
|
|
742
|
+
/**
|
|
743
|
+
* Set the _fix-end-of-line_ option.
|
|
744
|
+
*
|
|
745
|
+
* @param {boolean} value - The _fix-end-of-line_ option.
|
|
746
|
+
* @throws Throws {@link !RangeError} if value is not a boolean.
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* ```javascript
|
|
750
|
+
* // Set the 'fix-end-of-line' option.
|
|
751
|
+
* Rsvim.opt.fixEndOfLine = false;
|
|
752
|
+
* ```
|
|
753
|
+
*/
|
|
754
|
+
set fixEndOfLine(value: boolean);
|
|
755
|
+
/**
|
|
756
|
+
* Get the _line-break_ option. This options is also known as
|
|
757
|
+
* [word wrap](https://en.wikipedia.org/wiki/Line_wrap_and_word_wrap). Local to window.
|
|
758
|
+
*
|
|
759
|
+
* If `true`, Vim will wrap long lines by a word boundary rather than at the last character that fits on the screen.
|
|
760
|
+
* It only affects the way the file is displayed, not its contents.
|
|
761
|
+
*
|
|
762
|
+
* This option is not used when the {@link wrap} option is `false`.
|
|
763
|
+
*
|
|
764
|
+
* @returns {boolean}
|
|
765
|
+
*
|
|
766
|
+
* @defaultValue `false`
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
769
|
+
* ```javascript
|
|
770
|
+
* // Get the 'lineBreak' option.
|
|
771
|
+
* const value = Rsvim.opt.lineBreak;
|
|
772
|
+
* ```
|
|
773
|
+
*/
|
|
774
|
+
get lineBreak(): boolean;
|
|
775
|
+
/**
|
|
776
|
+
* Set the _line-break_ option.
|
|
777
|
+
*
|
|
778
|
+
* @param {boolean} value - The _line-break_ option.
|
|
779
|
+
* @throws Throws {@link !TypeError} if value is not a boolean.
|
|
780
|
+
*
|
|
781
|
+
* @example
|
|
782
|
+
* ```javascript
|
|
783
|
+
* // Set the 'lineBreak' option.
|
|
784
|
+
* Rsvim.opt.lineBreak = true;
|
|
785
|
+
* ```
|
|
786
|
+
*/
|
|
787
|
+
set lineBreak(value: boolean);
|
|
788
|
+
/**
|
|
789
|
+
* Get the _shift-width_ option. Local to buffer.
|
|
790
|
+
*
|
|
791
|
+
* When {@link expandTab} is `true`, the number of spaces that is used when inserts a
|
|
792
|
+
* [horizontal tab](https://en.wikipedia.org/wiki/Tab_key) (ASCII `9`).
|
|
793
|
+
*
|
|
794
|
+
* When {@link expandTab} is `false`, this option is not been used.
|
|
795
|
+
*
|
|
796
|
+
*
|
|
797
|
+
* @returns {number}
|
|
798
|
+
*
|
|
799
|
+
* @defaultValue `8`
|
|
800
|
+
*
|
|
801
|
+
* @example
|
|
802
|
+
* ```javascript
|
|
803
|
+
* // Get the 'shift-width' option.
|
|
804
|
+
* const value = Rsvim.opt.shiftWidth;
|
|
805
|
+
* ```
|
|
806
|
+
*/
|
|
807
|
+
get shiftWidth(): number;
|
|
808
|
+
/**
|
|
809
|
+
* Set the _shift-width_ option. It only accepts an integer between `[1,255]`, if the value is out of range, it will be bound to this range.
|
|
810
|
+
*
|
|
811
|
+
*
|
|
812
|
+
* @param {number} value - The _shift-width_ option.
|
|
813
|
+
* @throws Throws {@link !TypeError} if value is not an integer.
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```javascript
|
|
817
|
+
* // Set the 'shift-width' option.
|
|
818
|
+
* Rsvim.opt.shiftWidth = 4;
|
|
819
|
+
* ```
|
|
820
|
+
*/
|
|
821
|
+
set shiftWidth(value: number);
|
|
822
|
+
/**
|
|
823
|
+
* Get the _syntax-parser-lib-path_ option. Global option.
|
|
824
|
+
*
|
|
825
|
+
* By default the syntax parser libs are stored in `${RSVIM_CONFIG_HOME}/.tree-sitter-parsers` folder. `${RSVIM_CONFIG_HOME}` is the configuration home for rsvim.
|
|
826
|
+
*
|
|
827
|
+
* @see [Rsvim Configuration](https://rsvim.github.io/docs/manual/configuration)
|
|
828
|
+
*
|
|
829
|
+
* @returns {string}
|
|
830
|
+
*
|
|
831
|
+
* @defaultValue `${RSVIM_CONFIG_HOME}/.tree-sitter-parsers`
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```javascript
|
|
835
|
+
* // Get the 'syntax-parser-lib-path' option.
|
|
836
|
+
* const value = Rsvim.opt.syntaxParserLibPath;
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
839
|
+
get syntaxParserLibPath(): string;
|
|
840
|
+
/**
|
|
841
|
+
* Set the _syntax-parser-lib-path_ option. It only accepts a string which represents the file path on your local machine, which is used to save all compiled tree-sitter parser dynamic libraries.
|
|
842
|
+
*
|
|
843
|
+
* @param {string} value - The _syntax-parser-lib-path_ option.
|
|
844
|
+
* @throws Throws {@link !TypeError} if value is not an string.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* ```javascript
|
|
848
|
+
* // Set the 'syntax-parser-lib-path' option.
|
|
849
|
+
* Rsvim.opt.syntaxParserLibPath = ".";
|
|
850
|
+
* ```
|
|
851
|
+
*/
|
|
852
|
+
set syntaxParserLibPath(value: string);
|
|
853
|
+
/**
|
|
854
|
+
* Get the _tab-stop_ option. This option is also known as
|
|
855
|
+
* [tab-size](https://developer.mozilla.org/en-US/docs/Web/CSS/tab-size).
|
|
856
|
+
* Local to buffer.
|
|
857
|
+
*
|
|
858
|
+
* This option changes how text is displayed.
|
|
859
|
+
*
|
|
860
|
+
* Defines how many columns (on the terminal) used to display the
|
|
861
|
+
* [horizontal tab](https://en.wikipedia.org/wiki/Tab_key) (ASCII `9`). This value should be between `[1,255]`.
|
|
862
|
+
*
|
|
863
|
+
*
|
|
864
|
+
* @returns {number}
|
|
865
|
+
*
|
|
866
|
+
* @defaultValue `8`
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
869
|
+
* ```javascript
|
|
870
|
+
* // Get the 'tab-stop' option.
|
|
871
|
+
* const value = Rsvim.opt.tabStop;
|
|
872
|
+
* ```
|
|
873
|
+
*/
|
|
874
|
+
get tabStop(): number;
|
|
875
|
+
/**
|
|
876
|
+
* Set the _tab-stop_ option. It only accepts an integer between `[1,255]`, if the value is out of range, it will be bound to this range.
|
|
877
|
+
*
|
|
878
|
+
* @param {number} value - The _tab-stop_ option.
|
|
879
|
+
* @throws Throws {@link !TypeError} if value is not an integer.
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* ```javascript
|
|
883
|
+
* // Set the 'tab-stop' option.
|
|
884
|
+
* Rsvim.opt.tabStop = 4;
|
|
885
|
+
* ```
|
|
886
|
+
*/
|
|
887
|
+
set tabStop(value: number);
|
|
888
|
+
/**
|
|
889
|
+
* Get the _wrap_ option. This option is also known as
|
|
890
|
+
* [line wrap](https://en.wikipedia.org/wiki/Line_wrap_and_word_wrap). Local to window.
|
|
891
|
+
*
|
|
892
|
+
* This option changes how text is displayed.
|
|
893
|
+
*
|
|
894
|
+
* When `true`, lines longer than the width of the window will wrap and
|
|
895
|
+
* displaying continues on the next line. When `false` lines will not wrap
|
|
896
|
+
* and only part of long lines will be displayed. When the cursor is
|
|
897
|
+
* moved to a part that is not shown, the screen will scroll horizontally.
|
|
898
|
+
*
|
|
899
|
+
* The line will be broken in the middle of a word if necessary. See {@link lineBreak}
|
|
900
|
+
* to get the break at a word boundary.
|
|
901
|
+
*
|
|
902
|
+
* @returns {boolean}
|
|
903
|
+
*
|
|
904
|
+
* @defaultValue `true`
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* ```javascript
|
|
908
|
+
* // Get the 'wrap' option.
|
|
909
|
+
* const value = Rsvim.opt.wrap;
|
|
910
|
+
* ```
|
|
911
|
+
*/
|
|
912
|
+
get wrap(): boolean;
|
|
913
|
+
/**
|
|
914
|
+
* Set the _wrap_ option.
|
|
915
|
+
*
|
|
916
|
+
* @param {boolean} value - The _wrap_ option.
|
|
917
|
+
* @throws Throws {@link !TypeError} if value is not a boolean.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* ```javascript
|
|
921
|
+
* // Set the 'wrap' option.
|
|
922
|
+
* Rsvim.opt.wrap = true;
|
|
923
|
+
* ```
|
|
924
|
+
*/
|
|
925
|
+
set wrap(value: boolean);
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* The `Rsvim.proc` global object for child process.
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* ```javascript
|
|
932
|
+
* // Create a alias to 'Rsvim.proc'.
|
|
933
|
+
* const proc = Rsvim.proc;
|
|
934
|
+
* ```
|
|
935
|
+
*
|
|
936
|
+
* @category General APIs
|
|
937
|
+
*/
|
|
938
|
+
export declare namespace RsvimProc {
|
|
939
|
+
/**
|
|
940
|
+
* The command that create a child process.
|
|
941
|
+
*/
|
|
942
|
+
class Command {
|
|
943
|
+
#private;
|
|
944
|
+
constructor(execPath: string, options?: RsvimProc.CommandOptions);
|
|
945
|
+
get execPath(): string;
|
|
946
|
+
get options(): RsvimProc.CommandOptions;
|
|
947
|
+
/**
|
|
948
|
+
* Spawn a child process.
|
|
949
|
+
*
|
|
950
|
+
* @returns {RsvimProc.ChildProcess} It returns a child process.
|
|
951
|
+
* @throws Throws {@link !Error} if failed to spawn the child process.
|
|
952
|
+
*
|
|
953
|
+
* @example
|
|
954
|
+
* ```javascript
|
|
955
|
+
* try {
|
|
956
|
+
* const cmd = new Rsvim.proc.Command("ls");
|
|
957
|
+
* const child = cmd.spawn();
|
|
958
|
+
* } catch (e) {
|
|
959
|
+
* Rsvim.cmd.echo(`Failed to spawn child process: ${e}`);
|
|
960
|
+
* }
|
|
961
|
+
* ```
|
|
962
|
+
*/
|
|
963
|
+
spawn(): RsvimProc.ChildProcess;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Child process spawned from command.
|
|
967
|
+
*/
|
|
968
|
+
class ChildProcess {
|
|
969
|
+
#private;
|
|
970
|
+
/** @hideconstructor */
|
|
971
|
+
constructor(execPath: string, options: RsvimProc.CommandOptions, rid: number, stdinRid: number | null | undefined, stdoutRid: number | null | undefined, stderrRid: number | null | undefined);
|
|
972
|
+
get execPath(): string;
|
|
973
|
+
get options(): RsvimProc.CommandOptions;
|
|
974
|
+
get stdout(): RsvimProc.ChildProcessReadableStream | null | undefined;
|
|
975
|
+
get stderr(): RsvimProc.ChildProcessReadableStream | null | undefined;
|
|
976
|
+
/**
|
|
977
|
+
* Child process is already completed.
|
|
978
|
+
*
|
|
979
|
+
* @example
|
|
980
|
+
* ```javascript
|
|
981
|
+
* const child = new Rsvim.proc.Command("ls").spawn();
|
|
982
|
+
* {
|
|
983
|
+
* await using usedChild = child;
|
|
984
|
+
* Rsvim.cmd.echo(usedChild.isDisposed); // false
|
|
985
|
+
* }
|
|
986
|
+
* Rsvim.cmd.echo(usedChild.isDisposed); // true
|
|
987
|
+
* ```
|
|
988
|
+
*/
|
|
989
|
+
get isDisposed(): boolean;
|
|
990
|
+
/**
|
|
991
|
+
* Wait for the child process finish with `await using` API instead of `wait`.
|
|
992
|
+
*
|
|
993
|
+
* @returns {void} It returns nothing.
|
|
994
|
+
*/
|
|
995
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
996
|
+
/**
|
|
997
|
+
* Wait for child process complete.
|
|
998
|
+
*
|
|
999
|
+
* @returns {RsvimProc.ChildProcessExitStatus} It returns a child process exit status.
|
|
1000
|
+
* @throws Throws {@link !Error} if the child process is already finished, or failed to wait.
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```javascript
|
|
1004
|
+
* try {
|
|
1005
|
+
* const cmd = new Rsvim.proc.Command("ls");
|
|
1006
|
+
* const child = cmd.spawn();
|
|
1007
|
+
* const output = await child.stdout.text();
|
|
1008
|
+
* const exitStatus = await child.wait();
|
|
1009
|
+
* Rsvim.cmd.echo(`"ls" command is completed successfully: ${exitStatus.success}.`);
|
|
1010
|
+
* } catch (e) {
|
|
1011
|
+
* Rsvim.cmd.echo(`Failed to run "ls" command.`);
|
|
1012
|
+
* }
|
|
1013
|
+
* ```
|
|
1014
|
+
*/
|
|
1015
|
+
wait(): Promise<RsvimProc.ChildProcessExitStatus>;
|
|
1016
|
+
/**
|
|
1017
|
+
* Get child process exit status.
|
|
1018
|
+
*
|
|
1019
|
+
* @returns {RsvimProc.ChildProcessExitStatus | null | undefined} It returns exit status if the child process is already finished, otherwise it returns `null`.
|
|
1020
|
+
*
|
|
1021
|
+
* @example
|
|
1022
|
+
* ```javascript
|
|
1023
|
+
* const child = new Rsvim.proc.Command("ls").spawn();
|
|
1024
|
+
* await child.wait();
|
|
1025
|
+
* const exitStatus = child.exitStatus;
|
|
1026
|
+
* ```
|
|
1027
|
+
*/
|
|
1028
|
+
get exitStatus(): RsvimProc.ChildProcessExitStatus | null | undefined;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Child process readable stream.
|
|
1032
|
+
*/
|
|
1033
|
+
class ChildProcessReadableStream {
|
|
1034
|
+
#private;
|
|
1035
|
+
/** @hideconstructor */
|
|
1036
|
+
constructor(rid: number);
|
|
1037
|
+
/**
|
|
1038
|
+
* Read text from the stream.
|
|
1039
|
+
*
|
|
1040
|
+
* @returns {string} It returns the read text from child process stdio channel.
|
|
1041
|
+
* @throws Throws {@link !Error} if failed to read.
|
|
1042
|
+
*
|
|
1043
|
+
* @example
|
|
1044
|
+
* ```javascript
|
|
1045
|
+
* try {
|
|
1046
|
+
* const cmd = new Rsvim.proc.Command("ls");
|
|
1047
|
+
* const child = cmd.spawn();
|
|
1048
|
+
* const output = await child.stdout.text();
|
|
1049
|
+
* Rsvim.cmd.echo(`"ls" command output:${output}`);
|
|
1050
|
+
* } catch (e) {
|
|
1051
|
+
* Rsvim.cmd.echo(`Failed to run "ls" command.`);
|
|
1052
|
+
* }
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
text(): Promise<string>;
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Command options when creating a child-process command.
|
|
1059
|
+
*
|
|
1060
|
+
* @see {@link RsvimProc.Command}
|
|
1061
|
+
*/
|
|
1062
|
+
type CommandOptions = {
|
|
1063
|
+
/**
|
|
1064
|
+
* Command arguments.
|
|
1065
|
+
*
|
|
1066
|
+
* @defaultValue `[]`
|
|
1067
|
+
*/
|
|
1068
|
+
args?: string[];
|
|
1069
|
+
/**
|
|
1070
|
+
* Current working directory.
|
|
1071
|
+
*
|
|
1072
|
+
* @defaultValue `undefined`
|
|
1073
|
+
*/
|
|
1074
|
+
cwd?: string;
|
|
1075
|
+
/**
|
|
1076
|
+
* Whether to clear environment variables when the command creating a child-process.
|
|
1077
|
+
*
|
|
1078
|
+
* @defaultValue `false`
|
|
1079
|
+
*/
|
|
1080
|
+
clearEnv?: boolean;
|
|
1081
|
+
/**
|
|
1082
|
+
* Whether to detach spawned child process from current process (editor process).
|
|
1083
|
+
* This allows the spawned child process to continue running after current process exits.
|
|
1084
|
+
*
|
|
1085
|
+
* @defaultValue `false`
|
|
1086
|
+
*/
|
|
1087
|
+
detached?: boolean;
|
|
1088
|
+
/**
|
|
1089
|
+
* Environment variables to pass to the child-process.
|
|
1090
|
+
*
|
|
1091
|
+
* @defaultValue `{}`
|
|
1092
|
+
*/
|
|
1093
|
+
env?: Record<string, string | undefined | null>;
|
|
1094
|
+
/**
|
|
1095
|
+
* How `stdin` of spawned child process should be handled.
|
|
1096
|
+
*
|
|
1097
|
+
* @defaultValue `null`
|
|
1098
|
+
*/
|
|
1099
|
+
stdin?: "piped" | "inherit" | "null";
|
|
1100
|
+
/**
|
|
1101
|
+
* How `stdout` of spawned child process should be handled.
|
|
1102
|
+
*
|
|
1103
|
+
* @defaultValue `piped`
|
|
1104
|
+
*/
|
|
1105
|
+
stdout?: "piped" | "inherit" | "null";
|
|
1106
|
+
/**
|
|
1107
|
+
* How `stderr` of spawned child process should be handled.
|
|
1108
|
+
*
|
|
1109
|
+
* @defaultValue `piped`
|
|
1110
|
+
*/
|
|
1111
|
+
stderr?: "piped" | "inherit" | "null";
|
|
1112
|
+
};
|
|
1113
|
+
/**
|
|
1114
|
+
* Child process exit status.
|
|
1115
|
+
*
|
|
1116
|
+
* @see {@link RsvimProc.ChildProcess}
|
|
1117
|
+
*/
|
|
1118
|
+
type ChildProcessExitStatus = {
|
|
1119
|
+
/**
|
|
1120
|
+
* Exit successfully.
|
|
1121
|
+
*/
|
|
1122
|
+
success: boolean;
|
|
1123
|
+
/**
|
|
1124
|
+
* Exit code.
|
|
1125
|
+
*/
|
|
1126
|
+
exit?: number;
|
|
1127
|
+
/**
|
|
1128
|
+
* Terminated by signal.
|
|
1129
|
+
*/
|
|
1130
|
+
signal?: number;
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* The `Rsvim.rt` global object for javascript runtime (editor process).
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* ```javascript
|
|
1138
|
+
* // Create a alias to 'Rsvim.rt'.
|
|
1139
|
+
* const rt = Rsvim.rt;
|
|
1140
|
+
* ```
|
|
1141
|
+
*
|
|
1142
|
+
* @category General APIs
|
|
1143
|
+
*/
|
|
1144
|
+
export declare namespace RsvimRt {
|
|
1145
|
+
/**
|
|
1146
|
+
* Exit editor.
|
|
1147
|
+
*
|
|
1148
|
+
* :::tip
|
|
1149
|
+
* To ensure file system data safety, editor will wait for all the ongoing file write operations
|
|
1150
|
+
* to complete before actually exiting, however any new write requests will be rejected.
|
|
1151
|
+
* :::
|
|
1152
|
+
*
|
|
1153
|
+
* @param {exitCode?} exitCode - (Optional) The editor process exit with this exit code, by default with code `0`.
|
|
1154
|
+
*
|
|
1155
|
+
* @throws Throws {@link !TypeError} if `exitCode` is neither an integer nor `undefined`.
|
|
1156
|
+
*
|
|
1157
|
+
* @example
|
|
1158
|
+
* ```javascript
|
|
1159
|
+
* // Exit with default exit code `0`.
|
|
1160
|
+
* Rsvim.rt.exit();
|
|
1161
|
+
*
|
|
1162
|
+
* // Exit with error exit code `-1`.
|
|
1163
|
+
* Rsvim.rt.exit(-1);
|
|
1164
|
+
* ```
|
|
1165
|
+
*/
|
|
1166
|
+
function exit(exitCode?: number): void;
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* The `Rsvim.syn` global object for javascript runtime (editor process).
|
|
1170
|
+
*
|
|
1171
|
+
* @example
|
|
1172
|
+
* ```javascript
|
|
1173
|
+
* // Create a alias to 'Rsvim.syn'.
|
|
1174
|
+
* const syn = Rsvim.syn;
|
|
1175
|
+
* ```
|
|
1176
|
+
*
|
|
1177
|
+
* @category Editor APIs
|
|
1178
|
+
*/
|
|
1179
|
+
export declare namespace RsvimSyn {
|
|
1180
|
+
/**
|
|
1181
|
+
* Load tree-sitter parsers.
|
|
1182
|
+
*
|
|
1183
|
+
* @see [tree-sitter - List of parsers](https://github.com/tree-sitter/tree-sitter/wiki/List-of-parsers)
|
|
1184
|
+
*
|
|
1185
|
+
* @param {RsvimSyn.LoadParserOptions} options - Load options.
|
|
1186
|
+
*
|
|
1187
|
+
* @returns {string[]} It returns all the loaded parser names.
|
|
1188
|
+
*
|
|
1189
|
+
* @throws Throws {@link !TypeError} if `options` is an invalid option, throws {@link !Error} if failed to load.
|
|
1190
|
+
*
|
|
1191
|
+
* @example
|
|
1192
|
+
* ```javascript
|
|
1193
|
+
* // Load `tree-sitter-c` parser.
|
|
1194
|
+
* const parserNames = await Rsvim.syn.loadParser({grammarPath: "./tree-sitter-c"});
|
|
1195
|
+
* Rsvim.cmd.echo(`Loaded parsers: ${parserNames}`);
|
|
1196
|
+
* ```
|
|
1197
|
+
*/
|
|
1198
|
+
function loadParser(options: RsvimSyn.LoadParserOptions): Promise<string[]>;
|
|
1199
|
+
/**
|
|
1200
|
+
* Load tree-sitter parsers synchronizely.
|
|
1201
|
+
*
|
|
1202
|
+
* @see {@link loadParser}
|
|
1203
|
+
*
|
|
1204
|
+
* @param {RsvimSyn.LoadParserOptions} options - Load options.
|
|
1205
|
+
*
|
|
1206
|
+
* @returns {string[]} It returns all the loaded parser names.
|
|
1207
|
+
*
|
|
1208
|
+
* @throws Throws {@link !TypeError} if `options` is an invalid option, throws {@link !Error} if failed to load.
|
|
1209
|
+
*
|
|
1210
|
+
* @example
|
|
1211
|
+
* ```javascript
|
|
1212
|
+
* // Load `tree-sitter-c` parser synchronizely.
|
|
1213
|
+
* const parserNames = Rsvim.syn.loadParserSync({grammarPath: "./tree-sitter-c"});
|
|
1214
|
+
* Rsvim.cmd.echo(`Loaded parsers: ${parserNames}`);
|
|
1215
|
+
* ```
|
|
1216
|
+
*/
|
|
1217
|
+
function loadParserSync(options: RsvimSyn.LoadParserOptions): string[];
|
|
1218
|
+
/**
|
|
1219
|
+
* List all loaded tree-sitter parsers.
|
|
1220
|
+
*
|
|
1221
|
+
* @returns {string[]} It returns all the loaded parser names.
|
|
1222
|
+
*
|
|
1223
|
+
* @example
|
|
1224
|
+
* ```javascript
|
|
1225
|
+
* // Print all loaded parser names.
|
|
1226
|
+
* const allParserNames = Rsvim.syn.listParsers();
|
|
1227
|
+
* Rsvim.cmd.echo(`All loaded parsers: ${allParserNames}`);
|
|
1228
|
+
* ```
|
|
1229
|
+
*/
|
|
1230
|
+
function listParsers(): string[];
|
|
1231
|
+
/**
|
|
1232
|
+
* Get tree-sitter parser metadata by parser name.
|
|
1233
|
+
*
|
|
1234
|
+
* @param {string} name - The parser's name.
|
|
1235
|
+
*
|
|
1236
|
+
* @returns {RsvimSyn.ParserMetadata | undefined} It returns all the loaded parser names.
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```javascript
|
|
1240
|
+
* // Get parser metadata by name.
|
|
1241
|
+
* const parserMetadata = Rsvim.syn.getParserMetadata("rust");
|
|
1242
|
+
* Rsvim.cmd.echo(`Rust parser metadata: ${parserMetadata}`);
|
|
1243
|
+
* ```
|
|
1244
|
+
*/
|
|
1245
|
+
function getParserMetadata(name: string): RsvimSyn.ParserMetadata | undefined;
|
|
1246
|
+
/**
|
|
1247
|
+
* Options to load a tree-sitter parser.
|
|
1248
|
+
*
|
|
1249
|
+
* @see {@link RsvimSyn.loadParser}
|
|
1250
|
+
*/
|
|
1251
|
+
type LoadParserOptions = {
|
|
1252
|
+
/**
|
|
1253
|
+
* The tree-sitter parser path to load.
|
|
1254
|
+
*/
|
|
1255
|
+
grammarPath: string;
|
|
1256
|
+
};
|
|
1257
|
+
/**
|
|
1258
|
+
* Tree-sitter parser metadata.
|
|
1259
|
+
*
|
|
1260
|
+
* @see {@link RsvimSyn.getParserMetadata}
|
|
1261
|
+
*/
|
|
1262
|
+
type ParserMetadata = {
|
|
1263
|
+
/**
|
|
1264
|
+
* The tree-sitter parser name.
|
|
1265
|
+
*/
|
|
1266
|
+
name: string;
|
|
1267
|
+
/**
|
|
1268
|
+
* The tree-sitter parser name's camelcase.
|
|
1269
|
+
*/
|
|
1270
|
+
camelcase: string;
|
|
1271
|
+
/**
|
|
1272
|
+
* The tree-sitter parser scope.
|
|
1273
|
+
*/
|
|
1274
|
+
scope: string;
|
|
1275
|
+
/**
|
|
1276
|
+
* The tree-sitter parser path.
|
|
1277
|
+
*/
|
|
1278
|
+
path: string;
|
|
1279
|
+
/**
|
|
1280
|
+
* The tree-sitter parser file types.
|
|
1281
|
+
*/
|
|
1282
|
+
fileTypes: string[];
|
|
1283
|
+
/**
|
|
1284
|
+
* The tree-sitter parser highlights query path.
|
|
1285
|
+
*/
|
|
1286
|
+
highlightsPath?: string;
|
|
1287
|
+
/**
|
|
1288
|
+
* The tree-sitter parser highlights query.
|
|
1289
|
+
*/
|
|
1290
|
+
highlightsQuery?: string;
|
|
1291
|
+
/**
|
|
1292
|
+
* The tree-sitter parser tags query path.
|
|
1293
|
+
*/
|
|
1294
|
+
tagsPath?: string;
|
|
1295
|
+
/**
|
|
1296
|
+
* The tree-sitter parser tags query.
|
|
1297
|
+
*/
|
|
1298
|
+
tagsQuery?: string;
|
|
1299
|
+
/**
|
|
1300
|
+
* The tree-sitter parser injections query path.
|
|
1301
|
+
*/
|
|
1302
|
+
injectionsPath?: string;
|
|
1303
|
+
/**
|
|
1304
|
+
* The tree-sitter parser injections query.
|
|
1305
|
+
*/
|
|
1306
|
+
injectionsQuery?: string;
|
|
1307
|
+
/**
|
|
1308
|
+
* The tree-sitter parser injection regex.
|
|
1309
|
+
*/
|
|
1310
|
+
injectionRegex?: string;
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* The `Rsvim` global object.
|
|
1315
|
+
*
|
|
1316
|
+
* @example
|
|
1317
|
+
* ```javascript
|
|
1318
|
+
* // Create a alias to 'Rsvim'.
|
|
1319
|
+
* const vim = Rsvim;
|
|
1320
|
+
* ```
|
|
1321
|
+
*
|
|
1322
|
+
* @category Global Object
|
|
1323
|
+
*/
|
|
1324
|
+
export declare namespace Rsvim {
|
|
1325
|
+
export import buf = RsvimBuf;
|
|
1326
|
+
export import cmd = RsvimCmd;
|
|
1327
|
+
export import fs = RsvimFs;
|
|
1328
|
+
const opt: RsvimOpt;
|
|
1329
|
+
export import proc = RsvimProc;
|
|
1330
|
+
export import rt = RsvimRt;
|
|
1331
|
+
export import syn = RsvimSyn;
|
|
1332
|
+
}
|
|
1333
|
+
declare global {
|
|
1334
|
+
var Rsvim: typeof Rsvim;
|
|
1335
|
+
}
|