Skip to content

Commit 3b23adc

Browse files
authored
Merge pull request #16 from vim-denops/follow-latest
Update deps to latest
2 parents 915fbee + d2f2ac1 commit 3b23adc

File tree

6 files changed

+125
-24
lines changed

6 files changed

+125
-24
lines changed

README.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
1-
# 🐜 denops-std-deno
1+
# 🐜 denops_std
22

3-
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/denops_std/mod.ts)
43
[![deno](https://github.com/vim-denops/denops-std-deno/workflows/deno/badge.svg)](https://github.com/vim-denops/denops-std-deno/actions?query=workflow%3Adeno)
4+
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/denops_std/mod.ts)
5+
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/denops_std)
56

67
[Deno][deno] module for [denops.vim][denops.vim]. This module is assumed to be
78
used in denops plugin and the code is assumed to be called in a worker thread
89
for a plugin.
910

10-
Note that this module focused to provide non-primitive features. See
11-
[denops-deno](https://github.com/vim-denops/denops-deno) for primitives.
12-
1311
**UNDER DEVELOPMENT**
1412

13+
By using this module, developers can write Vim/Neovim denops plugins like:
14+
15+
```typescript
16+
import { ensureString, main } from "https://deno.land/x/denops_std/mod.ts";
17+
18+
main(async ({ vim }) => {
19+
vim.register({
20+
async say(where: unknown): Promise<void> {
21+
ensureString(where, "where");
22+
const name = await vim.call("input", "Your name: ");
23+
const progname = await vim.eval("v:progname");
24+
const messages = [
25+
`Hello ${where}`,
26+
`Your name is ${name}`,
27+
`This is ${progname}`,
28+
];
29+
await vim.cmd(`redraw | echomsg message`, {
30+
message: messages.join(". "),
31+
});
32+
},
33+
});
34+
35+
await vim.execute(`
36+
command! HelloWorld call denops#notify("${vim.name}", "say", ["World"])
37+
command! HelloDenops call denops#notify("${vim.name}", "say", ["Denops"])
38+
`);
39+
40+
console.log("denops plugin has loaded");
41+
});
42+
```
43+
44+
See [denops-helloworld.vim](https://github.com/denops-helloworld.vim) for more
45+
details.
46+
1547
[deno]: https://deno.land/
1648
[denops.vim]: https://github.com/vim-denops/denops.vim
1749

deps.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@ export * as fs from "https://deno.land/std@0.95.0/fs/mod.ts";
55
export type {
66
Context,
77
Dispatcher,
8-
} from "https://deno.land/x/denops_core@v0.11.0/mod.ts";
9-
export { Denops } from "https://deno.land/x/denops_core@v0.11.0/mod.ts";
8+
} from "https://deno.land/x/denops_core@v0.13.0/mod.ts";
9+
export {
10+
Denops,
11+
ensureArray,
12+
ensureNumber,
13+
ensureRecord,
14+
ensureString,
15+
} from "https://deno.land/x/denops_core@v0.13.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.93.0/testing/asserts.ts";
1+
export * from "https://deno.land/std@0.95.0/testing/asserts.ts";

mod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
export { Vim } from "./vim/mod.ts";
22
export { main } from "./main.ts";
33

4+
// Re-export
5+
export {
6+
Denops,
7+
ensureArray,
8+
ensureNumber,
9+
ensureRecord,
10+
ensureString,
11+
} from "./deps.ts";
12+
413
// Deprecated APIs
514
export { start } from "./vim/mod.ts";

vim/execute.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { Context, Denops } from "../deps.ts";
55
*/
66
export async function execute(
77
denops: Denops,
8-
command: string | string[],
9-
context: Context = {},
8+
script: string | string[],
9+
ctx: Context = {},
1010
): Promise<void> {
11-
if (Array.isArray(command)) {
12-
context = {
13-
...context,
14-
__denops_internal_command: command
11+
if (Array.isArray(script)) {
12+
ctx = {
13+
...ctx,
14+
__denops_internal_command: script
1515
.map((x) => x.replace(/^\s+|\s+$/g, ""))
1616
.filter((x) => !!x),
1717
};
18-
await denops.cmd("call execute(l:__denops_internal_command, '')", context);
18+
await denops.cmd("call execute(l:__denops_internal_command, '')", ctx);
1919
return;
2020
}
21-
command = command.replace(/\r?\n\s*\\/g, "");
22-
await execute(denops, command.split(/\r?\n/g), context);
21+
script = script.replace(/\r?\n\s*\\/g, "");
22+
await execute(denops, script.split(/\r?\n/g), ctx);
2323
}

vim/vim.ts

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { autocmd, AutocmdHelper } from "./autocmd.ts";
44
import { VariableHelper } from "./variable.ts";
55
import { 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+
*/
715
export 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

Comments
 (0)