Skip to content

Commit 48d5fef

Browse files
author
Elaheh Rashedi
authored
bypass launch.json (#6072)
1 parent abde9a3 commit 48d5fef

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

Extension/src/Debugger/extension.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,17 @@ export function initialize(context: vscode.ExtensionContext): void {
108108

109109
// Attempt to use the user's (possibly) modified configuration before using the generated one.
110110
try {
111-
await vscode.debug.startDebugging(folder, selection.configuration.name);
112-
Telemetry.logDebuggerEvent("buildAndDebug", { "success": "true" });
111+
await util.ensureDebugConfigExists(selection.configuration.name);
112+
try {
113+
await vscode.debug.startDebugging(folder, selection.configuration.name);
114+
Telemetry.logDebuggerEvent("buildAndDebug", { "success": "true" });
115+
} catch (e) {
116+
Telemetry.logDebuggerEvent("buildAndDebug", { "success": "false" });
117+
}
113118
} catch (e) {
114119
try {
115120
vscode.debug.startDebugging(folder, selection.configuration);
121+
Telemetry.logDebuggerEvent("buildAndDebug", { "success": "true" });
116122
} catch (e) {
117123
Telemetry.logDebuggerEvent("buildAndDebug", { "success": "false" });
118124
}

Extension/src/common.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ export function getRawPackageJson(): any {
6262
return rawPackageJson;
6363
}
6464

65+
export async function getRawLaunchJson(): Promise<any> {
66+
const path: string | undefined = getLaunchJsonPath();
67+
return getRawJson(path);
68+
}
69+
6570
export async function getRawTasksJson(): Promise<any> {
6671
const path: string | undefined = getTasksJsonPath();
72+
return getRawJson(path);
73+
}
74+
75+
async function getRawJson(path: string | undefined): Promise<any> {
6776
if (!path) {
6877
return {};
6978
}
@@ -82,6 +91,24 @@ export async function getRawTasksJson(): Promise<any> {
8291
return rawTasks;
8392
}
8493

94+
export async function ensureDebugConfigExists(configName: string): Promise<void> {
95+
const launchJsonPath: string | undefined = getLaunchJsonPath();
96+
if (!launchJsonPath) {
97+
throw new Error("Failed to get launchJsonPath in ensureDebugConfigExists()");
98+
}
99+
100+
const rawLaunchJson: any = await getRawLaunchJson();
101+
// Ensure that the debug configurations exists in the user's launch.json. Config will not be found otherwise.
102+
if (!rawLaunchJson || !rawLaunchJson.configurations) {
103+
throw new Error(`Configuration '${configName}' is missing in 'launch.json'.`);
104+
}
105+
const selectedConfig: vscode.Task | undefined = rawLaunchJson.configurations.find((config: any) => config.name && config.name === configName);
106+
if (!selectedConfig) {
107+
throw new Error(`Configuration '${configName}' is missing in 'launch.json'.`);
108+
}
109+
return;
110+
}
111+
85112
export async function ensureBuildTaskExists(taskLabel: string): Promise<void> {
86113
const rawTasksJson: any = await getRawTasksJson();
87114

@@ -159,7 +186,15 @@ export function getPackageJsonPath(): string {
159186
return getExtensionFilePath("package.json");
160187
}
161188

189+
export function getLaunchJsonPath(): string | undefined {
190+
return getJsonPath("launch.json");
191+
}
192+
162193
export function getTasksJsonPath(): string | undefined {
194+
return getJsonPath("tasks.json");
195+
}
196+
197+
function getJsonPath(jsonFilaName: string): string | undefined {
163198
const editor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
164199
if (!editor) {
165200
return undefined;
@@ -168,7 +203,7 @@ export function getTasksJsonPath(): string | undefined {
168203
if (!folder) {
169204
return undefined;
170205
}
171-
return path.join(folder.uri.fsPath, ".vscode", "tasks.json");
206+
return path.join(folder.uri.fsPath, ".vscode", jsonFilaName);
172207
}
173208

174209
export function getVcpkgPathDescriptorFile(): string {

0 commit comments

Comments
 (0)