Skip to content

Commit c81cd8d

Browse files
joao-boechatjoao-boechat
andauthored
Simplify debugger breaking (#3034)
This PR resolves [issue 2646](#2646) by changing the default behavior of qdk debugger, so that it won't stop on entry. --------- Co-authored-by: joao-boechat <joaoboehcat@microsoft.com>
1 parent c2bf9ed commit c81cd8d

File tree

3 files changed

+34
-49
lines changed

3 files changed

+34
-49
lines changed

source/vscode/src/debugger/activate.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function registerCommands(context: vscode.ExtensionContext) {
7171
}
7272
startQdkDebugging(resource, {
7373
name: "QDK: Debug Program",
74-
stopOnEntry: true,
7574
entry: expr,
7675
});
7776
},
@@ -83,7 +82,6 @@ function registerCommands(context: vscode.ExtensionContext) {
8382
resource,
8483
{
8584
name: "QDK: Run and Show Circuit",
86-
stopOnEntry: false,
8785
showCircuit: true,
8886
},
8987
{ noDebug: true },
@@ -159,18 +157,11 @@ class QsDebugConfigProvider implements vscode.DebugConfigurationProvider {
159157
path: fileUri.path,
160158
})
161159
.toString();
162-
} else {
163-
// if launch.json is missing or empty, try to launch the active Q# document
160+
} else if (!config.programUri) {
161+
// if config.programUri is not already set, try to default to the currently active document
164162
const docUri = getActiveQdkDocumentUri();
165163
if (docUri) {
166-
config.type = "qsharp";
167-
config.name = "Launch";
168-
config.request = "launch";
169164
config.programUri = docUri.toString();
170-
config.shots = 1;
171-
config.noDebug = "noDebug" in config ? config.noDebug : false;
172-
config.stopOnEntry = !config.noDebug;
173-
config.entry = config.entry ?? "";
174165
}
175166
}
176167

@@ -208,9 +199,9 @@ class QsDebugConfigProvider implements vscode.DebugConfigurationProvider {
208199
// noDebug is set to true when the user runs the program without debugging.
209200
// otherwise it usually isn't set, but we default to false.
210201
config.noDebug = config.noDebug ?? false;
211-
// stopOnEntry is set to true when the user runs the program with debugging.
202+
// stopOnEntry is set to false when the user runs the program with debugging.
212203
// unless overridden.
213-
config.stopOnEntry = config.stopOnEntry ?? !config.noDebug;
204+
config.stopOnEntry = config.stopOnEntry ?? false;
214205

215206
return config;
216207
}

source/vscode/test/suites/debugger/openqasm.test.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,21 @@ suite("OpenQASM Debugger Tests", function suite() {
5252
test("Launch with debugProgram command", async () => {
5353
await vscode.window.showTextDocument(selfContainedUri);
5454

55-
// launch debugger
55+
// Listen for session end before launching to avoid a race
56+
const sessionEnded = new Promise<void>((resolve, reject) => {
57+
vscode.debug.onDidTerminateDebugSession(() => {
58+
resolve();
59+
});
60+
setTimeout(
61+
() =>
62+
reject(new Error("Timed out waiting for debug session to terminate")),
63+
2000,
64+
);
65+
});
66+
5667
await vscode.commands.executeCommand(`${qsharpExtensionId}.debugProgram`);
5768

58-
await waitUntilPausedAndAssertStackTrace([
59-
{
60-
id: 0,
61-
source: {
62-
name: selfContainedName,
63-
path: `vscode-test-web://mount/${selfContainedName}`,
64-
sourceReference: 0,
65-
adapterData: "qsharp-adapter-data",
66-
},
67-
line: 5,
68-
column: 1,
69-
name: "program ",
70-
endLine: 5,
71-
endColumn: 9,
72-
},
73-
{ id: 0, line: 0, column: 0, name: "entry", source: undefined },
74-
]);
69+
await sessionEnded;
7570
});
7671

7772
test("Launch with launch.json configuration - workspaceFolder substitution", async () => {
@@ -82,6 +77,7 @@ suite("OpenQASM Debugger Tests", function suite() {
8277
type: "qsharp",
8378
request: "launch",
8479
program: "${workspaceFolder}" + `${selfContainedName}`,
80+
stopOnEntry: true,
8581
});
8682

8783
await waitUntilPausedAndAssertStackTrace([
@@ -112,6 +108,7 @@ suite("OpenQASM Debugger Tests", function suite() {
112108
type: "qsharp",
113109
request: "launch",
114110
program: "${file}",
111+
stopOnEntry: true,
115112
});
116113

117114
await waitUntilPausedAndAssertStackTrace([

source/vscode/test/suites/debugger/qsharp.test.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,21 @@ suite("Q# Debugger Tests", function suite() {
4242
test("Launch with debugProgram command", async () => {
4343
await vscode.window.showTextDocument(fooUri);
4444

45-
// launch debugger
45+
// Listen for session end before launching to avoid a race
46+
const sessionEnded = new Promise<void>((resolve, reject) => {
47+
vscode.debug.onDidTerminateDebugSession(() => {
48+
resolve();
49+
});
50+
setTimeout(
51+
() =>
52+
reject(new Error("Timed out waiting for debug session to terminate")),
53+
2000,
54+
);
55+
});
56+
4657
await vscode.commands.executeCommand(`${qsharpExtensionId}.debugProgram`);
4758

48-
await waitUntilPausedAndAssertStackTrace([
49-
{
50-
id: 0,
51-
source: {
52-
name: "foo.qs",
53-
path: "vscode-test-web://mount/src/foo.qs",
54-
sourceReference: 0,
55-
adapterData: "qsharp-adapter-data",
56-
},
57-
line: 5,
58-
column: 9,
59-
name: "Foo ",
60-
endLine: 5,
61-
endColumn: 15,
62-
},
63-
{ id: 0, line: 0, column: 0, name: "entry", source: undefined },
64-
]);
59+
await sessionEnded;
6560
});
6661

6762
test("Launch with launch.json configuration - workspaceFolder substitution", async () => {
@@ -72,6 +67,7 @@ suite("Q# Debugger Tests", function suite() {
7267
type: "qsharp",
7368
request: "launch",
7469
program: "${workspaceFolder}src/foo.qs",
70+
stopOnEntry: true,
7571
});
7672

7773
await waitUntilPausedAndAssertStackTrace([
@@ -102,6 +98,7 @@ suite("Q# Debugger Tests", function suite() {
10298
type: "qsharp",
10399
request: "launch",
104100
program: "${file}",
101+
stopOnEntry: true,
105102
});
106103

107104
await waitUntilPausedAndAssertStackTrace([

0 commit comments

Comments
 (0)