Skip to content

Commit

Permalink
Improve exists() check
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Oct 7, 2024
1 parent 181ee89 commit 69a9069
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/jsr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ jobs:
- name: Publish
run: |
deno run -A jsr:@david/publish-on-tag@0.1.3
24 changes: 12 additions & 12 deletions denops/dpp/ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ export async function getExt(
]
> {
if (!loader.getExt(name)) {
await loader.autoload(denops, "ext", name);
}

const ext = loader.getExt(name);
if (!ext) {
if (name.length !== 0) {
const exists = await loader.autoload(denops, "ext", name);
if (!exists) {
await printError(
denops,
`Not found ext: "${name}"`,
);
}
}

const ext = loader.getExt(name);
if (!ext) {
return [
undefined,
defaultExtOptions(),
Expand All @@ -155,17 +155,17 @@ async function getProtocol(
]
> {
if (!loader.getProtocol(name)) {
await loader.autoload(denops, "protocol", name);
}

const protocol = loader.getProtocol(name);
if (!protocol) {
if (name.length !== 0) {
const exists = await loader.autoload(denops, "protocol", name);
if (!exists) {
await printError(
denops,
`Not found protocol: "${name}"`,
);
}
}

const protocol = loader.getProtocol(name);
if (!protocol) {
return [
undefined,
defaultProtocolOptions(),
Expand Down
8 changes: 6 additions & 2 deletions denops/dpp/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Loader {
denops: Denops,
type: DppExtType,
name: string,
) {
): Promise<boolean> {
const runtimepath = await op.runtimepath.getGlobal(denops);
if (runtimepath !== this.#prevRuntimepath) {
this.#cachedPaths = await globpath(
Expand All @@ -46,10 +46,14 @@ export class Loader {
const key = `@dpp-${type}s/${name}`;

if (!this.#cachedPaths[key]) {
return;
return this.#prevRuntimepath === "";
}

await this.registerPath(type, this.#cachedPaths[key]);

// NOTE: this.#prevRuntimepath may be true if initialized.
// NOTE: If not found, it returns false, .
return this.#prevRuntimepath === "" || this.#cachedPaths[key] !== undefined;
}

async registerPath(type: DppExtType, path: string) {
Expand Down

0 comments on commit 69a9069

Please sign in to comment.