From ab1765bb5797fd880d7e65311d6b8b4b2c147125 Mon Sep 17 00:00:00 2001 From: Alisue Date: Sat, 27 Jul 2024 16:51:41 +0900 Subject: [PATCH] :memo: Use JSR instead to support Denops v7 --- src/api-reference.md | 6 +- src/getting-started/README.md | 4 +- src/getting-started/explanation.md | 55 ++++-------- src/install.md | 8 +- src/tutorial.md | 8 +- src/tutorial/helloworld/adding-an-api.md | 8 +- .../helloworld/calling-vim-features.md | 6 +- .../creating-a-minimal-denops-plugin.md | 4 +- .../adjusting-maze-size-to-fit-the-window.md | 18 ++-- .../maze/creating-applicative-plugin.md | 19 ++-- .../maze/outputting-content-to-buffer.md | 4 +- .../maze/properly-configured-the-buffer.md | 10 +-- .../maze/properly-create-a-virtual-buffer.md | 10 +-- .../maze/reduce-the-number-of-rpc-calls.md | 16 ++-- .../maze/utilizing-denops-std-library.md | 90 ------------------- .../maze/utilizing-third-party-library.md | 6 +- 16 files changed, 82 insertions(+), 190 deletions(-) delete mode 100644 src/tutorial/maze/utilizing-denops-std-library.md diff --git a/src/api-reference.md b/src/api-reference.md index 82f0904..18d2252 100644 --- a/src/api-reference.md +++ b/src/api-reference.md @@ -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 diff --git a/src/getting-started/README.md b/src/getting-started/README.md index 58c0021..667d0af 100644 --- a/src/getting-started/README.md +++ b/src/getting-started/README.md @@ -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 = { diff --git a/src/getting-started/explanation.md b/src/getting-started/explanation.md index 5d9f151..b83d958 100644 --- a/src/getting-started/explanation.md +++ b/src/getting-started/explanation.md @@ -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 = { @@ -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). @@ -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 @@ -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 @@ -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", "%"); @@ -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 diff --git a/src/install.md b/src/install.md index 3c29039..758a33f 100644 --- a/src/install.md +++ b/src/install.md @@ -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 diff --git a/src/tutorial.md b/src/tutorial.md index 5a30bee..dfb6f96 100644 --- a/src/tutorial.md +++ b/src/tutorial.md @@ -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 diff --git a/src/tutorial/helloworld/adding-an-api.md b/src/tutorial/helloworld/adding-an-api.md index 280be8a..ced95ae 100644 --- a/src/tutorial/helloworld/adding-an-api.md +++ b/src/tutorial/helloworld/adding-an-api.md @@ -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 = { @@ -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!". diff --git a/src/tutorial/helloworld/calling-vim-features.md b/src/tutorial/helloworld/calling-vim-features.md index 71de4f5..bb6df14 100644 --- a/src/tutorial/helloworld/calling-vim-features.md +++ b/src/tutorial/helloworld/calling-vim-features.md @@ -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 = { @@ -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) diff --git a/src/tutorial/helloworld/creating-a-minimal-denops-plugin.md b/src/tutorial/helloworld/creating-a-minimal-denops-plugin.md index 61895fe..3d0056a 100644 --- a/src/tutorial/helloworld/creating-a-minimal-denops-plugin.md +++ b/src/tutorial/helloworld/creating-a-minimal-denops-plugin.md @@ -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!"); @@ -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. diff --git a/src/tutorial/maze/adjusting-maze-size-to-fit-the-window.md b/src/tutorial/maze/adjusting-maze-size-to-fit-the-window.md index 1aec304..deed874 100644 --- a/src/tutorial/maze/adjusting-maze-size-to-fit-the-window.md +++ b/src/tutorial/maze/adjusting-maze-size-to-fit-the-window.md @@ -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 = { @@ -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, @@ -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: diff --git a/src/tutorial/maze/creating-applicative-plugin.md b/src/tutorial/maze/creating-applicative-plugin.md index 3b7dcd0..d59744a 100644 --- a/src/tutorial/maze/creating-applicative-plugin.md +++ b/src/tutorial/maze/creating-applicative-plugin.md @@ -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 = { @@ -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. diff --git a/src/tutorial/maze/outputting-content-to-buffer.md b/src/tutorial/maze/outputting-content-to-buffer.md index 2988eda..6620c92 100644 --- a/src/tutorial/maze/outputting-content-to-buffer.md +++ b/src/tutorial/maze/outputting-content-to-buffer.md @@ -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 = { diff --git a/src/tutorial/maze/properly-configured-the-buffer.md b/src/tutorial/maze/properly-configured-the-buffer.md index 4528edb..54a540b 100644 --- a/src/tutorial/maze/properly-configured-the-buffer.md +++ b/src/tutorial/maze/properly-configured-the-buffer.md @@ -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 = { diff --git a/src/tutorial/maze/properly-create-a-virtual-buffer.md b/src/tutorial/maze/properly-create-a-virtual-buffer.md index 2a57e06..bacb2cf 100644 --- a/src/tutorial/maze/properly-create-a-virtual-buffer.md +++ b/src/tutorial/maze/properly-create-a-virtual-buffer.md @@ -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 = { diff --git a/src/tutorial/maze/reduce-the-number-of-rpc-calls.md b/src/tutorial/maze/reduce-the-number-of-rpc-calls.md index 0d359b8..ad915b6 100644 --- a/src/tutorial/maze/reduce-the-number-of-rpc-calls.md +++ b/src/tutorial/maze/reduce-the-number-of-rpc-calls.md @@ -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 = { @@ -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) diff --git a/src/tutorial/maze/utilizing-denops-std-library.md b/src/tutorial/maze/utilizing-denops-std-library.md deleted file mode 100644 index 697da9f..0000000 --- a/src/tutorial/maze/utilizing-denops-std-library.md +++ /dev/null @@ -1,90 +0,0 @@ -# Utilizing Denops Standard library - -In the previous section, we created a plugin that outputs a maze to a buffer. -However, the plugin has the following problems: - -- The maze does not fit the window size. The maze may be too large for it -- The buffer is modifiable so that the content may accidentally be modified -- When user execute `:edit` command, the maze is disappeared - -Additionally, we used `denops.cmd` or `denops.call` to execute Vim commands and -functions directly. However, it was a bit painful to use those because we must -know the definitions of the commands and functions. No auto-completion, no type -checking, etc. - -In this section, we introduce Denops standard library (`denops_std`) to solves -all above problems. The plugin will output the maze to non-file like buffer that -is non-modifiable and the content is remained even if user execute `:edit` -command. - -First, modify the `denops/denops-helloworld/main.ts` file as follows: - -```typescript:denops/denops-helloworld/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"; - -export const main: Entrypoint = (denops) => { - denops.dispatcher = { - async maze() { - // Get the current window size - const winWidth = await fn.winwidth(denops, 0); - const winHeight = await fn.winheight(denops, 0); - - // Create a maze that fits the current window size - const maze = new Maze({ - xSize: winWidth / 3, - ySize: winHeight / 3, - }).generate(); - const content = maze.getString(); - - // Open a 'maze://' buffer with specified opener - const { bufnr } = await buffer.open(denops, "maze://"); - - // Replace the buffer content with the maze - await buffer.replace(denops, bufnr, content.split(/\r?\n/g)); - - // Concrete (fix) the buffer content - await buffer.concrete(denops, bufnr); - - // Set the buffer options - await op.bufhidden.setLocal(denops, "wipe"); - await op.modifiable.setLocal(denops, false); - }, - }; -}; -``` - -Let's break down this code step by step. - -### Get the current window size - -```typescript -// Get the current window size -const winWidth = await fn.winwidth(denops, 0); -const winHeight = await fn.winheight(denops, 0); -``` - -This code call Vim's `winwidth` and `winheight` functions to get the current -window size. While `function` module (alised to `fn`) of `denops_std` provides a -set of functions that are available on both Vim and Neovim, LSP can provide -auto-completion and type checking for the functions. - -> [!NOTE] -> -> 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) -> for more details. - -### Open a 'maze://' buffer with specified opener - -```typescript -const { bufnr } = await buffer.open(denops, "maze://"); -``` diff --git a/src/tutorial/maze/utilizing-third-party-library.md b/src/tutorial/maze/utilizing-third-party-library.md index 8fb2cbc..4b87463 100644 --- a/src/tutorial/maze/utilizing-third-party-library.md +++ b/src/tutorial/maze/utilizing-third-party-library.md @@ -2,7 +2,7 @@ Certainly, starting with coding a maze generation algorithm would be nice. However, since you're now using Deno, you can conveniently employ a third-party -library called [maze_generator](https://deno.land/x/maze_generator@v0.4.0). +library called [maze_generator](https://github.com/mjrlowe/maze_generator). Let's define a `Maze` command similar to `DenopsHello`; `Maze` generates a maze and outputs it. @@ -29,8 +29,8 @@ directory tree will look like this: The content of the `denops/denops-maze/main.ts` file will be: ```typescript: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 = {