Skip to content

Extension development

Λlisue edited this page Nov 17, 2024 · 3 revisions

Extensions for Fall are functions that return objects matching the types of modules defined in @vim-fall/core. During development, you will typically use helper functions provided by @vim-fall/std such as defineXXXXX, as shown in the example below.

import * as vars from "jsr:@denops/std/variable";
import { enumerate } from "jsr:@core/iterutil/enumerate";
import { defineSource, type Source } from "jsr:@vim-fall/std/source";

type Detail = {
  path: string;
};

/**
 * Provides a source for recently accessed files.
 *
 * This source fetches the list of old files stored in the `v:oldfiles` variable
 * in Vim/Neovim and yields them with each file’s path as `Detail`.
 *
 * @returns A source that yields recently accessed files.
 */
export function oldfiles(): Source<Detail> {
  return defineSource(async function* (denops, _params, { signal }) {
    const oldfiles = await vars.v.get(denops, "oldfiles") as string[];
    signal?.throwIfAborted();
    for (const [id, path] of enumerate(oldfiles)) {
      yield {
        id,
        value: path,
        detail: {
          path,
        },
      };
    }
  });
}

Distribution

Fall extensions should be distributed as TypeScript standard modules. Since Fall internally uses Deno, which supports local files, HTTP URLs, and JavaScript registries, you can choose the appropriate method based on your distribution goals.

Purpose Recommended Distribution Method
For personal use with no intent to share Local file
To share with a limited group of users GitHub repository, Gist, or any HTTP-accessible source
For public distribution JavaScript registries such as JSR.io

If you do not wish to set up your own namespace on JSR.io for public distribution, you can submit a PR to deno-fall-extra. Extensions included there will be available under @vim-fall/extra.

If you develop an extension that would be better supported as a built-in feature, submit a PR to the builtin directory of deno-fall-std. Extensions included there will be available under @vim-fall/std.

Clone this wiki locally