diff --git a/denops/ddc/deps.ts b/denops/ddc/deps.ts index 18b8bf9..005288e 100644 --- a/denops/ddc/deps.ts +++ b/denops/ddc/deps.ts @@ -11,16 +11,20 @@ export * as op from "https://deno.land/x/denops_std@v5.0.1/option/mod.ts"; export * as fn from "https://deno.land/x/denops_std@v5.0.1/function/mod.ts"; export * as vars from "https://deno.land/x/denops_std@v5.0.1/variable/mod.ts"; export * as autocmd from "https://deno.land/x/denops_std@v5.0.1/autocmd/mod.ts"; -export * as base64 from "https://deno.land/std@0.203.0/encoding/base64.ts"; +export * as base64 from "https://deno.land/std@0.204.0/encoding/base64.ts"; export { assertEquals, equal, -} from "https://deno.land/std@0.203.0/assert/mod.ts"; -export { parse, toFileUrl } from "https://deno.land/std@0.203.0/path/mod.ts"; +} from "https://deno.land/std@0.204.0/assert/mod.ts"; +export { + basename, + parse, + toFileUrl, +} from "https://deno.land/std@0.204.0/path/mod.ts"; export { deadline, DeadlineError, -} from "https://deno.land/std@0.203.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 { spy } from "https://deno.land/x/mock@0.15.2/mock.ts"; export { ensure, is } from "https://deno.land/x/unknownutil@v3.9.0/mod.ts"; diff --git a/denops/ddc/loader.ts b/denops/ddc/loader.ts index 4d3391d..3f1634b 100644 --- a/denops/ddc/loader.ts +++ b/denops/ddc/loader.ts @@ -10,7 +10,7 @@ import { SourceName, UiName, } from "./types.ts"; -import { Denops, fn, Lock, op, parse, toFileUrl } from "./deps.ts"; +import { basename, Denops, fn, Lock, op, parse, toFileUrl } from "./deps.ts"; export class Loader { private uis: Record> = {}; @@ -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: DdcExtType, name: string, ) { - const paths = await globpath( - denops, - `denops/@ddc-${type}s/`, - this.getAlias(type, name) ?? name, - ); + const runtimepath = await op.runtimepath.getGlobal(denops); + if (runtimepath !== this.prevRuntimepath) { + this.cachedPaths = await globpath( + denops, + "denops/@ddc-*s", + ); + this.prevRuntimepath = runtimepath; + } + + const key = `@ddc-${type}s/${this.getAlias(type, name) ?? name}`; - if (paths.length === 0) { + if (!this.cachedPaths[key]) { return; } - await this.registerPath(type, paths[0]); + await this.registerPath(type, this.cachedPaths[key]); } registerAlias(type: DdcExtType, alias: string, base: string) { @@ -119,28 +126,27 @@ export class Loader { 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;