Skip to content

Commit 6f2e8aa

Browse files
committed
Auto merge of #15252 - tetsuharuohzeki:enable-unknonw-catch, r=lnicola
editor/code: Enable TypeScript's `--useUnknownInCatchVariables` option This enables TypeScript's [`--useUnknownInCatchVariables`](https://www.typescriptlang.org/tsconfig#useUnknownInCatchVariables).
2 parents 2f6d545 + 444bc5b commit 6f2e8aa

File tree

4 files changed

+5
-35
lines changed

4 files changed

+5
-35
lines changed

editors/code/src/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export function ssr(ctx: CtxInit): Cmd {
373373
selections,
374374
});
375375
} catch (e) {
376-
return e.toString();
376+
return String(e);
377377
}
378378
return null;
379379
},
@@ -1156,7 +1156,7 @@ export function viewMemoryLayout(ctx: CtxInit): Cmd {
11561156
<meta http-equiv="X-UA-Compatible" content="IE=edge">
11571157
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11581158
<title>Document</title>
1159-
<style>
1159+
<style>
11601160
* {
11611161
box-sizing: border-box;
11621162
}

editors/code/src/util.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as lc from "vscode-languageclient/node";
21
import * as vscode from "vscode";
32
import { strict as nativeAssert } from "assert";
43
import { exec, ExecOptions, spawnSync } from "child_process";
@@ -57,37 +56,6 @@ export const log = new (class {
5756
}
5857
})();
5958

60-
export async function sendRequestWithRetry<TParam, TRet>(
61-
client: lc.LanguageClient,
62-
reqType: lc.RequestType<TParam, TRet, unknown>,
63-
param: TParam,
64-
token?: vscode.CancellationToken
65-
): Promise<TRet> {
66-
// The sequence is `10 * (2 ** (2 * n))` where n is 1, 2, 3...
67-
for (const delay of [40, 160, 640, 2560, 10240, null]) {
68-
try {
69-
return await (token
70-
? client.sendRequest(reqType, param, token)
71-
: client.sendRequest(reqType, param));
72-
} catch (error) {
73-
if (delay === null) {
74-
log.warn("LSP request timed out", { method: reqType.method, param, error });
75-
throw error;
76-
}
77-
if (error.code === lc.LSPErrorCodes.RequestCancelled) {
78-
throw error;
79-
}
80-
81-
if (error.code !== lc.LSPErrorCodes.ContentModified) {
82-
log.warn("LSP request failed", { method: reqType.method, param, error });
83-
throw error;
84-
}
85-
await sleep(delay);
86-
}
87-
}
88-
throw "unreachable";
89-
}
90-
9159
export function sleep(ms: number) {
9260
return new Promise((resolve) => setTimeout(resolve, ms));
9361
}

editors/code/tests/unit/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as assert from "node:assert/strict";
12
import { readdir } from "fs/promises";
23
import * as path from "path";
34

@@ -30,6 +31,7 @@ class Suite {
3031
await test.promise;
3132
ok(` ✔ ${test.name}`);
3233
} catch (e) {
34+
assert.ok(e instanceof Error);
3335
error(` ✖︎ ${test.name}\n ${e.stack}`);
3436
failed += 1;
3537
}
@@ -50,6 +52,7 @@ export class Context {
5052
await ctx.run();
5153
ok(`✔ ${name}`);
5254
} catch (e) {
55+
assert.ok(e instanceof Error);
5356
error(`✖︎ ${name}\n ${e.stack}`);
5457
throw e;
5558
}

editors/code/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"newLine": "LF",
1313
// These disables some enhancement type checking options
1414
// to update typescript version without any code change.
15-
"useUnknownInCatchVariables": false,
1615
"exactOptionalPropertyTypes": false
1716
},
1817
"exclude": ["node_modules", ".vscode-test"],

0 commit comments

Comments
 (0)