about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorTetsuharu Ohzeki <tetsuharu.ohzeki@gmail.com>2023-07-10 23:12:42 +0900
committerTetsuharu Ohzeki <tetsuharu.ohzeki@gmail.com>2023-07-10 23:13:36 +0900
commitfd31006646b3c9014b1770cf02ab2e9bca59c1e8 (patch)
tree61216128a6e51ec6dd42ee845e9ac6c9ba186afa /editors/code/src
parent2f6d545535acbedff0c338102be7f8a775602149 (diff)
downloadrust-fd31006646b3c9014b1770cf02ab2e9bca59c1e8.tar.gz
rust-fd31006646b3c9014b1770cf02ab2e9bca59c1e8.zip
editor/code: Assert types in catch in `sendRequestWithRetry()` properly
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/util.ts20
1 files changed, 12 insertions, 8 deletions
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<TParam, TRet>(
             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.code !== lc.LSPErrorCodes.ContentModified) {
-                log.warn("LSP request failed", { method: reqType.method, param, error });
-                throw error;
+            if (error instanceof lc.ResponseError) {
+                switch (error.code) {
+                    case lc.LSPErrorCodes.RequestCancelled:
+                        throw error;
+                    case lc.LSPErrorCodes.ContentModified:
+                        await sleep(delay);
+                        continue;
+                }
             }
-            await sleep(delay);
+
+            log.warn("LSP request failed", { method: reqType.method, param, error });
+            throw error;
         }
     }
     throw "unreachable";