diff --git a/autoload/dpp/util.vim b/autoload/dpp/util.vim index 1fab727..bdb51a9 100644 --- a/autoload/dpp/util.vim +++ b/autoload/dpp/util.vim @@ -1,3 +1,5 @@ +const s:is_windows = has('win32') || has('win64') + function dpp#util#_error(msg) abort for mes in s:msg2list(a:msg) echohl WarningMsg | echomsg '[dpp] ' .. mes | echohl None @@ -84,8 +86,8 @@ function dpp#util#_expand(path) abort \ (a:path =~# '^\$\h\w*') ? a:path \ ->substitute('^\$\h\w*', '\=eval(submatch(0))', '') : \ a:path - return (s:is_windows && path =~# '\\') ? - \ dpp#util#_substitute_path(path) : path + return ((s:is_windows && path =~# '\\') ? + \ dpp#util#_substitute_path(path) : path)->substitute('/$', '', '') endfunction function dpp#util#_substitute_path(path) abort return ((s:is_windows || has('win32unix')) && a:path =~# '\\') ? diff --git a/denops/@dpp-exts/local.ts b/denops/@dpp-exts/local.ts index a0ab50e..b49a993 100644 --- a/denops/@dpp-exts/local.ts +++ b/denops/@dpp-exts/local.ts @@ -1,14 +1,55 @@ -import { Actions, BaseExt } from "../dpp/types.ts"; -import { Denops } from "../dpp/deps.ts"; +import { Actions, BaseExt, Plugin } from "../dpp/types.ts"; +import { Denops, fn } from "../dpp/deps.ts"; +import { isDirectory } from "../dpp/utils.ts"; +import { basename } from "https://deno.land/std@0.201.0/path/mod.ts"; type Params = Record; +type LocalArgs = { + directory: string; + options?: Partial; + includes?: string[]; +}; + export class Ext extends BaseExt { override actions: Actions = { local: { description: "Load local plugins", - callback: async (args: { denops: Denops }) => { - console.log("hello"); + callback: async (args: { + denops: Denops; + actionParams: unknown; + }) => { + const params = args.actionParams as LocalArgs; + const base = await args.denops.call( + "dpp#util#_expand", + params.directory, + ); + + const defaultOptions = params.options ?? {}; + + let plugins: Plugin[] = []; + for (const include of params.includes ?? ["*"]) { + const dirs = await fn.glob( + args.denops, + base + "/" + include, + 1, + 1, + ) as string[]; + + plugins = plugins.concat( + dirs.filter(async (dir) => await isDirectory(dir)).map((dir) => { + return { + ...defaultOptions, + repo: dir, + local: true, + path: dir, + name: basename(dir), + }; + }), + ); + } + + return plugins; }, }, }; diff --git a/denops/dpp/types.ts b/denops/dpp/types.ts index d8a87d2..0cb87f0 100644 --- a/denops/dpp/types.ts +++ b/denops/dpp/types.ts @@ -68,5 +68,11 @@ export type Action = { }; export type Plugin = { + frozen?: boolean; + lazy?: boolean; + local?: boolean; + merged?: boolean; name: string; + path: string; + repo: string; }; diff --git a/denops/dpp/utils.ts b/denops/dpp/utils.ts index a3f3ba7..22ee9d1 100644 --- a/denops/dpp/utils.ts +++ b/denops/dpp/utils.ts @@ -28,3 +28,16 @@ export async function errorException( console.error(e); } } + +export async function isDirectory(path: string) { + // NOTE: Deno.stat() may be failed + try { + if ((await Deno.stat(path)).isDirectory) { + return true; + } + } catch (_e: unknown) { + // Ignore + } + + return false; +}