Skip to content

Commit ed114f1

Browse files
committed
📝 Use Entrypoint style in example codes
1 parent 6aeb2f2 commit ed114f1

14 files changed

+90
-73
lines changed

src/getting-started/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ $HOME
2222
Next, write the following TypeScript code in `main.ts`:
2323

2424
```typescript
25-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
25+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
2626

27-
export function main(denops: Denops): void {
27+
export const main: Entrypoint = (denops) => {
2828
denops.dispatcher = {
2929
async hello() {
3030
await denops.cmd(`echo "Hello, Denops!"`);
3131
},
3232
};
33-
}
33+
};
3434
```
3535

3636
## Activate the Plugin

src/getting-started/explanation.md

+34-17
Original file line numberDiff line numberDiff line change
@@ -91,42 +91,42 @@ easily call.
9191
In the Getting Started, we wrote the following code in the `main.ts` file:
9292

9393
```typescript
94-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
94+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
9595

96-
export function main(denops: Denops): void {
96+
export const main: Entrypoint = (denops) => {
9797
denops.dispatcher = {
9898
async hello() {
9999
await denops.cmd(`echo "Hello, Denops!"`);
100100
},
101101
};
102-
}
102+
};
103103
```
104104

105105
Let's break down this code step by step.
106106

107107
### About Imports
108108

109109
```typescript
110-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
110+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
111111
```
112112

113-
The first line imports the `Denops` type from the [denops_std] standard library.
114-
You can find detailed information about the library by checking the URL:
115-
`https://deno.land/x/denops_std@v6.0.0` (remove `/mod.ts`). We fixed the version
116-
in the import URL, so it's recommended to check for details and update to the
117-
latest version URL.
113+
The first line imports the `Entrypoint` type from the [denops_std] standard
114+
library. You can find detailed information about the library by checking the
115+
URL: `https://deno.land/x/denops_std@v6.5.0` (remove `/mod.ts`). We fixed the
116+
version in the import URL, so it's recommended to check for details and update
117+
to the latest version URL.
118118

119119
Note that we use `import type` syntax, which is part of TypeScript's
120120
[Type-Only Imports and Export](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html).
121-
This syntax can be written as `import { type Denops }` with the same meaning.
122-
Using `import { Denops }` for a type-only import is also valid.
121+
This syntax can be written as `import { type Entrypoint }` with the same
122+
meaning. Using `import { Entrypoint }` for a type-only import is also valid.
123123

124124
> [!NOTE]
125125
>
126126
> Denops plugins are dynamically imported, so there might be differences in
127127
> Denops versions between development and usage. Therefore, to minimize
128-
> differences between Denops versions, only the `Denops` type information is
129-
> exposed. The implementation can be found in
128+
> differences between Denops versions, only type information is exposed. The
129+
> implementation can be found in
130130
> [`denops/@denops-private/denops.ts`](https://github.com/vim-denops/denops.vim/blob/main/denops/%40denops-private/denops.ts),
131131
> but it is not publicly exposed for the reasons mentioned above.
132132
>
@@ -135,12 +135,29 @@ Using `import { Denops }` for a type-only import is also valid.
135135
> intended to be referenced only by [denops.vim] and [denops_std], so Denops
136136
> plugin developers don't need to use it directly.
137137
138+
> [!NOTE]
139+
>
140+
> Prior to denops-std v6.5.0, the `Entrypoint` type was not defined thus
141+
> developers must define the `main` function as like
142+
>
143+
> ```typescript
144+
> import type { Denops } from "https://deno.land/x/[email protected]/mod.ts";
145+
>
146+
> export function main(denops: Denops): void {
147+
> denops.dispatcher = {
148+
> async hello() {
149+
> await denops.cmd(`echo "Hello, Denops!"`);
150+
> },
151+
> };
152+
> }
153+
> ```
154+
138155
### About Entry Point
139156
140157
```typescript
141-
export function main(denops: Denops): void {
158+
export const main: Entrypoint = (denops) => {
142159
// Omitted...
143-
}
160+
};
144161
```
145162
146163
The above code exports the `main` function. The `main` function is called by
@@ -211,11 +228,11 @@ recommended to use [denops_std] to call Vim's features in actual plugin
211228
development.
212229

213230
For example, use
214-
[`function` module](https://deno.land/x/denops_std@v6.0.0/function/mod.ts) to
231+
[`function` module](https://deno.land/x/denops_std@v6.5.0/function/mod.ts) to
215232
call Vim's function instead of `denops.call` like:
216233

217234
```typescript
218-
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts";
235+
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts";
219236

220237
// Bad (result1 is `unknown`)
221238
const result1 = await denops.call("expand", "%");

src/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ This article is a tutorial on developing Denops plugins.
66

77
In this tutorial, we use the following software and version as of writing.
88

9-
- [denops.vim v6.0.0](https://github.com/vim-denops/denops.vim/releases/tag/v6.0.0)
9+
- [denops.vim v6.1.0](https://github.com/vim-denops/denops.vim/releases/tag/v6.1.0)
1010
(2024-02-03)
11-
- [denops_std v6.0.0](https://github.com/vim-denops/deno-denops-std/releases/tag/v6.0.0)
11+
- [denops_std v6.5.0](https://github.com/vim-denops/deno-denops-std/releases/tag/v6.5.0)
1212
(2024-02-03)
1313

1414
[vim-jp]: https://vim-jp.org/

src/tutorial/helloworld/adding-an-api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ Open `denops/denops-helloworld/main.ts` and rewrite the content with the
77
following code:
88

99
```typescript:denops/denops-helloworld/main.ts
10-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
11-
import { assert, is } from "https://deno.land/x/unknownutil@v3.14.1/mod.ts";
10+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
11+
import { assert, is } from "https://deno.land/x/unknownutil@v3.18.1/mod.ts";
1212

13-
export function main(denops: Denops): void {
13+
export const main: Entrypoint = (denops) => {
1414
denops.dispatcher = {
1515
hello(name) {
1616
assert(name, is.String);
1717
return `Hello, ${name || "Denops"}!`;
1818
},
1919
};
20-
}
20+
};
2121
```
2222

2323
The above code adds a new API `hello` to the plugin. The `hello` API takes a

src/tutorial/helloworld/calling-vim-features.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ the `denops` instance passed to the plugin's `main` function. You can rewrite
55
`main.ts` as follows to register the `DenopsHello` as a Vim command:
66

77
```ts:denops/denops-helloworld/main.ts
8-
import { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
9-
import { assert, is } from "https://deno.land/x/unknownutil@v3.14.1/mod.ts";
8+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
9+
import { assert, is } from "https://deno.land/x/unknownutil@v3.18.1/mod.ts";
1010

11-
export function main(denops: Denops): void {
11+
export const main: Entrypoint = (denops) => {
1212
denops.dispatcher = {
1313
async init() {
1414
// This is just an example.
@@ -23,7 +23,7 @@ export function main(denops: Denops): void {
2323
return `Hello, ${name || "Denops"}!`;
2424
},
2525
};
26-
}
26+
};
2727
```
2828

2929
Then, rewrite `plugin/denops-helloworld.vim` to automatically call the `init`

src/tutorial/helloworld/creating-a-minimal-denops-plugin.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ denops-helloworld
3232
Here is the content of the `denops/denops-helloworld/main.ts` file:
3333

3434
```typescript:denops/denops-helloworld/main.ts
35-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
35+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
3636

37-
export function main(denops: Denops): void {
37+
export const main: Entrypoint = (denops) => {
3838
console.log("Hello, Denops from TypeScript!");
39-
}
39+
};
4040
```
4141

4242
> [!WARNING]

src/tutorial/maze/adjusting-maze-size-to-fit-the-window.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Let's modify the plugin to ensure the generated maze fits the current window
88
size.
99

1010
```typescript:denops/denops-helloworld/main.ts
11-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
12-
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts";
11+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
12+
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts";
1313
import { Maze } from "https://deno.land/x/[email protected]/mod.js";
1414

15-
export function main(denops: Denops): void {
15+
export const main: Entrypoint = (denops) => {
1616
denops.dispatcher = {
1717
async maze() {
1818
await denops.cmd("enew");
@@ -28,7 +28,7 @@ export function main(denops: Denops): void {
2828
await fn.setline(denops, 1, content.split(/\r?\n/g));
2929
},
3030
};
31-
}
31+
};
3232
```
3333

3434
In this code, we utilize the `function` module (aliased to `fn`) of `denops_std`

src/tutorial/maze/creating-applicative-plugin.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ opener, generate a maze that fits the current window size, configure the buffer
3333
options to make it non-file readonly buffer, etc.
3434

3535
```ts:denops/denops-maze/main.ts
36-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
37-
import { batch, collect } from "https://deno.land/x/denops_std@v6.0.0/batch/mod.ts";
38-
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts";
39-
import * as op from "https://deno.land/x/denops_std@v6.0.0/option/mod.ts";
36+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
37+
import { batch, collect } from "https://deno.land/x/denops_std@v6.5.0/batch/mod.ts";
38+
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts";
39+
import * as op from "https://deno.land/x/denops_std@v6.5.0/option/mod.ts";
4040
import { Maze } from "https://deno.land/x/[email protected]/mod.js";
41-
import { assert, is } from "https://deno.land/x/unknownutil@v3.14.1/mod.ts";
41+
import { assert, is } from "https://deno.land/x/unknownutil@v3.18.1/mod.ts";
4242

43-
export function main(denops: Denops): void {
43+
export const main: Entrypoint = (denops) => {
4444
denops.dispatcher = {
4545
async maze(opener) {
4646
assert(opener, is.String);

src/tutorial/maze/outputting-content-to-buffer.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ the maze to a buffer so that users can yank the maze with daily Vim operations!
77
Let's modify the code to make the generated maze output to a buffer.
88

99
```ts:denops/denops-maze/main.ts
10-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
10+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
1111
import { Maze } from "https://deno.land/x/[email protected]/mod.js";
1212

13-
export function main(denops: Denops): void {
13+
export const main: Entrypoint = (denops) => {
1414
denops.dispatcher = {
1515
async maze() {
1616
const maze = new Maze({}).generate();
@@ -19,7 +19,7 @@ export function main(denops: Denops): void {
1919
await denops.call("setline", 1, content.split(/\r?\n/g));
2020
},
2121
};
22-
}
22+
};
2323
```
2424

2525
In this code, `denops.cmd` executes the Vim command `enew` to open a new buffer

src/tutorial/maze/properly-configured-the-buffer.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ buffer after closure. Open the `main.ts` file and modify the `maze` method as
77
follows:
88

99
```typescript:denops/denops-maze/main.ts
10-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
11-
import * as buffer from "https://deno.land/x/denops_std@v6.0.0/buffer/mod.ts";
12-
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts";
13-
import * as op from "https://deno.land/x/denops_std@v6.0.0/option/mod.ts";
10+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
11+
import * as buffer from "https://deno.land/x/denops_std@v6.5.0/buffer/mod.ts";
12+
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts";
13+
import * as op from "https://deno.land/x/denops_std@v6.5.0/option/mod.ts";
1414
import { Maze } from "https://deno.land/x/[email protected]/mod.js";
1515

16-
export function main(denops: Denops): void {
16+
export const main: Entrypoint = (denops) => {
1717
denops.dispatcher = {
1818
async maze() {
1919
const { bufnr, winnr } = await buffer.open(denops, "maze://");
@@ -33,7 +33,7 @@ export function main(denops: Denops): void {
3333
await op.modifiable.setLocal(denops, false);
3434
},
3535
};
36-
}
36+
};
3737
```
3838

3939
In this code, we use `op.bufhidden.setLocal` to set the `bufhidden` option to

src/tutorial/maze/properly-create-a-virtual-buffer.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ proper virtual buffer that concretizes the buffer content. Let's modify the
1010
`main.ts` file as follows:
1111

1212
```typescript:denops/denops-maze/main.ts
13-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
14-
import * as buffer from "https://deno.land/x/denops_std@v6.0.0/buffer/mod.ts";
15-
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts";
13+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
14+
import * as buffer from "https://deno.land/x/denops_std@v6.5.0/buffer/mod.ts";
15+
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts";
1616
import { Maze } from "https://deno.land/x/[email protected]/mod.js";
1717

18-
export function main(denops: Denops): void {
18+
export const main: Entrypoint = (denops) => {
1919
denops.dispatcher = {
2020
async maze() {
2121
const { bufnr, winnr } = await buffer.open(denops, "maze://");
@@ -32,7 +32,7 @@ export function main(denops: Denops): void {
3232
await buffer.concrete(denops, bufnr);
3333
},
3434
};
35-
}
35+
};
3636
```
3737

3838
In this code, we use `buffer.open` to open a `maze://` buffer and get the buffer

src/tutorial/maze/reduce-the-number-of-rpc-calls.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ enhance performance by reducing the number of RPC calls using the `batch` module
66
from `denops_std`. Let's revise the `main.ts` file as follows:
77

88
```typescript:denops/denops-maze/main.ts
9-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
10-
import { batch, collect } from "https://deno.land/x/denops_std@v6.0.0/batch/mod.ts";
11-
import * as buffer from "https://deno.land/x/denops_std@v6.0.0/buffer/mod.ts";
12-
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts";
13-
import * as op from "https://deno.land/x/denops_std@v6.0.0/option/mod.ts";
9+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
10+
import { batch, collect } from "https://deno.land/x/denops_std@v6.5.0/batch/mod.ts";
11+
import * as buffer from "https://deno.land/x/denops_std@v6.5.0/buffer/mod.ts";
12+
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts";
13+
import * as op from "https://deno.land/x/denops_std@v6.5.0/option/mod.ts";
1414
import { Maze } from "https://deno.land/x/[email protected]/mod.js";
1515

16-
export function main(denops: Denops): void {
16+
export const main: Entrypoint = (denops) => {
1717
denops.dispatcher = {
1818
async maze() {
1919
const { bufnr, winnr } = await buffer.open(denops, "maze://");
@@ -36,7 +36,7 @@ export function main(denops: Denops): void {
3636
});
3737
},
3838
};
39-
}
39+
};
4040
```
4141

4242
In this code, we use the `collect` function to gather window size values and the

src/tutorial/maze/utilizing-denops-std-library.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ command.
2020
First, modify the `denops/denops-helloworld/main.ts` file as follows:
2121

2222
```typescript:denops/denops-helloworld/main.ts
23-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
24-
import * as buffer from "https://deno.land/x/denops_std@v6.0.0/buffer/mod.ts";
25-
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts";
26-
import * as op from "https://deno.land/x/denops_std@v6.0.0/option/mod.ts";
23+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
24+
import * as buffer from "https://deno.land/x/denops_std@v6.5.0/buffer/mod.ts";
25+
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts";
26+
import * as op from "https://deno.land/x/denops_std@v6.5.0/option/mod.ts";
2727
import { Maze } from "https://deno.land/x/[email protected]/mod.js";
2828

29-
export function main(denops: Denops): void {
29+
export const main: Entrypoint = (denops) => {
3030
denops.dispatcher = {
3131
async maze() {
3232
// Get the current window size
@@ -54,7 +54,7 @@ export function main(denops: Denops): void {
5454
await op.modifiable.setLocal(denops, false);
5555
},
5656
};
57-
}
57+
};
5858
```
5959

6060
Let's break down this code step by step.

src/tutorial/maze/utilizing-third-party-library.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ directory tree will look like this:
2929
The content of the `denops/denops-maze/main.ts` file will be:
3030

3131
```typescript:denops/denops-maze/main.ts
32-
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
32+
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
3333
import { Maze } from "https://deno.land/x/[email protected]/mod.js";
3434

35-
export function main(denops: Denops): void {
35+
export const main: Entrypoint = (denops) => {
3636
denops.dispatcher = {
3737
maze() {
3838
const maze = new Maze({}).generate();
3939
const content = maze.getString();
4040
console.log(content);
4141
},
4242
};
43-
}
43+
};
4444
```
4545

4646
The content of the `plugin/denops-maze.vim` file will be:

0 commit comments

Comments
 (0)