diff --git a/denops/dpp/deps.ts b/denops/dpp/deps.ts index fd34555..3252946 100644 --- a/denops/dpp/deps.ts +++ b/denops/dpp/deps.ts @@ -15,21 +15,19 @@ export { ensure, is } from "https://deno.land/x/unknownutil@v3.9.0/mod.ts"; export { assertEquals, equal, -} from "https://deno.land/std@0.202.0/assert/mod.ts"; +} from "https://deno.land/std@0.204.0/assert/mod.ts"; export { + basename, + dirname, extname, parse, + SEP as pathsep, toFileUrl, -} from "https://deno.land/std@0.202.0/path/mod.ts"; +} from "https://deno.land/std@0.204.0/path/mod.ts"; export { deadline, DeadlineError, -} from "https://deno.land/std@0.202.0/async/mod.ts"; +} from "https://deno.land/std@0.204.0/async/mod.ts"; export { TimeoutError } from "https://deno.land/x/msgpack_rpc@v4.0.1/response_waiter.ts"; export { Lock } from "https://deno.land/x/async@v2.0.2/mod.ts"; -export { - basename, - dirname, - SEP as pathsep, -} from "https://deno.land/std@0.202.0/path/mod.ts"; -export { deferred } from "https://deno.land/std@0.202.0/async/deferred.ts"; +export { deferred } from "https://deno.land/std@0.204.0/async/deferred.ts"; diff --git a/denops/dpp/loader.ts b/denops/dpp/loader.ts index 85b88a2..3cab856 100644 --- a/denops/dpp/loader.ts +++ b/denops/dpp/loader.ts @@ -7,7 +7,7 @@ import { ExtName, ProtocolName, } from "./types.ts"; -import { Denops, fn, Lock, op, parse, toFileUrl } from "./deps.ts"; +import { basename, Denops, fn, Lock, op, parse, toFileUrl } from "./deps.ts"; type Mod = { // deno-lint-ignore no-explicit-any @@ -23,23 +23,30 @@ export class Loader { }; private checkPaths: Record = {}; private registerLock = new Lock(0); + private cachedPaths: Record = {}; + private prevRuntimepath = ""; async autoload( denops: Denops, type: DppExtType, name: string, ) { - const paths = await globpath( - denops, - `denops/@dpp-${type}s/`, - name, - ); + const runtimepath = await op.runtimepath.getGlobal(denops); + if (runtimepath !== this.prevRuntimepath) { + this.cachedPaths = await globpath( + denops, + "denops/@dpp-*s", + ); + this.prevRuntimepath = runtimepath; + } + + const key = `@dpp-${type}s/${name}`; - if (paths.length === 0) { + if (!this.cachedPaths[key]) { return; } - await this.registerPath(type, paths[0]); + await this.registerPath(type, this.cachedPaths[key]); } async registerPath(type: DppExtType, path: string) { @@ -114,28 +121,27 @@ class Extension { async function globpath( denops: Denops, search: string, - file: string, -): Promise { +): Promise> { const runtimepath = await op.runtimepath.getGlobal(denops); - const check: Record = {}; - const paths: string[] = []; + const paths: Record = {}; const glob = await fn.globpath( denops, runtimepath, - search + file + ".ts", + search + "/*.ts", 1, 1, ); for (const path of glob) { // Skip already added name. - if (parse(path).name in check) { + const parsed = parse(path); + const key = `${basename(parsed.dir)}/${parsed.name}`; + if (key in paths) { continue; } - paths.push(path); - check[parse(path).name] = true; + paths[key] = path; } return paths;