Skip to content

Commit 4470ee2

Browse files
authored
Merge pull request #173 from vim-denops/fix-docs
📝 Improve documentation on deno doc
2 parents e0dcbf9 + 25ac118 commit 4470ee2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1871
-1786
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
used in denops plugin and the code is assumed to be called in a worker thread
1212
for a plugin.
1313

14-
See [Module README](./denops_std/README.md) for quick usage and API
15-
documentations and see
14+
See [deno doc](https://doc.deno.land/https/deno.land/x/denops_std/mod.ts) for
15+
quick usage and API documentations and see
1616
[Denops Documentation](https://vim-denops.github.io/denops-documentation/) for
1717
learning how to write Vim/Neovim plugins.
1818

denops_std/README.md

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,7 @@
55
[![Documentation](https://img.shields.io/badge/denops-Documentation-yellow.svg)](https://vim-denops.github.io/denops-documentation/)
66
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x/denops__std-lightgrey.svg?logo=deno)](https://deno.land/x/denops_std)
77

8-
[Deno][deno] module for [denops.vim][denops.vim]. This module is assumed to be
9-
used in denops plugin and the code is assumed to be called in a worker thread
10-
for a plugin.
11-
12-
By using this module, developers can write Vim/Neovim denops plugins like:
13-
14-
```typescript
15-
import { Denops } from "./mod.ts";
16-
import * as fn from "./function/mod.ts";
17-
import * as vars from "./variable/mod.ts";
18-
import * as helper from "./helper/mod.ts";
19-
20-
import { assertString } from "https://deno.land/x/unknownutil/mod.ts";
21-
22-
export async function main(denops: Denops): Promise<void> {
23-
denops.dispatcher = {
24-
async say(where: unknown): Promise<void> {
25-
// Ensure that `where` is `string` here
26-
assertString(where);
27-
const name = await fn.input(denops, "Your name: ");
28-
const progname = await vars.v.get(denops, "progname");
29-
const messages = [
30-
`Hello ${where}.`,
31-
`Your name is ${name}.`,
32-
`This is ${progname}.`,
33-
];
34-
await helper.echo(denops, messages.join("\n"));
35-
},
36-
};
37-
38-
await helper.execute(
39-
denops,
40-
`
41-
command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])
42-
command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])
43-
`,
44-
);
45-
}
46-
```
47-
48-
See [Denops Documentation](https://vim-denops.github.io/denops-documentation/)
49-
or [denops-helloworld.vim](https://github.com/vim-denops/denops-helloworld.vim)
50-
for more details.
8+
[Deno][deno] module for [denops.vim][denops.vim].
519

5210
[deno]: https://deno.land/
5311
[denops.vim]: https://github.com/vim-denops/denops.vim
54-
55-
## Index
56-
57-
| Name | Description |
58-
| -------------------------- | ---------------------------------------------------------------------- |
59-
| [`anonymous`](./anonymous) | A module to provide anonymous function |
60-
| [`argument`](./argument) | A module to provide helper functions to manage Vim's command arguments |
61-
| [`autocmd`](./autocmd) | A module to provide helper functions to manage `autocmd` |
62-
| [`batch`](./batch) | A module to provide wrapper functions of `denops.batch()` |
63-
| [`buffer`](./buffer) | A module to provide helper functions to manage buffers |
64-
| [`bufname`](./bufname) | A module to provide helper functions to manage Vim's buffer name |
65-
| [`function`](./function) | A module to provide functions of Vim and Neovim native functions |
66-
| [`helper`](./helper) | A module to provide helper functions |
67-
| [`mapping`](./mapping) | A module to provide helper functions to manage mappings |
68-
| [`option`](./option) | A module to provide helper functions to manage options |
69-
| [`variable`](./variable) | A module to provide helper accessor functions to variables |

denops_std/anonymous/README.md

Lines changed: 0 additions & 104 deletions
This file was deleted.

denops_std/anonymous/mod.ts

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* A module to provide anonymous function which is callable from
3+
* outside of the plugin (Vim or other plugins.)
4+
*
5+
* @module
6+
*/
17
import type { Denops } from "https://deno.land/x/denops_core@v3.4.1/mod.ts";
28

39
// https://github.com/microsoft/TypeScript/issues/26223#issuecomment-674500430
@@ -19,7 +25,36 @@ export type Identifier = string;
1925
export type Callback = (...args: unknown[]) => Promise<unknown> | unknown;
2026

2127
/**
22-
* Add anonymous functions as a denops API and return the identifiers
28+
* Add anonymous functions as denops API and return the identifiers
29+
*
30+
* ```typescript
31+
* import { Denops } from "../mod.ts";
32+
* import * as anonymous from "./mod.ts";
33+
*
34+
* export async function main(denops: Denops): Promise<void> {
35+
* // Add anonymous functions
36+
* const ids = anonymous.add(
37+
* denops,
38+
* () => {
39+
* // Do what ever you want.
40+
* },
41+
* () => {
42+
* // Do what ever you want.
43+
* },
44+
* // You can add as many callbacks as you want...
45+
* );
46+
*
47+
* // Use ids to dispatch added functions from Deno
48+
* await denops.dispatch(denops.name, ids[0]);
49+
* await denops.dispatch(denops.name, ids[1]);
50+
*
51+
* // Or from Vim
52+
* await denops.cmd("call denops#notify(name, id, [])", {
53+
* name: denops.name,
54+
* id: ids[1],
55+
* });
56+
* }
57+
* ```
2358
*/
2459
export function add<N extends number>(
2560
denops: Denops,
@@ -36,7 +71,33 @@ export function add<N extends number>(
3671
}
3772

3873
/**
39-
* Add oneshot anonymous functions as a denops API and return the identifiers
74+
* Add oneshot anonymous functions as denops API and return the identifiers
75+
*
76+
* ```typescript
77+
* import { Denops } from "../mod.ts";
78+
* import * as anonymous from "./mod.ts";
79+
*
80+
* export async function main(denops: Denops): Promise<void> {
81+
* // Add anonymous functions
82+
* const ids = anonymous.once(
83+
* denops,
84+
* () => {
85+
* // Do what ever you want.
86+
* },
87+
* () => {
88+
* // Do what ever you want.
89+
* },
90+
* // You can add as many callbacks as you want...
91+
* );
92+
*
93+
* // First calls complete normally
94+
* await denops.dispatch(denops.name, ids[0]);
95+
* await denops.dispatch(denops.name, ids[1]);
96+
*
97+
* // But second call would throw errors
98+
* await denops.dispatch(denops.name, ids[0]);
99+
* }
100+
* ```
40101
*/
41102
export function once<N extends number>(
42103
denops: Denops,
@@ -57,7 +118,35 @@ export function once<N extends number>(
57118
}
58119

59120
/**
60-
* Remove anonymous functions identified by names from a denops API
121+
* Remove anonymous functions from denops API identified by the identifiers
122+
*
123+
* ```typescript
124+
* import { Denops } from "../mod.ts";
125+
* import * as anonymous from "./mod.ts";
126+
*
127+
* export async function main(denops: Denops): Promise<void> {
128+
* // Add anonymous functions
129+
* const ids = anonymous.add(
130+
* denops,
131+
* () => {
132+
* // Do what ever you want.
133+
* },
134+
* () => {
135+
* // Do what ever you want.
136+
* },
137+
* // You can add as many callbacks as you want...
138+
* );
139+
*
140+
* // Remove ids[1]
141+
* anonymous.remove(denops, ids[1]);
142+
*
143+
* // Call of ids[0] complete normally
144+
* await denops.dispatch(denops.name, ids[0]);
145+
*
146+
* // But ids[1] is already removed
147+
* await denops.dispatch(denops.name, ids[1]);
148+
* }
149+
* ```
61150
*/
62151
export function remove<N extends number>(
63152
denops: Denops,

0 commit comments

Comments
 (0)