From 7359b2c9d29f16edbca268f00b3ab7d71649f3c4 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 3 Aug 2024 09:45:05 +0900 Subject: [PATCH] Detect deno cache errors --- denops/ddc/app.ts | 29 ++++++++++++++++++++++------- denops/ddc/loader.ts | 17 ++++++++++++++++- denops/ddc/utils.ts | 12 ++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/denops/ddc/app.ts b/denops/ddc/app.ts index 0cfe7a0..1277b8b 100644 --- a/denops/ddc/app.ts +++ b/denops/ddc/app.ts @@ -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"; @@ -160,13 +161,27 @@ export const main: Entrypoint = (denops: Denops) => { async loadConfig(arg1: unknown): Promise { 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(); }, diff --git a/denops/ddc/loader.ts b/denops/ddc/loader.ts index 72e399a..bda76ca 100644 --- a/denops/ddc/loader.ts +++ b/denops/ddc/loader.ts @@ -20,6 +20,7 @@ import { parse, toFileUrl, } from "./deps.ts"; +import { isDenoCacheIssueError } from "./utils.ts"; import { mods } from "./_mods.js"; export class Loader { @@ -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; + } }); } diff --git a/denops/ddc/utils.ts b/denops/ddc/utils.ts index cc838aa..6281ec0 100644 --- a/denops/ddc/utils.ts +++ b/denops/ddc/utils.ts @@ -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[] = [];