@@ -4,6 +4,14 @@ import { autocmd, AutocmdHelper } from "./autocmd.ts";
44import { VariableHelper } from "./variable.ts" ;
55import { load } from "./load.ts" ;
66
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+ */
715export class Vim {
816 private static instance ?: Vim ;
917
@@ -24,47 +32,93 @@ export class Vim {
2432 this . v = new VariableHelper ( denops , "v" ) ;
2533 }
2634
35+ /**
36+ * Get thread-local Vim instance.
37+ */
2738 static get ( ) : Vim {
2839 if ( ! Vim . instance ) {
2940 Vim . instance = new Vim ( Denops . get ( ) ) ;
3041 }
3142 return Vim . instance ;
3243 }
3344
45+ /**
46+ * Plugin name
47+ */
3448 get name ( ) : string {
3549 return this . #denops. name ;
3650 }
3751
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+ */
3858 async call ( func : string , ...args : unknown [ ] ) : Promise < unknown > {
3959 return await this . #denops. call ( func , ...args ) ;
4060 }
4161
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 ) ;
4470 }
4571
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 ) ;
4880 }
4981
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+ */
5088 async execute (
51- command : string | string [ ] ,
52- context : Context = { } ,
89+ script : string | string [ ] ,
90+ ctx : Context = { } ,
5391 ) : Promise < void > {
54- await execute ( this . #denops, command , context ) ;
92+ await execute ( this . #denops, script , ctx ) ;
5593 }
5694
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+ */
57101 async autocmd (
58102 group : string ,
59103 main : ( helper : AutocmdHelper ) => void ,
60104 ) : Promise < void > {
61105 await autocmd ( this . #denops, group , main ) ;
62106 }
63107
108+ /**
109+ * Load an arbitrary Vim script from local or remote.
110+ *
111+ * @param url: An URL to locate the target Vim script.
112+ */
64113 async load ( url : URL ) : Promise < void > {
65114 await load ( this . #denops, url ) ;
66115 }
67116
117+ /**
118+ * Register plugin APIs
119+ *
120+ * @param dispatcher: A collection of the plugin APIs
121+ */
68122 register ( dispatcher : Dispatcher ) : void {
69123 this . #denops. extendDispatcher ( dispatcher ) ;
70124 }
0 commit comments