@@ -4,6 +4,14 @@ import { autocmd, AutocmdHelper } from "./autocmd.ts";
4
4
import { VariableHelper } from "./variable.ts" ;
5
5
import { load } from "./load.ts" ;
6
6
7
+ /**
8
+ * Vim is a facade instance visible from each denops plugins for
9
+ *
10
+ * 1. Communicate with other plugins
11
+ * 2. Communicate with the host (Vim/Neovim)
12
+ * 3. Register them msgpack-rpc APIs
13
+ *
14
+ */
7
15
export class Vim {
8
16
private static instance ?: Vim ;
9
17
@@ -24,47 +32,93 @@ export class Vim {
24
32
this . v = new VariableHelper ( denops , "v" ) ;
25
33
}
26
34
35
+ /**
36
+ * Get thread-local Vim instance.
37
+ */
27
38
static get ( ) : Vim {
28
39
if ( ! Vim . instance ) {
29
40
Vim . instance = new Vim ( Denops . get ( ) ) ;
30
41
}
31
42
return Vim . instance ;
32
43
}
33
44
45
+ /**
46
+ * Plugin name
47
+ */
34
48
get name ( ) : string {
35
49
return this . #denops. name ;
36
50
}
37
51
52
+ /**
53
+ * Call an arbitrary function of Vim/Neovim and return the result
54
+ *
55
+ * @param fn: A function name of Vim/Neovim.
56
+ * @param args: Arguments of the function.
57
+ */
38
58
async call ( func : string , ...args : unknown [ ] ) : Promise < unknown > {
39
59
return await this . #denops. call ( func , ...args ) ;
40
60
}
41
61
42
- async cmd ( cmd : string , context : Context = { } ) : Promise < void > {
43
- await this . #denops. cmd ( cmd , context ) ;
62
+ /**
63
+ * Execute an arbitrary command of Vim/Neovim under a given context.
64
+ *
65
+ * @param cmd: A command expression to be executed.
66
+ * @param ctx: A context object which is expanded to the local namespace (l:)
67
+ */
68
+ async cmd ( cmd : string , ctx : Context = { } ) : Promise < void > {
69
+ await this . #denops. cmd ( cmd , ctx ) ;
44
70
}
45
71
46
- async eval ( expr : string , context : Context = { } ) : Promise < unknown > {
47
- return await this . #denops. eval ( expr , context ) ;
72
+ /**
73
+ * Evaluate an arbitrary expression of Vim/Neovim under a given context and return the result.
74
+ *
75
+ * @param expr: An expression to be evaluated.
76
+ * @param ctx: A context object which is expanded to the local namespace (l:)
77
+ */
78
+ async eval ( expr : string , ctx : Context = { } ) : Promise < unknown > {
79
+ return await this . #denops. eval ( expr , ctx ) ;
48
80
}
49
81
82
+ /**
83
+ * Execute an arbitrary Vim script under a given context.
84
+ *
85
+ * @param script: A script to be executed. Can be string or string list.
86
+ * @param ctx: A context object which is expanded to the local namespace (l:)
87
+ */
50
88
async execute (
51
- command : string | string [ ] ,
52
- context : Context = { } ,
89
+ script : string | string [ ] ,
90
+ ctx : Context = { } ,
53
91
) : Promise < void > {
54
- await execute ( this . #denops, command , context ) ;
92
+ await execute ( this . #denops, script , ctx ) ;
55
93
}
56
94
95
+ /**
96
+ * Define autocmd in autocmd group.
97
+ *
98
+ * @param group: An autocmd group name.
99
+ * @param main: A function which is used to define autocmds.
100
+ */
57
101
async autocmd (
58
102
group : string ,
59
103
main : ( helper : AutocmdHelper ) => void ,
60
104
) : Promise < void > {
61
105
await autocmd ( this . #denops, group , main ) ;
62
106
}
63
107
108
+ /**
109
+ * Load an arbitrary Vim script from local or remote.
110
+ *
111
+ * @param url: An URL to locate the target Vim script.
112
+ */
64
113
async load ( url : URL ) : Promise < void > {
65
114
await load ( this . #denops, url ) ;
66
115
}
67
116
117
+ /**
118
+ * Register plugin APIs
119
+ *
120
+ * @param dispatcher: A collection of the plugin APIs
121
+ */
68
122
register ( dispatcher : Dispatcher ) : void {
69
123
this . #denops. extendDispatcher ( dispatcher ) ;
70
124
}
0 commit comments