Skip to content

Commit 861632d

Browse files
authored
Merge pull request #13 from vim-denops/add-main
Add 'main()' and deprecate 'start()'
2 parents 9074940 + 4ca8f76 commit 861632d

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

deps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type {
22
Context,
33
Dispatcher,
4-
} from "https://deno.land/x/denops_core@v0.10.0/mod.ts";
5-
export { Denops } from "https://deno.land/x/denops_core@v0.10.0/mod.ts";
4+
} from "https://deno.land/x/denops_core@v0.11.0/mod.ts";
5+
export { Denops } from "https://deno.land/x/denops_core@v0.11.0/mod.ts";

deps_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "https://deno.land/std@0.92.0/testing/asserts.ts";
1+
export * from "https://deno.land/std@0.93.0/testing/asserts.ts";

main.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Denops } from "./deps.ts";
2+
import { Vim } from "./vim/mod.ts";
3+
4+
export interface RunnerContext {
5+
denops: Denops;
6+
vim: Vim;
7+
}
8+
9+
/**
10+
* Define a plugin main function which starts denops mainloop for the plugin
11+
*/
12+
export function main(runner: (context: RunnerContext) => Promise<void>) {
13+
Denops.start(async (denops) => {
14+
const vim = Vim.get();
15+
const ctx: RunnerContext = {
16+
denops,
17+
vim,
18+
};
19+
await runner(ctx);
20+
});
21+
}

mod.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export { start, Vim } from "./vim/mod.ts";
1+
export { Vim } from "./vim/mod.ts";
2+
export { main } from "./main.ts";
3+
4+
// Deprecated APIs
5+
export { start } from "./vim/mod.ts";

vim/vim.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ export class Vim {
6565
}
6666
}
6767

68+
/**
69+
* Define a plugin main function which starts denops mainloop for the plugin
70+
* @deprecated Use `main` function instead.
71+
*/
6872
export function start(main: (vim: Vim) => Promise<void>) {
69-
Denops.start(() => main(Vim.get()));
73+
Denops.start(async () => {
74+
const vim = Vim.get();
75+
console.warn(
76+
`${vim.name}: The 'start()' is deprecated since denops_std@v0.8.`,
77+
);
78+
console.warn(
79+
`${vim.name}: Use 'main()' instead to launch a plugin like:`,
80+
);
81+
console.warn(`${vim.name}:`);
82+
console.warn(`${vim.name}: main(async ({ vim }) => {`);
83+
console.warn(`${vim.name}: vim.register({`);
84+
console.warn(`${vim.name}: // ...`);
85+
console.warn(`${vim.name}: });`);
86+
console.warn(`${vim.name}: });`);
87+
console.warn(`${vim.name}:`);
88+
await main(vim);
89+
});
7090
}

0 commit comments

Comments
 (0)