-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from vim-denops/use-entrypoint
📝 Use `Entrypoint` style in example codes
- Loading branch information
Showing
16 changed files
with
99 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,42 +91,42 @@ easily call. | |
In the Getting Started, we wrote the following code in the `main.ts` file: | ||
|
||
```typescript | ||
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts"; | ||
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts"; | ||
|
||
export function main(denops: Denops): void { | ||
export const main: Entrypoint = (denops) => { | ||
denops.dispatcher = { | ||
async hello() { | ||
await denops.cmd(`echo "Hello, Denops!"`); | ||
}, | ||
}; | ||
} | ||
}; | ||
``` | ||
|
||
Let's break down this code step by step. | ||
|
||
### About Imports | ||
|
||
```typescript | ||
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts"; | ||
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts"; | ||
``` | ||
|
||
The first line imports the `Denops` type from the [denops_std] standard library. | ||
You can find detailed information about the library by checking the URL: | ||
`https://deno.land/x/denops_std@v6.0.0` (remove `/mod.ts`). We fixed the version | ||
in the import URL, so it's recommended to check for details and update to the | ||
latest version URL. | ||
The first line imports the `Entrypoint` type from the [denops_std] standard | ||
library. You can find detailed information about the library by checking the | ||
URL: `https://deno.land/x/denops_std@v6.5.0` (remove `/mod.ts`). We fixed the | ||
version in the import URL, so it's recommended to check for details and update | ||
to the latest version URL. | ||
|
||
Note that we use `import type` syntax, which is part of TypeScript's | ||
[Type-Only Imports and Export](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html). | ||
This syntax can be written as `import { type Denops }` with the same meaning. | ||
Using `import { Denops }` for a type-only import is also valid. | ||
This syntax can be written as `import { type Entrypoint }` with the same | ||
meaning. Using `import { Entrypoint }` for a type-only import is also valid. | ||
|
||
> [!NOTE] | ||
> | ||
> Denops plugins are dynamically imported, so there might be differences in | ||
> Denops versions between development and usage. Therefore, to minimize | ||
> differences between Denops versions, only the `Denops` type information is | ||
> exposed. The implementation can be found in | ||
> differences between Denops versions, only type information is exposed. The | ||
> implementation can be found in | ||
> [`denops/@denops-private/denops.ts`](https://github.com/vim-denops/denops.vim/blob/main/denops/%40denops-private/denops.ts), | ||
> but it is not publicly exposed for the reasons mentioned above. | ||
> | ||
|
@@ -135,12 +135,29 @@ Using `import { Denops }` for a type-only import is also valid. | |
> intended to be referenced only by [denops.vim] and [denops_std], so Denops | ||
> plugin developers don't need to use it directly. | ||
> [!NOTE] | ||
> | ||
> Prior to denops-std v6.5.0, the `Entrypoint` type was not defined thus | ||
> developers must define the `main` function as like | ||
> | ||
> ```typescript | ||
> import type { Denops } from "https://deno.land/x/[email protected]/mod.ts"; | ||
> | ||
> export function main(denops: Denops): void { | ||
> denops.dispatcher = { | ||
> async hello() { | ||
> await denops.cmd(`echo "Hello, Denops!"`); | ||
> }, | ||
> }; | ||
> } | ||
> ``` | ||
### About Entry Point | ||
```typescript | ||
export function main(denops: Denops): void { | ||
export const main: Entrypoint = (denops) => { | ||
// Omitted... | ||
} | ||
}; | ||
``` | ||
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 | |
development. | ||
|
||
For example, use | ||
[`function` module](https://deno.land/x/denops_std@v6.0.0/function/mod.ts) to | ||
[`function` module](https://deno.land/x/denops_std@v6.5.0/function/mod.ts) to | ||
call Vim's function instead of `denops.call` like: | ||
|
||
```typescript | ||
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts"; | ||
|
||
// Bad (result1 is `unknown`) | ||
const result1 = await denops.call("expand", "%"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,11 @@ Let's modify the plugin to ensure the generated maze fits the current window | |
size. | ||
|
||
```typescript:denops/denops-helloworld/main.ts | ||
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts"; | ||
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts"; | ||
import { Maze } from "https://deno.land/x/[email protected]/mod.js"; | ||
|
||
export function main(denops: Denops): void { | ||
export const main: Entrypoint = (denops) => { | ||
denops.dispatcher = { | ||
async maze() { | ||
await denops.cmd("enew"); | ||
|
@@ -28,7 +28,7 @@ export function main(denops: Denops): void { | |
await fn.setline(denops, 1, content.split(/\r?\n/g)); | ||
}, | ||
}; | ||
} | ||
}; | ||
``` | ||
|
||
In this code, we utilize the `function` module (aliased to `fn`) of `denops_std` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,14 @@ opener, generate a maze that fits the current window size, configure the buffer | |
options to make it non-file readonly buffer, etc. | ||
|
||
```ts:denops/denops-maze/main.ts | ||
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts"; | ||
import { batch, collect } from "https://deno.land/x/denops_std@v6.0.0/batch/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts"; | ||
import * as op from "https://deno.land/x/denops_std@v6.0.0/option/mod.ts"; | ||
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts"; | ||
import { batch, collect } from "https://deno.land/x/denops_std@v6.5.0/batch/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts"; | ||
import * as op from "https://deno.land/x/denops_std@v6.5.0/option/mod.ts"; | ||
import { Maze } from "https://deno.land/x/[email protected]/mod.js"; | ||
import { assert, is } from "https://deno.land/x/unknownutil@v3.14.1/mod.ts"; | ||
import { assert, is } from "https://deno.land/x/unknownutil@v3.18.1/mod.ts"; | ||
|
||
export function main(denops: Denops): void { | ||
export const main: Entrypoint = (denops) => { | ||
denops.dispatcher = { | ||
async maze(opener) { | ||
assert(opener, is.String); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,10 @@ the maze to a buffer so that users can yank the maze with daily Vim operations! | |
Let's modify the code to make the generated maze output to a buffer. | ||
|
||
```ts:denops/denops-maze/main.ts | ||
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts"; | ||
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts"; | ||
import { Maze } from "https://deno.land/x/[email protected]/mod.js"; | ||
|
||
export function main(denops: Denops): void { | ||
export const main: Entrypoint = (denops) => { | ||
denops.dispatcher = { | ||
async maze() { | ||
const maze = new Maze({}).generate(); | ||
|
@@ -19,7 +19,7 @@ export function main(denops: Denops): void { | |
await denops.call("setline", 1, content.split(/\r?\n/g)); | ||
}, | ||
}; | ||
} | ||
}; | ||
``` | ||
|
||
In this code, `denops.cmd` executes the Vim command `enew` to open a new buffer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,13 @@ buffer after closure. Open the `main.ts` file and modify the `maze` method as | |
follows: | ||
|
||
```typescript:denops/denops-maze/main.ts | ||
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts"; | ||
import * as buffer from "https://deno.land/x/denops_std@v6.0.0/buffer/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts"; | ||
import * as op from "https://deno.land/x/denops_std@v6.0.0/option/mod.ts"; | ||
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts"; | ||
import * as buffer from "https://deno.land/x/denops_std@v6.5.0/buffer/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts"; | ||
import * as op from "https://deno.land/x/denops_std@v6.5.0/option/mod.ts"; | ||
import { Maze } from "https://deno.land/x/[email protected]/mod.js"; | ||
|
||
export function main(denops: Denops): void { | ||
export const main: Entrypoint = (denops) => { | ||
denops.dispatcher = { | ||
async maze() { | ||
const { bufnr, winnr } = await buffer.open(denops, "maze://"); | ||
|
@@ -33,7 +33,7 @@ export function main(denops: Denops): void { | |
await op.modifiable.setLocal(denops, false); | ||
}, | ||
}; | ||
} | ||
}; | ||
``` | ||
|
||
In this code, we use `op.bufhidden.setLocal` to set the `bufhidden` option to | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,12 @@ proper virtual buffer that concretizes the buffer content. Let's modify the | |
`main.ts` file as follows: | ||
|
||
```typescript:denops/denops-maze/main.ts | ||
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts"; | ||
import * as buffer from "https://deno.land/x/denops_std@v6.0.0/buffer/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts"; | ||
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts"; | ||
import * as buffer from "https://deno.land/x/denops_std@v6.5.0/buffer/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts"; | ||
import { Maze } from "https://deno.land/x/[email protected]/mod.js"; | ||
|
||
export function main(denops: Denops): void { | ||
export const main: Entrypoint = (denops) => { | ||
denops.dispatcher = { | ||
async maze() { | ||
const { bufnr, winnr } = await buffer.open(denops, "maze://"); | ||
|
@@ -32,7 +32,7 @@ export function main(denops: Denops): void { | |
await buffer.concrete(denops, bufnr); | ||
}, | ||
}; | ||
} | ||
}; | ||
``` | ||
|
||
In this code, we use `buffer.open` to open a `maze://` buffer and get the buffer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,14 @@ enhance performance by reducing the number of RPC calls using the `batch` module | |
from `denops_std`. Let's revise the `main.ts` file as follows: | ||
|
||
```typescript:denops/denops-maze/main.ts | ||
import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts"; | ||
import { batch, collect } from "https://deno.land/x/denops_std@v6.0.0/batch/mod.ts"; | ||
import * as buffer from "https://deno.land/x/denops_std@v6.0.0/buffer/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.0.0/function/mod.ts"; | ||
import * as op from "https://deno.land/x/denops_std@v6.0.0/option/mod.ts"; | ||
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts"; | ||
import { batch, collect } from "https://deno.land/x/denops_std@v6.5.0/batch/mod.ts"; | ||
import * as buffer from "https://deno.land/x/denops_std@v6.5.0/buffer/mod.ts"; | ||
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts"; | ||
import * as op from "https://deno.land/x/denops_std@v6.5.0/option/mod.ts"; | ||
import { Maze } from "https://deno.land/x/[email protected]/mod.js"; | ||
|
||
export function main(denops: Denops): void { | ||
export const main: Entrypoint = (denops) => { | ||
denops.dispatcher = { | ||
async maze() { | ||
const { bufnr, winnr } = await buffer.open(denops, "maze://"); | ||
|
@@ -36,7 +36,7 @@ export function main(denops: Denops): void { | |
}); | ||
}, | ||
}; | ||
} | ||
}; | ||
``` | ||
|
||
In this code, we use the `collect` function to gather window size values and the | ||
|
Oops, something went wrong.