Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions source/vscode/src/debugger/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function registerCommands(context: vscode.ExtensionContext) {
}
startQdkDebugging(resource, {
name: "QDK: Debug Program",
stopOnEntry: true,
entry: expr,
});
},
Expand All @@ -83,7 +82,6 @@ function registerCommands(context: vscode.ExtensionContext) {
resource,
{
name: "QDK: Run and Show Circuit",
stopOnEntry: false,
showCircuit: true,
},
{ noDebug: true },
Expand Down Expand Up @@ -159,18 +157,11 @@ class QsDebugConfigProvider implements vscode.DebugConfigurationProvider {
path: fileUri.path,
})
.toString();
} else {
// if launch.json is missing or empty, try to launch the active Q# document
} else if (!config.programUri) {
// if config.programUri is not already set, try to default to the currently active document
const docUri = getActiveQdkDocumentUri();
if (docUri) {
config.type = "qsharp";
config.name = "Launch";
config.request = "launch";
config.programUri = docUri.toString();
config.shots = 1;
config.noDebug = "noDebug" in config ? config.noDebug : false;
config.stopOnEntry = !config.noDebug;
config.entry = config.entry ?? "";
}
}

Expand Down Expand Up @@ -208,9 +199,9 @@ class QsDebugConfigProvider implements vscode.DebugConfigurationProvider {
// noDebug is set to true when the user runs the program without debugging.
// otherwise it usually isn't set, but we default to false.
config.noDebug = config.noDebug ?? false;
// stopOnEntry is set to true when the user runs the program with debugging.
// stopOnEntry is set to false when the user runs the program with debugging.
// unless overridden.
config.stopOnEntry = config.stopOnEntry ?? !config.noDebug;
config.stopOnEntry = config.stopOnEntry ?? false;

return config;
}
Expand Down
33 changes: 15 additions & 18 deletions source/vscode/test/suites/debugger/openqasm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,21 @@
test("Launch with debugProgram command", async () => {
await vscode.window.showTextDocument(selfContainedUri);

// launch debugger
// Listen for session end before launching to avoid a race
const sessionEnded = new Promise<void>((resolve, reject) => {
vscode.debug.onDidTerminateDebugSession(() => {
resolve();
});
setTimeout(
() =>
reject(new Error("Timed out waiting for debug session to terminate")),
2000,
);
});

await vscode.commands.executeCommand(`${qsharpExtensionId}.debugProgram`);

await waitUntilPausedAndAssertStackTrace([
{
id: 0,
source: {
name: selfContainedName,
path: `vscode-test-web://mount/${selfContainedName}`,
sourceReference: 0,
adapterData: "qsharp-adapter-data",
},
line: 5,
column: 1,
name: "program ",
endLine: 5,
endColumn: 9,
},
{ id: 0, line: 0, column: 0, name: "entry", source: undefined },
]);
await sessionEnded;
});

test("Launch with launch.json configuration - workspaceFolder substitution", async () => {
Expand All @@ -82,6 +77,7 @@
type: "qsharp",
request: "launch",
program: "${workspaceFolder}" + `${selfContainedName}`,
stopOnEntry: true,
});

await waitUntilPausedAndAssertStackTrace([
Expand Down Expand Up @@ -112,6 +108,7 @@
type: "qsharp",
request: "launch",
program: "${file}",
stopOnEntry: true,
});

await waitUntilPausedAndAssertStackTrace([
Expand Down
33 changes: 15 additions & 18 deletions source/vscode/test/suites/debugger/qsharp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,21 @@
test("Launch with debugProgram command", async () => {
await vscode.window.showTextDocument(fooUri);

// launch debugger
// Listen for session end before launching to avoid a race
const sessionEnded = new Promise<void>((resolve, reject) => {
vscode.debug.onDidTerminateDebugSession(() => {
resolve();
});
setTimeout(
() =>
reject(new Error("Timed out waiting for debug session to terminate")),
2000,
);
});

await vscode.commands.executeCommand(`${qsharpExtensionId}.debugProgram`);

await waitUntilPausedAndAssertStackTrace([
{
id: 0,
source: {
name: "foo.qs",
path: "vscode-test-web://mount/src/foo.qs",
sourceReference: 0,
adapterData: "qsharp-adapter-data",
},
line: 5,
column: 9,
name: "Foo ",
endLine: 5,
endColumn: 15,
},
{ id: 0, line: 0, column: 0, name: "entry", source: undefined },
]);
await sessionEnded;
});

test("Launch with launch.json configuration - workspaceFolder substitution", async () => {
Expand All @@ -72,6 +67,7 @@
type: "qsharp",
request: "launch",
program: "${workspaceFolder}src/foo.qs",
stopOnEntry: true,
});

await waitUntilPausedAndAssertStackTrace([
Expand Down Expand Up @@ -102,6 +98,7 @@
type: "qsharp",
request: "launch",
program: "${file}",
stopOnEntry: true,
});

await waitUntilPausedAndAssertStackTrace([
Expand Down
Loading