Skip to content

Commit

Permalink
Merge pull request #14 from vim-denops/support-v7
Browse files Browse the repository at this point in the history
📝 Use JSR instead to support Denops v7
  • Loading branch information
lambdalisue authored Jul 27, 2024
2 parents 4e10ba0 + ab1765b commit 9122f91
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 190 deletions.
6 changes: 3 additions & 3 deletions src/api-reference.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# API Reference

There is a standard module [denops_std] to develop denops plugins. It provides
There is a standard module [@denops/std] to develop denops plugins. It provides
various functions to interact with Vim and Neovim and some shorthands to make it
easier to write plugins.

You can find API references about the module by checking the Deno doc page:
`https://deno.land/x/denops_std/mod.ts`.
`https://jsr.io/@denops/std`.

[denops_std]: https://deno.land/x/denops_std/mod.ts
[@denops/std]: https://jsr.io/@denops/std
4 changes: 2 additions & 2 deletions src/getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ $HOME

Next, write the following TypeScript code in `main.ts`:

```typescript
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
```typescript:denops/denops-getting-started/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
55 changes: 19 additions & 36 deletions src/getting-started/explanation.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ easily call.
In the Getting Started, we wrote the following code in the `main.ts` file:

```typescript
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand All @@ -107,14 +107,14 @@ Let's break down this code step by step.
### About Imports

```typescript
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
```

The first line imports the `Entrypoint` type from the [denops_std] standard
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.
URL: `https://jsr.io/@denops/std@7.0.0` (replace `jsr:` to `https://jsr.io/`).
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).
Expand All @@ -130,28 +130,11 @@ meaning. Using `import { Entrypoint }` for a type-only import is also valid.
> [`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.
>
> This type information is provided by [denops_core], and [denops_std] simply
> re-exports the type information from [denops_core]. However, [denops_core] is
> intended to be referenced only by [denops.vim] and [denops_std], so Denops
> This type information is provided by [@denops/core], and [@denops/std] simply
> re-exports the type information from [@denops/core]. However, [@denops/core]
> is 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/denops_std@v6.0.0/mod.ts";
>
> export function main(denops: Denops): void {
> denops.dispatcher = {
> async hello() {
> await denops.cmd(`echo "Hello, Denops!"`);
> },
> };
> }
> ```
### About Entry Point

```typescript
Expand All @@ -162,8 +145,8 @@ export const main: Entrypoint = (denops) => {

The above code exports the `main` function. The `main` function is called by
Denops, and it takes the
[Denops instance](https://deno.land/x/denops_std/mod.ts?s=Denops) (`denops`) as
an argument. Denops plugins use this `denops` to add user-defined APIs or call
[Denops instance](https://jsr.io/@denops/core/doc/~/Denops) (`denops`) as an
argument. Denops plugins use this `denops` to add user-defined APIs or call
Vim's features.

### About User-Defined APIs
Expand Down Expand Up @@ -222,17 +205,17 @@ several methods:
| `eval` | Evaluate a Vim expression and returns the result. If `ctx` is provided, it is expanded as local variables. |
| `dispatch` | Calls a user-defined API of another Denops plugin and returns the result. |

Although `denops` provides low-level interfaces, [denops_std] combines these
Although `denops` provides low-level interfaces, [@denops/std] combines these
low-level interfaces to offer higher-level interfaces. Therefore, it's
recommended to use [denops_std] to call Vim's features in actual plugin
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.5.0/function/mod.ts) to
call Vim's function instead of `denops.call` like:
[`function` module](https://jsr.io/@denops/std@7.0.0/doc/function/~) to call
Vim's function instead of `denops.call` like:

```typescript
import * as fn from "https://deno.land/x/denops_std@v6.5.0/function/mod.ts";
import * as fn from "jsr:@denops/std@7.0.0/function";

// Bad (result1 is `unknown`)
const result1 = await denops.call("expand", "%");
Expand All @@ -251,8 +234,8 @@ plugin.

- [Tutorial (Hello World)](../tutorial/helloworld/README.md)
- [Tutorial (Maze)](../tutorial/maze/README.md)
- [API reference](https://deno.land/x/denops_std/mod.ts)
- [API reference](https://jsr.io/@denops/std)

[denops.vim]: https://github.com/vim-denops/denops.vim
[denops_std]: https://deno.land/x/denops_std
[denops_core]: https://deno.land/x/denops_core
[@denops/std]: https://jsr.io/@denops/std
[@denops/core]: https://jsr.io/@denops/core
8 changes: 4 additions & 4 deletions src/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ You can check the health of Denops by running the `:checkhealth` command
==============================================================================
denops: health#denops#check
- Supported Deno version: `1.38.5`
- Detected Deno version: `1.39.4`
- Supported Deno version: `1.45.0`
- Detected Deno version: `1.45.4`
- OK Deno version check: passed
- Supported Neovim version: `0.9.4`
- Detected Neovim version: `0.9.5`
- Supported Neovim version: `0.10.0`
- Detected Neovim version: `0.10.0`
- OK Neovim version check: passed
- Denops status: `running`
- OK Denops status check: passed
Expand Down
8 changes: 4 additions & 4 deletions src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ This article is a tutorial on developing Denops plugins.

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

- [denops.vim v6.0.7](https://github.com/vim-denops/denops.vim/releases/tag/v6.0.7)
(2024-05-15)
- [denops_std v6.5.0](https://github.com/vim-denops/deno-denops-std/releases/tag/v6.5.0)
(2024-05-15)
- [denops.vim v7.0.0](https://github.com/vim-denops/denops.vim/releases/tag/v7.0.0)
(2024-07-27)
- [denops_std v7.0.0](https://github.com/vim-denops/deno-denops-std/releases/tag/v7.0.0)
(2024-07-27)

[vim-jp]: https://vim-jp.org/
[denops.vim]: https://github.com/vim-denops/denops.vim
Expand Down
8 changes: 4 additions & 4 deletions src/tutorial/helloworld/adding-an-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Open `denops/denops-helloworld/main.ts` and rewrite the content with the
following code:

```typescript:denops/denops-helloworld/main.ts
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import { assert, is } from "https://deno.land/x/unknownutil@v3.18.1/mod.ts";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { assert, is } from "jsr:@core/unknownutil@3.18.1";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand All @@ -29,8 +29,8 @@ for details about User-Defined APIs.
>
> While Vim script does not facilitate types, Denops uses `unknown` types on the
> interface between Vim and Denops. That's why we use
> [unknownutil](https://deno.land/x/unknownutil) to ensure that the `name` is of
> type `string` in the above code.
> [unknownutil](https://jsr.io/@core/unknownutil) to ensure that the `name` is
> of type `string` in the above code.
Once you've updated the file, restart Vim, and execute the following command,
you will see the message "Hello, Your name!".
Expand Down
6 changes: 3 additions & 3 deletions src/tutorial/helloworld/calling-vim-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ the `denops` instance passed to the plugin's `main` function. You can rewrite
`main.ts` as follows to register the `DenopsHello` as a Vim command:

```ts:denops/denops-helloworld/main.ts
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import { assert, is } from "https://deno.land/x/unknownutil@v3.18.1/mod.ts";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { assert, is } from "jsr:@core/unknownutil@3.18.1";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down Expand Up @@ -61,4 +61,4 @@ In the next step, follow the tutorial to learn how to develop a real Denops
plugin.

- [Tutorial (Maze)](../tutorial/maze/README.md)
- [API reference](https://deno.land/x/denops_std/mod.ts)
- [API reference](https://jsr.io/@denops/std)
4 changes: 2 additions & 2 deletions src/tutorial/helloworld/creating-a-minimal-denops-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ denops-helloworld
Here is the content of the `denops/denops-helloworld/main.ts` file:

```typescript:denops/denops-helloworld/main.ts
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";

export const main: Entrypoint = (denops) => {
console.log("Hello, Denops from TypeScript!");
Expand All @@ -45,7 +45,7 @@ export const main: Entrypoint = (denops) => {
> `console.error`, etc.) for debug output. The content will be echoed to Vim.
> However, it is not recommended to use `console.log` in production code.
> Instead, use `denops.cmd("echo '...'")` or the `echo` function in the `helper`
> module of the `denops_std` library.
> module of the `@denops/std` library.
Once you've created the file, restart Vim, and "Hello, Denops from TypeScript!"
will be displayed on Vim startup.
Expand Down
18 changes: 9 additions & 9 deletions src/tutorial/maze/adjusting-maze-size-to-fit-the-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Let's modify the plugin to ensure the generated maze fits the current window
size.

```typescript:denops/denops-helloworld/main.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/maze_generator@v0.4.0/mod.js";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import * as fn from "jsr:@denops/std@7.0.0/function";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand All @@ -31,10 +31,10 @@ export const main: Entrypoint = (denops) => {
};
```

In this code, we utilize the `function` module (aliased to `fn`) of `denops_std`
(Denops Standard Library) to call `winwidth()`, `winheight()`, and `setline()`
functions. Then, we create a maze that fits the current window size and write it
to the buffer.
In this code, we utilize the `function` module (aliased to `fn`) of
`@denops/std` (Denops Standard Library) to call `winwidth()`, `winheight()`, and
`setline()` functions. Then, we create a maze that fits the current window size
and write it to the buffer.

So why do we use the `function` module instead of `denops.call`? With
`denops.call`, developers must know the function name, arguments, return type,
Expand All @@ -44,13 +44,13 @@ checking, etc. It is more convenient and safe to use the `function` module.

> [!TIP]
>
> The `function` module of the `denops_std` library provides a set of functions
> The `function` module of the `@denops/std` library provides a set of functions
> that are available on both Vim and Neovim. If you'd like to use Vim or Neovim
> only functions, use the `vim` or `nvim` module under the `function` module
> instead.
>
> See the
> [function module of denops_std API document](https://doc.deno.land/https/deno.land/x/denops_std/function/mod.ts)
> [function module of @denops/std API document](https://jsr.io/@denops/std@7.0.0/doc/function/~)
> for more details.
Restart Vim, rerun the `:Maze` command, and then you can see:
Expand Down
19 changes: 9 additions & 10 deletions src/tutorial/maze/creating-applicative-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ 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 { 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/maze_generator@v0.4.0/mod.js";
import { assert, is } from "https://deno.land/x/unknownutil@v3.18.1/mod.ts";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { batch, collect } from "jsr:@denops/std@7.0.0/batch";
import * as fn from "jsr:@denops/std@7.0.0/function";
import * as op from "jsr:@denops/std@7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";
import { assert, is } from "jsr:@core/unknownutil@3.18.1";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down Expand Up @@ -68,16 +68,15 @@ export const main: Entrypoint = (denops) => {
};
```

In above code, we utilize the following denops_std modules:
In above code, we utilize the following `@denops/std` modules:

- `batch` and `collect` functions in a `batch` module to execute multiple
commands in a single RPC
- `function` module to call Vim's functions
- `option` module to get and set Vim's options

See the
[denops_std API document](https://doc.deno.land/https/deno.land/x/denops_std/mod.ts)
for more details about each modules.
See the [denops_std API document](https://jsr.io/@denops/std) for more details
about each modules.

That's it. Now you can see a smaller maze shown on the window with `:Maze`
command.
Expand Down
4 changes: 2 additions & 2 deletions src/tutorial/maze/outputting-content-to-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ 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 { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import { Maze } from "https://deno.land/x/maze_generator@v0.4.0/mod.js";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
10 changes: 5 additions & 5 deletions src/tutorial/maze/properly-configured-the-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ buffer after closure. Open the `main.ts` file and modify the `maze` method as
follows:

```typescript:denops/denops-maze/main.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/maze_generator@v0.4.0/mod.js";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import * as buffer from "jsr:@denops/std@7.0.0/buffer";
import * as fn from "jsr:@denops/std@7.0.0/function";
import * as op from "jsr:@denops/std@7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
10 changes: 5 additions & 5 deletions src/tutorial/maze/properly-create-a-virtual-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ For example, if a user executes the `:edit` command on the buffer, the maze will
disappear. This is because Vim does not know how to reload the buffer content,
and we must inform Vim about the content of the buffer when it is reloaded.

In this section, we will use the `buffer` module of `denops_std` to create a
In this section, we will use the `buffer` module of `@denops/std` to create a
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 { 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/maze_generator@v0.4.0/mod.js";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import * as buffer from "jsr:@denops/std@7.0.0/buffer";
import * as fn from "jsr:@denops/std@7.0.0/function";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
16 changes: 8 additions & 8 deletions src/tutorial/maze/reduce-the-number-of-rpc-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
As Denops employs RPC to interact with Vim, the volume of RPC calls
significantly influences the plugin's performance. In this section, we aim to
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:
from `@denops/std`. Let's revise the `main.ts` file as follows:

```typescript:denops/denops-maze/main.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/maze_generator@v0.4.0/mod.js";
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { batch, collect } from "jsr:@denops/std@7.0.0/batch";
import * as buffer from "jsr:@denops/std@7.0.0/buffer";
import * as fn from "jsr:@denops/std@7.0.0/function";
import * as op from "jsr:@denops/std@7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down Expand Up @@ -96,7 +96,7 @@ properly with `batch` and `collect`.

In the next step, read API references or real-world plugins

- [API reference](https://deno.land/x/denops_std/mod.ts)
- [API reference](https://jsr.io/@denops/std)
- [lambdalisue/gin.vim](https://github.com/lambdalisue/gin.vim)
- [vim-skk/skkeleton](https://github.com/vim-skk/skkeleton)
- [Shougo/ddu.vim](https://github.com/Shougo/ddu.vim)
Expand Down
Loading

0 comments on commit 9122f91

Please sign in to comment.