Skip to content

Commit 4e10ba0

Browse files
authored
Merge pull request #13 from vim-denops/use-entrypoint
📝 Use `Entrypoint` style in example codes
2 parents 6aeb2f2 + e316b72 commit 4e10ba0

16 files changed

+99
-79
lines changed

.github/workflows/mdbook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ jobs:
3636
run: |
3737
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
3838
rustup update
39-
cargo install --version ${MDBOOK_VERSION} mdbook
40-
cargo install mdbook-alerts
39+
cargo install --force --version ${MDBOOK_VERSION} mdbook
40+
cargo install --force mdbook-alerts
4141
- name: Setup Pages
4242
id: pages
4343
uses: actions/configure-pages@v4

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ env:
66

77
on:
88
push:
9+
branches:
10+
- main
911
pull_request:
12+
workflow_dispatch:
1013

1114
jobs:
1215
test:
@@ -30,8 +33,8 @@ jobs:
3033
run: |
3134
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
3235
rustup update
33-
cargo install --version ${MDBOOK_VERSION} mdbook
34-
cargo install mdbook-alerts
36+
cargo install --force --version ${MDBOOK_VERSION} mdbook
37+
cargo install --force mdbook-alerts
3538
- name: Build with mdBook
3639
run: mdbook build
3740
- name: Format

src/getting-started/README.md

Lines changed: 3 additions & 3 deletions
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

Lines changed: 34 additions & 17 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ 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)
10-
(2024-02-03)
11-
- [denops_std v6.0.0](https://github.com/vim-denops/deno-denops-std/releases/tag/v6.0.0)
12-
(2024-02-03)
9+
- [denops.vim v6.0.7](https://github.com/vim-denops/denops.vim/releases/tag/v6.0.7)
10+
(2024-05-15)
11+
- [denops_std v6.5.0](https://github.com/vim-denops/deno-denops-std/releases/tag/v6.5.0)
12+
(2024-05-15)
1313

1414
[vim-jp]: https://vim-jp.org/
1515
[denops.vim]: https://github.com/vim-denops/denops.vim

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 6 additions & 6 deletions
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);

0 commit comments

Comments
 (0)