Skip to content

Commit 9344551

Browse files
committed
📝 Improve documentation comments
1 parent 727dcfc commit 9344551

File tree

19 files changed

+243
-79
lines changed

19 files changed

+243
-79
lines changed

autocmd/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ export type AutocmdEvent =
119119
| "WinNew"
120120
| "WinScrolled";
121121

122-
type CommonOptions = {
122+
interface CommonOptions {
123123
group?: string;
124-
};
124+
}
125125

126-
export type DefineOptions = CommonOptions & {
126+
export interface DefineOptions extends CommonOptions {
127127
once?: boolean;
128128
nested?: boolean;
129-
};
129+
}
130130

131131
export type RemoveOptions = CommonOptions;
132132

133133
export type ListOptions = CommonOptions;
134134

135-
export type EmitOptions = CommonOptions & {
135+
export interface EmitOptions extends CommonOptions {
136136
nomodeline?: boolean;
137-
};
137+
}

batch/batch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class BatchHelper implements Denops {
9494
*
9595
* ```typescript
9696
* import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts";
97-
* import { batch } from "./batch.ts";
97+
* import { batch } from "https://deno.land/x/denops_std@$MODULE_VERSION/batch/mod.ts";
9898
*
9999
* export async function main(denops: Denops): Promise<void> {
100100
* await batch(denops, async (denops) => {
@@ -110,7 +110,7 @@ class BatchHelper implements Denops {
110110
*
111111
* ```typescript
112112
* import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts";
113-
* import { batch } from "./batch.ts";
113+
* import { batch } from "https://deno.land/x/denops_std@$MODULE_VERSION/batch/mod.ts";
114114
*
115115
* async function replace(denops: Denops, content: string): Promise<void> {
116116
* await batch(denops, async (denops) => {
@@ -135,7 +135,7 @@ class BatchHelper implements Denops {
135135
*
136136
* ```typescript
137137
* import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts";
138-
* import { batch } from "./batch.ts";
138+
* import { batch } from "https://deno.land/x/denops_std@$MODULE_VERSION/batch/mod.ts";
139139
*
140140
* export async function main(denops: Denops): Promise<void> {
141141
* await batch(denops, async (denops) => {
@@ -154,8 +154,8 @@ class BatchHelper implements Denops {
154154
*
155155
* ```typescript
156156
* import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts";
157-
* import { batch } from "./batch.ts";
158157
* import * as lambda from "https://deno.land/x/denops_std@$MODULE_VERSION/lambda/mod.ts";
158+
* import { batch } from "https://deno.land/x/denops_std@$MODULE_VERSION/batch/mod.ts";
159159
*
160160
* export async function main(denops: Denops): Promise<void> {
161161
* await batch(denops, async (denops) => {

batch/collect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class CollectHelper implements Denops {
8787
*
8888
* ```typescript
8989
* import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts";
90-
* import { collect } from "./collect.ts";
90+
* import { collect } from "https://deno.land/x/denops_std@$MODULE_VERSION/batch/mod.ts";
9191
*
9292
* export async function main(denops: Denops): Promise<void> {
9393
* const results = await collect(denops, (denops) => [
@@ -106,7 +106,7 @@ class CollectHelper implements Denops {
106106
*
107107
* ```typescript
108108
* import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts";
109-
* import { collect } from "./collect.ts";
109+
* import { collect } from "https://deno.land/x/denops_std@$MODULE_VERSION/batch/mod.ts";
110110
*
111111
* export async function main(denops: Denops): Promise<void> {
112112
* const results = await collect(denops, (denops) => {

batch/mod.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
/**
22
* A module to provide `denops.batch()` helper functions
33
*
4+
* ```typescript
5+
* import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts";
6+
* import { batch, collect } from "https://deno.land/x/denops_std@$MODULE_VERSION/batch/mod.ts";
7+
*
8+
* export async function main(denops: Denops): Promise<void> {
9+
* // Call multiple denops functions sequentially in a signle RPC call
10+
* await batch(denops, async (denops) => {
11+
* await denops.cmd("setlocal modifiable");
12+
* await denops.cmd("setlocal noswap");
13+
* await denops.cmd("setlocal nobackup");
14+
* });
15+
*
16+
* // Call multiple denops functions sequentially and get the return values in a single RPC call
17+
* const results = await collect(denops, (denops) => [
18+
* denops.eval("&modifiable"),
19+
* denops.eval("&modified"),
20+
* denops.eval("&filetype"),
21+
* ]);
22+
* // results contains the value of modifiable, modified, and filetype
23+
* }
24+
* ```
25+
*
426
* @module
527
*/
628
export * from "./batch.ts";

buffer/buffer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export interface OpenResult {
223223
*
224224
* export async function main(denops: Denops): Promise<void> {
225225
* await open(denops, "README.md");
226-
* const bufnr = (await fn.bufnr(denops)) as number;
226+
* const bufnr = await fn.bufnr(denops);
227227
* // ...
228228
* // Reload the content of the `bufnr` buffer.
229229
* await reload(denops, bufnr);
@@ -251,7 +251,7 @@ export async function reload(denops: Denops, bufnr: number): Promise<void> {
251251
*
252252
* export async function main(denops: Denops): Promise<void> {
253253
* await open(denops, "README.md");
254-
* const bufnr = (await fn.bufnr(denops)) as number;
254+
* const bufnr = await fn.bufnr(denops);
255255
* const data = await Deno.readFile("README.md");
256256
* const { content } = await decode(denops, bufnr, data);
257257
* await replace(denops, bufnr, content);
@@ -315,7 +315,7 @@ export interface DecodeResult {
315315
*
316316
* export async function main(denops: Denops): Promise<void> {
317317
* await open(denops, "README.md");
318-
* const bufnr = (await fn.bufnr(denops)) as number;
318+
* const bufnr = await fn.bufnr(denops);
319319
* // Append the content under the cursor position of the `bufnr` buffer
320320
* await append(denops, bufnr, ["Hello", "World"]);
321321
* }
@@ -355,7 +355,7 @@ export interface AppendOptions {
355355
*
356356
* export async function main(denops: Denops): Promise<void> {
357357
* await open(denops, "README.md");
358-
* const bufnr = (await fn.bufnr(denops)) as number;
358+
* const bufnr = await fn.bufnr(denops);
359359
* // Set the content of the `bufnr` buffer
360360
* await replace(denops, bufnr, ["Hello", "World"]);
361361
* }
@@ -403,7 +403,7 @@ export interface ReplaceOptions {
403403
*
404404
* export async function main(denops: Denops): Promise<void> {
405405
* await open(denops, "README.md");
406-
* const bufnr = (await fn.bufnr(denops)) as number;
406+
* const bufnr = await fn.bufnr(denops);
407407
* await fn.setbufvar(denops, bufnr, "&buftype", "nofile");
408408
* await replace(denops, bufnr, ["Hello", "World"]);
409409
* await concrete(denops, bufnr);
@@ -454,7 +454,7 @@ export async function concrete(
454454
*
455455
* export async function main(denops: Denops): Promise<void> {
456456
* await open(denops, "README.md");
457-
* const bufnr = (await fn.bufnr(denops)) as number;
457+
* const bufnr = await fn.bufnr(denops);
458458
* // ...
459459
* await ensure(denops, bufnr, async () => {
460460
* await option.buftype.set(denops, "nofile");
@@ -510,7 +510,7 @@ export async function ensure<T>(
510510
*
511511
* export async function main(denops: Denops): Promise<void> {
512512
* await open(denops, "README.md");
513-
* const bufnr = (await fn.bufnr(denops)) as number;
513+
* const bufnr = await fn.bufnr(denops);
514514
* // ...
515515
* await modifiable(denops, bufnr, async () => {
516516
* await fn.setline(denops, 1, ["Hello", "World"]);

buffer/decoration.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ import { unreachable } from "https://deno.land/x/unreachable@v0.1.0/mod.ts";
88
const cacheKey = "denops_std/buffer/decoration/vimDecorate/rs@1";
99

1010
export interface Decoration {
11-
// Line number
11+
/**
12+
* Line number
13+
*/
1214
line: number;
13-
// Column number (bytes)
15+
/**
16+
* Column number (bytes)
17+
*/
1418
column: number;
15-
// Length (bytes)
19+
/**
20+
* Length (bytes)
21+
*/
1622
length: number;
17-
// Highlight name
23+
/**
24+
* Highlight name
25+
*/
1826
highlight: string;
1927
}
2028

buffer/mod.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
11
/**
22
* A module to provide Vim buffer utility functions
33
*
4+
* ```typescript
5+
* import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts";
6+
* import * as fn from "https://deno.land/x/denops_std@$MODULE_VERSION/function/mod.ts";
7+
* import * as buffer from "https://deno.land/x/denops_std@$MODULE_VERSION/buffer/mod.ts";
8+
*
9+
* export async function main(denops: Denops): Promise<void> {
10+
* // Open `README.md`
11+
* // Same as `:edit README.md`
12+
* await buffer.open(denops, "README.md");
13+
*
14+
* // Open `LICENSE` with given options
15+
* // Same as `:keepjumps keepalt edit ++enc=sjis ++ff=dos LICENSE`
16+
* await buffer.open(denops, "LICENSE", {
17+
* mods: "keepjumps keepalt",
18+
* cmdarg: "++enc=sjis ++ff=dos",
19+
* });
20+
*
21+
* const bufnr = await fn.bufnr(denops);
22+
*
23+
* // Append the content under the cursor position of the `bufnr` buffer
24+
* await buffer.append(denops, bufnr, ["Hello", "World"]);
25+
*
26+
* // Set the content of the `bufnr` buffer
27+
* await buffer.replace(denops, bufnr, ["Hello", "World"]);
28+
*
29+
* // Concrete the buffer.
30+
* // - The `buftype` option become "nofile"
31+
* // - The `swapfile` become disabled
32+
* // - The `modifiable` become disabled
33+
* // - The content of the buffer is restored on `BufReadCmd` synchronously
34+
* await buffer.concrete(denops, bufnr);
35+
*
36+
* // Decorate the specified buffer with decorations
37+
* await buffer.decorate(denops, bufnr, [
38+
* {
39+
* line: 1,
40+
* column: 1,
41+
* length: 10,
42+
* highlight: "Special",
43+
* },
44+
* {
45+
* line: 2,
46+
* column: 2,
47+
* length: 3,
48+
* highlight: "Comment",
49+
* },
50+
* ]);
51+
* }
52+
* ```
453
* @module
554
*/
655
export * from "./buffer.ts";

bufname/bufname.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,21 @@ export type BufnameParams = Record<string, string | string[] | undefined>;
4545
* ```
4646
*/
4747
export interface Bufname {
48-
// Scheme part of a buffer name. Note that Vim supports only alphabets in scheme part.
48+
/**
49+
* Scheme part of a buffer name. Note that Vim supports only alphabets in scheme part.
50+
*/
4951
scheme: string;
50-
// Expression part of a buffer name. Note that '<>|?*' are not supported in Vim on Windows.
52+
/**
53+
* Expression part of a buffer name. Note that '<>|?*' are not supported in Vim on Windows.
54+
*/
5155
expr: string;
52-
// Params part of a buffer name. While '?' is not supported, the params part are splitted by ';' instead.
56+
/**
57+
* Params part of a buffer name. While '?' is not supported, the params part are splitted by ';' instead.
58+
*/
5359
params?: BufnameParams;
54-
// Fragment part of a buffer name. This is mainly used to regulate the suffix of the buffer name.
60+
/**
61+
* Fragment part of a buffer name. This is mainly used to regulate the suffix of the buffer name.
62+
*/
5563
fragment?: string;
5664
}
5765

@@ -78,7 +86,7 @@ const exprPattern = /^(.*?)(?:;(.*?))?(?:#(.*))?$/;
7886
* percent-encoded characters. It's required to distinguish `params` and or `fragment`.
7987
*
8088
* ```typescript
81-
* import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
89+
* import { assertEquals } from "https://deno.land/std@0.211.0/assert/mod.ts";
8290
* import { format } from "https://deno.land/x/denops_std@$MODULE_VERSION/bufname/mod.ts";
8391
*
8492
* assertEquals(
@@ -130,8 +138,8 @@ const exprPattern = /^(.*?)(?:;(.*?))?(?:#(.*))?$/;
130138
* constructing a buffer name from a real path. For example
131139
*
132140
* ```typescript
133-
* import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
134-
* import * as path from "https://deno.land/std/path/mod.ts";
141+
* import { assertEquals } from "https://deno.land/std@0.211.0/assert/mod.ts";
142+
* import * as path from "https://deno.land/std@0.211.0/path/mod.ts";
135143
* import { format } from "https://deno.land/x/denops_std@$MODULE_VERSION/bufname/mod.ts";
136144
*
137145
* // NOTE:
@@ -170,7 +178,7 @@ export function format(
170178
* For example, if it contains unusable characters ("<>|?*).
171179
*
172180
* ```typescript
173-
* import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
181+
* import { assertEquals } from "https://deno.land/std@0.211.0/assert/mod.ts";
174182
* import { parse } from "https://deno.land/x/denops_std@$MODULE_VERSION/bufname/mod.ts";
175183
*
176184
* assertEquals(
@@ -224,8 +232,8 @@ export function format(
224232
* was constructed from a real path. For example
225233
*
226234
* ```typescript
227-
* import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
228-
* import * as path from "https://deno.land/std/path/mod.ts";
235+
* import { assertEquals } from "https://deno.land/std@0.211.0/assert/mod.ts";
236+
* import * as path from "https://deno.land/std@0.211.0/path/mod.ts";
229237
* import { parse } from "https://deno.land/x/denops_std@$MODULE_VERSION/bufname/mod.ts";
230238
*
231239
* const bufname = parse("denops:///C:/Users/John%2520Titor/test.git");

bufname/mod.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,59 @@
4242
* scheme expr params fragment
4343
* ```
4444
*
45+
* Developers can use `format` and `parse` functions like below:
46+
*
47+
* ```typescript
48+
* import { assertEquals } from "https://deno.land/std@0.211.0/assert/mod.ts";
49+
* import { format, parse } from "https://deno.land/x/denops_std@$MODULE_VERSION/bufname/mod.ts";
50+
*
51+
* // Format
52+
* assertEquals(
53+
* format({
54+
* scheme: "denops",
55+
* expr: "/Users/John Titor/test.git",
56+
* }),
57+
* "denops:///Users/John Titor/test.git",
58+
* );
59+
* // Parse
60+
* assertEquals(
61+
* parse("denops:///Users/John Titor/test.git"),
62+
* {
63+
* scheme: "denops",
64+
* expr: "/Users/John Titor/test.git",
65+
* },
66+
* );
67+
*
68+
* // Format (complex)
69+
* assertEquals(
70+
* format({
71+
* scheme: "denops",
72+
* expr: "/Users/John Titor/test.git",
73+
* params: {
74+
* foo: "foo",
75+
* bar: ["bar1", "bar2"],
76+
* },
77+
* fragment: "README.md",
78+
* }),
79+
* "denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md",
80+
* );
81+
* // Parse (complex)
82+
* assertEquals(
83+
* parse(
84+
* "denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md",
85+
* ),
86+
* {
87+
* scheme: "denops",
88+
* expr: "/Users/John Titor/test.git",
89+
* params: {
90+
* foo: "foo",
91+
* bar: ["bar1", "bar2"],
92+
* },
93+
* fragment: "README.md",
94+
* },
95+
* );
96+
* ```
97+
*
4598
* @module
4699
*/
47100
export * from "./bufname.ts";

0 commit comments

Comments
 (0)