Skip to content

Commit

Permalink
Add toml ext
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Sep 19, 2023
1 parent 0e06660 commit dacc2eb
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions denops/@dpp-exts/toml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Actions, BaseExt, Plugin } from "../dpp/types.ts";
import { Denops } from "../dpp/deps.ts";
import { parse } from "https://deno.land/[email protected]/encoding/toml.ts";
import { basename } from "https://deno.land/[email protected]/path/mod.ts";

type Params = Record<string, never>;

type LoadArgs = {
path: string;
options?: Partial<Plugin>;
};

type Toml = {
hooks_file?: string;
plugins: Plugin[];
};

export class Ext extends BaseExt<Params> {
override actions: Actions<Params> = {
load: {
description: "Load toml config",
callback: async (args: {
denops: Denops;
actionParams: unknown;
}) => {
const params = args.actionParams as LoadArgs;
const path = await args.denops.call(
"dpp#util#_expand",
params.path,
) as string;

const defaultOptions = params.options ?? {};

const toml = parse(await Deno.readTextFile(path)) as Toml;

const plugins = toml.plugins.map((plugin: Plugin) => {
return {
...defaultOptions,
...plugin,
name: plugin.name ?? basename(plugin.repo),
}
});
console.log(plugins);

return plugins;
},
},
};

override params(): Params {
return {};
}
}

0 comments on commit dacc2eb

Please sign in to comment.