Skip to content

Commit e8c04a2

Browse files
committed
Add Vim.get() to get singleton for 3rd parties
1 parent f1f93e5 commit e8c04a2

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export type {
22
Context,
33
Dispatcher,
44
} from "https://deno.land/x/denops@v0.7/mod.ts";
5-
export { Denops } from "https://deno.land/x/denops@v0.7/mod.ts";
5+
export { Denops, getCacheOrElse } from "https://deno.land/x/denops@v0.7/mod.ts";

mod.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
export * from "./autocmd.ts";
2-
export * from "./execute.ts";
3-
export * from "./variable.ts";
4-
export * from "./vim.ts";
1+
export { start, Vim } from "./vim/mod.ts";

autocmd.ts renamed to vim/autocmd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Denops } from "./deps.ts";
1+
import { Denops } from "../deps.ts";
22
import { execute } from "./execute.ts";
33

44
export async function autocmd(

execute.ts renamed to vim/execute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Context, Denops } from "./deps.ts";
1+
import { Context, Denops } from "../deps.ts";
22

33
/**
44
* Execute Vim script directly

vim/mod.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from "./autocmd.ts";
2+
export * from "./execute.ts";
3+
export * from "./variable.ts";
4+
export * from "./vim.ts";

variable.ts renamed to vim/variable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Denops } from "./deps.ts";
1+
import { Denops } from "../deps.ts";
22

33
/**
44
* Vim variable groups

vim.ts renamed to vim/vim.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Context, Denops, Dispatcher } from "./deps.ts";
1+
import { Context, Denops, Dispatcher, getCacheOrElse } from "../deps.ts";
22
import { execute } from "./execute.ts";
33
import { autocmd, AutocmdHelper } from "./autocmd.ts";
44
import { VariableHelper } from "./variable.ts";
@@ -23,6 +23,12 @@ export class Vim {
2323
this.env = new VariableHelper(denops, "env");
2424
}
2525

26+
static get(): Vim {
27+
return getCacheOrElse("vim", () => {
28+
return new Vim(Denops.get());
29+
});
30+
}
31+
2632
get name(): string {
2733
return this.#denops.name;
2834
}
@@ -59,8 +65,5 @@ export class Vim {
5965
}
6066

6167
export function start(main: (vim: Vim) => Promise<void>) {
62-
Denops.start(async (denops) => {
63-
const vim = new Vim(denops);
64-
await main(vim);
65-
});
68+
Denops.start(() => main(Vim.get()));
6669
}

0 commit comments

Comments
 (0)