Skip to content

Commit 854b9e9

Browse files
authored
[lldb-dap] Format extension typescript. (#138925)
I think the format checker isn't checking typescript files. I ran `npm run format` to fix the extenion typescript.
1 parent 70cf616 commit 854b9e9

File tree

2 files changed

+153
-111
lines changed

2 files changed

+153
-111
lines changed

lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,79 +21,97 @@ async function isServerModeSupported(exe: string): Promise<boolean> {
2121
}
2222

2323
interface BoolConfig {
24-
type: 'boolean';
24+
type: "boolean";
2525
default: boolean;
2626
}
2727
interface StringConfig {
28-
type: 'string';
28+
type: "string";
2929
default: string;
3030
}
3131
interface NumberConfig {
32-
type: 'number';
32+
type: "number";
3333
default: number;
3434
}
3535
interface StringArrayConfig {
36-
type: 'stringArray';
36+
type: "stringArray";
3737
default: string[];
3838
}
39-
type DefaultConfig = BoolConfig | NumberConfig | StringConfig | StringArrayConfig;
39+
type DefaultConfig =
40+
| BoolConfig
41+
| NumberConfig
42+
| StringConfig
43+
| StringArrayConfig;
4044

4145
const configurations: Record<string, DefaultConfig> = {
4246
// Keys for debugger configurations.
43-
"commandEscapePrefix": { type: "string", default: "`" },
44-
"customFrameFormat": { type: "string", default: "" },
45-
"customThreadFormat": { type: "string", default: "" },
46-
"detachOnError": { type: "boolean", default: false },
47-
"disableASLR": { type: "boolean", default: true },
48-
"disableSTDIO": { type: "boolean", default: false },
49-
"displayExtendedBacktrace": { type: "boolean", default: false },
50-
"enableAutoVariableSummaries": { type: "boolean", default: false },
51-
"enableSyntheticChildDebugging": { type: "boolean", default: false },
52-
"timeout": { type: "number", default: 30 },
47+
commandEscapePrefix: { type: "string", default: "`" },
48+
customFrameFormat: { type: "string", default: "" },
49+
customThreadFormat: { type: "string", default: "" },
50+
detachOnError: { type: "boolean", default: false },
51+
disableASLR: { type: "boolean", default: true },
52+
disableSTDIO: { type: "boolean", default: false },
53+
displayExtendedBacktrace: { type: "boolean", default: false },
54+
enableAutoVariableSummaries: { type: "boolean", default: false },
55+
enableSyntheticChildDebugging: { type: "boolean", default: false },
56+
timeout: { type: "number", default: 30 },
5357

5458
// Keys for platform / target configuration.
55-
"platformName": { type: "string", default: "" },
56-
"targetTriple": { type: "string", default: "" },
59+
platformName: { type: "string", default: "" },
60+
targetTriple: { type: "string", default: "" },
5761

5862
// Keys for debugger command hooks.
59-
"initCommands": { type: "stringArray", default: [] },
60-
"preRunCommands": { type: "stringArray", default: [] },
61-
"postRunCommands": { type: "stringArray", default: [] },
62-
"stopCommands": { type: "stringArray", default: [] },
63-
"exitCommands": { type: "stringArray", default: [] },
64-
"terminateCommands": { type: "stringArray", default: [] },
63+
initCommands: { type: "stringArray", default: [] },
64+
preRunCommands: { type: "stringArray", default: [] },
65+
postRunCommands: { type: "stringArray", default: [] },
66+
stopCommands: { type: "stringArray", default: [] },
67+
exitCommands: { type: "stringArray", default: [] },
68+
terminateCommands: { type: "stringArray", default: [] },
6569
};
6670

6771
export class LLDBDapConfigurationProvider
68-
implements vscode.DebugConfigurationProvider {
69-
constructor(private readonly server: LLDBDapServer) { }
72+
implements vscode.DebugConfigurationProvider
73+
{
74+
constructor(private readonly server: LLDBDapServer) {}
7075

7176
async resolveDebugConfiguration(
7277
folder: vscode.WorkspaceFolder | undefined,
7378
debugConfiguration: vscode.DebugConfiguration,
74-
token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration> {
75-
let config = vscode.workspace.getConfiguration('lldb-dap.defaults');
79+
token?: vscode.CancellationToken,
80+
): Promise<vscode.DebugConfiguration> {
81+
let config = vscode.workspace.getConfiguration("lldb-dap.defaults");
7682
for (const [key, cfg] of Object.entries(configurations)) {
77-
if (Reflect.has(debugConfiguration, key)) continue;
83+
if (Reflect.has(debugConfiguration, key)) {
84+
continue;
85+
}
7886
const value = config.get(key);
79-
if (value === cfg.default) continue;
87+
if (!value || value === cfg.default) {
88+
continue;
89+
}
8090
switch (cfg.type) {
81-
case 'string':
82-
if (typeof value !== 'string')
91+
case "string":
92+
if (typeof value !== "string") {
8393
throw new Error(`Expected ${key} to be a string, got ${value}`);
94+
}
8495
break;
85-
case 'number':
86-
if (typeof value !== 'number')
96+
case "number":
97+
if (typeof value !== "number") {
8798
throw new Error(`Expected ${key} to be a number, got ${value}`);
99+
}
88100
break;
89-
case 'boolean':
90-
if (typeof value !== 'boolean')
101+
case "boolean":
102+
if (typeof value !== "boolean") {
91103
throw new Error(`Expected ${key} to be a boolean, got ${value}`);
104+
}
92105
break;
93-
case 'stringArray':
94-
if (typeof value !== 'object' && Array.isArray(value))
95-
throw new Error(`Expected ${key} to be a array of strings, got ${value}`);
96-
if ((value as string[]).length === 0) continue;
106+
case "stringArray":
107+
if (typeof value !== "object" && Array.isArray(value)) {
108+
throw new Error(
109+
`Expected ${key} to be a array of strings, got ${value}`,
110+
);
111+
}
112+
if ((value as string[]).length === 0) {
113+
continue;
114+
}
97115
break;
98116
}
99117

Lines changed: 96 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,102 @@
11
import * as vscode from "vscode";
22

33
export class LaunchUriHandler implements vscode.UriHandler {
4-
async handleUri(uri: vscode.Uri) {
5-
try {
6-
const params = new URLSearchParams(uri.query);
7-
if (uri.path == '/start') {
8-
// Some properties have default values
9-
let debugConfig: vscode.DebugConfiguration = {
10-
type: 'lldb-dap',
11-
request: 'launch',
12-
name: '',
13-
};
14-
// The `config` parameter allows providing a complete JSON-encoded configuration
15-
const configJson = params.get("config");
16-
if (configJson !== null) {
17-
Object.assign(debugConfig, JSON.parse(configJson));
18-
}
19-
// Furthermore, some frequently used parameters can also be provided as separate parameters
20-
const stringKeys = ["name", "request", "program", "cwd", "debuggerRoot"];
21-
const numberKeys = ["pid"];
22-
const arrayKeys = [
23-
"args", "initCommands", "preRunCommands", "stopCommands", "exitCommands",
24-
"terminateCommands", "launchCommands", "attachCommands"
25-
];
26-
for (const key of stringKeys) {
27-
const value = params.get(key);
28-
if (value) {
29-
debugConfig[key] = value;
30-
}
31-
}
32-
for (const key of numberKeys) {
33-
const value = params.get(key);
34-
if (value) {
35-
debugConfig[key] = Number(value);
36-
}
37-
}
38-
for (const key of arrayKeys) {
39-
// `getAll()` returns an array of strings.
40-
const value = params.getAll(key);
41-
if (value) {
42-
debugConfig[key] = value;
43-
}
44-
}
45-
// Report an error if we received any unknown parameters
46-
const supportedKeys = new Set<string>(["config"].concat(stringKeys).concat(numberKeys).concat(arrayKeys));
47-
const presentKeys = new Set<string>(params.keys());
48-
// FIXME: Use `Set.difference` as soon as ES2024 is widely available
49-
const unknownKeys = new Set<string>();
50-
for (const k of presentKeys.keys()) {
51-
if (!supportedKeys.has(k)) {
52-
unknownKeys.add(k);
53-
}
54-
}
55-
if (unknownKeys.size > 0) {
56-
throw new Error(`Unsupported URL parameters: ${Array.from(unknownKeys.keys()).join(", ")}`);
57-
}
58-
// Prodide a default for the config name
59-
const defaultName = debugConfig.request == 'launch' ? "URL-based Launch" : "URL-based Attach";
60-
debugConfig.name = debugConfig.name || debugConfig.program || defaultName;
61-
// Force the type to `lldb-dap`. We don't want to allow launching any other
62-
// Debug Adapters using this URI scheme.
63-
if (debugConfig.type != "lldb-dap") {
64-
throw new Error(`Unsupported debugger type: ${debugConfig.type}`);
65-
}
66-
await vscode.debug.startDebugging(undefined, debugConfig);
67-
} else {
68-
throw new Error(`Unsupported Uri path: ${uri.path}`);
69-
}
70-
} catch (err) {
71-
if (err instanceof Error) {
72-
await vscode.window.showErrorMessage(`Failed to handle lldb-dap URI request: ${err.message}`);
73-
} else {
74-
await vscode.window.showErrorMessage(`Failed to handle lldb-dap URI request: ${JSON.stringify(err)}`);
75-
}
4+
async handleUri(uri: vscode.Uri) {
5+
try {
6+
const params = new URLSearchParams(uri.query);
7+
if (uri.path == "/start") {
8+
// Some properties have default values
9+
let debugConfig: vscode.DebugConfiguration = {
10+
type: "lldb-dap",
11+
request: "launch",
12+
name: "",
13+
};
14+
// The `config` parameter allows providing a complete JSON-encoded configuration
15+
const configJson = params.get("config");
16+
if (configJson !== null) {
17+
Object.assign(debugConfig, JSON.parse(configJson));
7618
}
19+
// Furthermore, some frequently used parameters can also be provided as separate parameters
20+
const stringKeys = [
21+
"name",
22+
"request",
23+
"program",
24+
"cwd",
25+
"debuggerRoot",
26+
];
27+
const numberKeys = ["pid"];
28+
const arrayKeys = [
29+
"args",
30+
"initCommands",
31+
"preRunCommands",
32+
"stopCommands",
33+
"exitCommands",
34+
"terminateCommands",
35+
"launchCommands",
36+
"attachCommands",
37+
];
38+
for (const key of stringKeys) {
39+
const value = params.get(key);
40+
if (value) {
41+
debugConfig[key] = value;
42+
}
43+
}
44+
for (const key of numberKeys) {
45+
const value = params.get(key);
46+
if (value) {
47+
debugConfig[key] = Number(value);
48+
}
49+
}
50+
for (const key of arrayKeys) {
51+
// `getAll()` returns an array of strings.
52+
const value = params.getAll(key);
53+
if (value) {
54+
debugConfig[key] = value;
55+
}
56+
}
57+
// Report an error if we received any unknown parameters
58+
const supportedKeys = new Set<string>(
59+
["config"].concat(stringKeys).concat(numberKeys).concat(arrayKeys),
60+
);
61+
const presentKeys = new Set<string>(params.keys());
62+
// FIXME: Use `Set.difference` as soon as ES2024 is widely available
63+
const unknownKeys = new Set<string>();
64+
for (const k of presentKeys.keys()) {
65+
if (!supportedKeys.has(k)) {
66+
unknownKeys.add(k);
67+
}
68+
}
69+
if (unknownKeys.size > 0) {
70+
throw new Error(
71+
`Unsupported URL parameters: ${Array.from(unknownKeys.keys()).join(", ")}`,
72+
);
73+
}
74+
// Prodide a default for the config name
75+
const defaultName =
76+
debugConfig.request == "launch"
77+
? "URL-based Launch"
78+
: "URL-based Attach";
79+
debugConfig.name =
80+
debugConfig.name || debugConfig.program || defaultName;
81+
// Force the type to `lldb-dap`. We don't want to allow launching any other
82+
// Debug Adapters using this URI scheme.
83+
if (debugConfig.type != "lldb-dap") {
84+
throw new Error(`Unsupported debugger type: ${debugConfig.type}`);
85+
}
86+
await vscode.debug.startDebugging(undefined, debugConfig);
87+
} else {
88+
throw new Error(`Unsupported Uri path: ${uri.path}`);
89+
}
90+
} catch (err) {
91+
if (err instanceof Error) {
92+
await vscode.window.showErrorMessage(
93+
`Failed to handle lldb-dap URI request: ${err.message}`,
94+
);
95+
} else {
96+
await vscode.window.showErrorMessage(
97+
`Failed to handle lldb-dap URI request: ${JSON.stringify(err)}`,
98+
);
99+
}
77100
}
101+
}
78102
}

0 commit comments

Comments
 (0)