Skip to content

Commit

Permalink
Detect deno cache errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Aug 3, 2024
1 parent f877ea7 commit 7359b2c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
29 changes: 22 additions & 7 deletions denops/ddc/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
vars,
} from "./deps.ts";
import { Loader } from "./loader.ts";
import { isDenoCacheIssueError } from "./utils.ts";
import { createCallbackContext } from "./callback.ts";
import { getPreviewer, onCompleteDone, onEvent } from "./ext.ts";

Expand Down Expand Up @@ -160,13 +161,27 @@ export const main: Entrypoint = (denops: Denops) => {
async loadConfig(arg1: unknown): Promise<void> {
await lock.lock(async () => {
const path = ensure(arg1, is.String) as string;
// NOTE: Import module with fragment so that reload works properly.
// /~https://github.com/vim-denops/denops.vim/issues/227
const mod = await import(
`${toFileUrl(path).href}#${performance.now()}`
);
const obj = new mod.Config();
await obj.config({ denops, contextBuilder, setAlias });
try {
// NOTE: Import module with fragment so that reload works properly.
// /~https://github.com/vim-denops/denops.vim/issues/227
const mod = await import(
`${toFileUrl(path).href}#${performance.now()}`
);
const obj = new mod.Config();
await obj.config({ denops, contextBuilder, setAlias });
} catch (e) {
if (isDenoCacheIssueError(e)) {
console.warn("*".repeat(80));
console.warn(`Deno module cache issue is detected.`);
console.warn(
`Execute '!deno cache --reload "${path}"' and restart Vim/Neovim.`,
);
console.warn("*".repeat(80));
}

console.error(`Failed to load file '${path}': ${e}`);
throw e;
}
});
return Promise.resolve();
},
Expand Down
17 changes: 16 additions & 1 deletion denops/ddc/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
parse,
toFileUrl,
} from "./deps.ts";
import { isDenoCacheIssueError } from "./utils.ts";
import { mods } from "./_mods.js";

export class Loader {
Expand Down Expand Up @@ -109,7 +110,21 @@ export class Loader {

async registerPath(type: DdcExtType, path: string) {
await this.#registerLock.lock(async () => {
await this.#register(type, path);
try {
await this.#register(type, path);
} catch (e) {
if (isDenoCacheIssueError(e)) {
console.warn("*".repeat(80));
console.warn(`Deno module cache issue is detected.`);
console.warn(
`Execute '!deno cache --reload "${path}"' and restart Vim/Neovim.`,
);
console.warn("*".repeat(80));
}

console.error(`Failed to load file '${path}': ${e}`);
throw e;
}
});
}

Expand Down
12 changes: 12 additions & 0 deletions denops/ddc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ export async function convertKeywordPattern(
return replaced;
}

// See /~https://github.com/vim-denops/denops.vim/issues/358 for details
export function isDenoCacheIssueError(e: unknown): boolean {
const expects = [
"Could not find constraint in the list of versions: ", // Deno 1.40?
"Could not find version of ", // Deno 1.38
] as const;
if (e instanceof TypeError) {
return expects.some((expect) => e.message.startsWith(expect));
}
return false;
}

function vimoption2ts(option: string): string {
let hasDash = false;
const patterns: string[] = [];
Expand Down

0 comments on commit 7359b2c

Please sign in to comment.