1
- import { Context , Denops , Dispatcher } from "./deps.ts" ;
1
+ import { Context , Denops , Dispatcher , getCacheOrElse } from ". ./deps.ts" ;
2
2
import { execute } from "./execute.ts" ;
3
3
import { autocmd , AutocmdHelper } from "./autocmd.ts" ;
4
4
import { VariableHelper } from "./variable.ts" ;
@@ -23,6 +23,12 @@ export class Vim {
23
23
this . env = new VariableHelper ( denops , "env" ) ;
24
24
}
25
25
26
+ static get ( ) : Vim {
27
+ return getCacheOrElse ( "vim" , ( ) => {
28
+ return new Vim ( Denops . get ( ) ) ;
29
+ } ) ;
30
+ }
31
+
26
32
get name ( ) : string {
27
33
return this . #denops. name ;
28
34
}
@@ -39,8 +45,11 @@ export class Vim {
39
45
return await this . #denops. eval ( expr , context ) ;
40
46
}
41
47
42
- async execute ( command : string | string [ ] ) : Promise < void > {
43
- await execute ( this . #denops, command ) ;
48
+ async execute (
49
+ command : string | string [ ] ,
50
+ context : Context = { } ,
51
+ ) : Promise < void > {
52
+ await execute ( this . #denops, command , context ) ;
44
53
}
45
54
46
55
async autocmd (
@@ -56,8 +65,5 @@ export class Vim {
56
65
}
57
66
58
67
export function start ( main : ( vim : Vim ) => Promise < void > ) {
59
- Denops . start ( async ( denops ) => {
60
- const vim = new Vim ( denops ) ;
61
- await main ( vim ) ;
62
- } ) ;
68
+ Denops . start ( ( ) => main ( Vim . get ( ) ) ) ;
63
69
}
0 commit comments