diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index b6b779e2660..688e3873ab4 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts @@ -69,20 +69,24 @@ export async function sendRequestWithRetry( return await (token ? client.sendRequest(reqType, param, token) : client.sendRequest(reqType, param)); - } catch (error) { + } catch (error: unknown) { if (delay === null) { log.warn("LSP request timed out", { method: reqType.method, param, error }); throw error; } - if (error.code === lc.LSPErrorCodes.RequestCancelled) { - throw error; + + if (error instanceof lc.ResponseError) { + switch (error.code) { + case lc.LSPErrorCodes.RequestCancelled: + throw error; + case lc.LSPErrorCodes.ContentModified: + await sleep(delay); + continue; + } } - if (error.code !== lc.LSPErrorCodes.ContentModified) { - log.warn("LSP request failed", { method: reqType.method, param, error }); - throw error; - } - await sleep(delay); + log.warn("LSP request failed", { method: reqType.method, param, error }); + throw error; } } throw "unreachable";