Skip to content

Commit

Permalink
feat: use dpp
Browse files Browse the repository at this point in the history
  • Loading branch information
ucpr committed Mar 31, 2024
1 parent 4f6a987 commit 20f81bf
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 1,143 deletions.
113 changes: 113 additions & 0 deletions nvim/dpp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import {
BaseConfig,
ContextBuilder,
Dpp,
Plugin,
} from "https://deno.land/x/[email protected]/types.ts";
import { Denops, fn } from "https://deno.land/x/[email protected]/deps.ts";

export class Config extends BaseConfig {
override async config(args: {
denops: Denops;
contextBuilder: ContextBuilder;
basePath: string;
dpp: Dpp;
}): Promise<{
plugins: Plugin[];
stateLines: string[];
}> {
args.contextBuilder.setGlobal({
protocols: ["git"],
});

type Toml = {
hooks_file?: string;
ftplugins?: Record<string, string>;
plugins?: Plugin[];
};

type LazyMakeStateResult = {
plugins: Plugin[];
stateLines: string[];
};

const [context, options] = await args.contextBuilder.get(args.denops);
const dotfilesDir = "~/.config/nvim/";

const tomls: Toml[] = [];
tomls.push(
await args.dpp.extAction(
args.denops,
context,
options,
"toml",
"load",
{
path: await fn.expand(args.denops, dotfilesDir + "tomls/dein.toml"),
options: {
lazy: false,
},
},
) as Toml,
);

tomls.push(
await args.dpp.extAction(
args.denops,
context,
options,
"toml",
"load",
{
path: await fn.expand(args.denops, dotfilesDir + "tomls/dein_lazy.toml"),
options: {
lazy: true,
},
},
) as Toml,
);

const recordPlugins: Record<string, Plugin> = {};
const ftplugins: Record<string, string> = {};
const hooksFiles: string[] = [];

tomls.forEach((toml) => {

for (const plugin of toml.plugins) {
recordPlugins[plugin.name] = plugin;
}

if (toml.ftplugins) {
for (const filetype of Object.keys(toml.ftplugins)) {
if (ftplugins[filetype]) {
ftplugins[filetype] += `\n${toml.ftplugins[filetype]}`;
} else {
ftplugins[filetype] = toml.ftplugins[filetype];
}
}
}

if (toml.hooks_file) {
hooksFiles.push(toml.hooks_file);
}
});

const lazyResult = await args.dpp.extAction(
args.denops,
context,
options,
"lazy",
"makeState",
{
plugins: Object.values(recordPlugins),
},
) as LazyMakeStateResult;

console.log(lazyResult);

return {
plugins: lazyResult.plugins,
stateLines: lazyResult.stateLines,
};
}
}
Loading

0 comments on commit 20f81bf

Please sign in to comment.