@@ -9,10 +9,8 @@ import { qsharpExtensionId } from "../common";
9
9
import { clearCommandDiagnostics } from "../diagnostics" ;
10
10
import {
11
11
FullProgramConfigOrError ,
12
- getActiveOpenQasmDocumentUri ,
13
- getActiveQSharpDocumentUri ,
14
- getOpenQasmProgramForDocument ,
15
- getQSharpProgramForDocument ,
12
+ getActiveQdkDocumentUri ,
13
+ getProgramForDocument ,
16
14
} from "../programConfig" ;
17
15
import { getRandomGuid } from "../utils" ;
18
16
import { QscDebugSession } from "./session" ;
@@ -35,29 +33,15 @@ export async function activateDebugger(
35
33
36
34
const provider = new QsDebugConfigProvider ( ) ;
37
35
context . subscriptions . push (
38
- vscode . debug . registerDebugConfigurationProvider ( "qsharp " , provider ) ,
36
+ vscode . debug . registerDebugConfigurationProvider ( "qdk " , provider ) ,
39
37
) ;
40
38
41
- const factory = new InlineDebugAdapterFactory ( ( uri ) =>
42
- getQSharpProgramForDocument ( uri ) ,
43
- ) ;
39
+ const factory = new InlineDebugAdapterFactory ( async ( uri ) => {
40
+ const file = await vscode . workspace . openTextDocument ( uri ) ;
41
+ return getProgramForDocument ( file ) ;
42
+ } ) ;
44
43
context . subscriptions . push (
45
- vscode . debug . registerDebugAdapterDescriptorFactory ( "qsharp" , factory ) ,
46
- ) ;
47
-
48
- const qasm_provider = new OpenQasmDebugConfigProvider ( ) ;
49
- context . subscriptions . push (
50
- vscode . debug . registerDebugConfigurationProvider ( "openqasm" , qasm_provider ) ,
51
- ) ;
52
-
53
- const qasm_factory = new InlineDebugAdapterFactory ( ( uri ) =>
54
- getOpenQasmProgramForDocument ( uri ) ,
55
- ) ;
56
- context . subscriptions . push (
57
- vscode . debug . registerDebugAdapterDescriptorFactory (
58
- "openqasm" ,
59
- qasm_factory ,
60
- ) ,
44
+ vscode . debug . registerDebugAdapterDescriptorFactory ( "qdk" , factory ) ,
61
45
) ;
62
46
}
63
47
@@ -72,9 +56,9 @@ function registerCommands(context: vscode.ExtensionContext) {
72
56
if ( typeof expr !== "string" ) {
73
57
expr = undefined ;
74
58
}
75
- startQSharpDebugging (
59
+ startQdkDebugging (
76
60
resource ,
77
- { name : "Run Q# File" , stopOnEntry : false , entry : expr } ,
61
+ { name : "Run File" , stopOnEntry : false , entry : expr } ,
78
62
{ noDebug : true } ,
79
63
) ;
80
64
} ,
@@ -87,8 +71,8 @@ function registerCommands(context: vscode.ExtensionContext) {
87
71
if ( typeof expr !== "string" ) {
88
72
expr = undefined ;
89
73
}
90
- startQSharpDebugging ( resource , {
91
- name : "Debug Q# File" ,
74
+ startQdkDebugging ( resource , {
75
+ name : "Debug File" ,
92
76
stopOnEntry : true ,
93
77
entry : expr ,
94
78
} ) ;
@@ -97,7 +81,7 @@ function registerCommands(context: vscode.ExtensionContext) {
97
81
vscode . commands . registerCommand (
98
82
`${ qsharpExtensionId } .runEditorContentsWithCircuit` ,
99
83
( resource : vscode . Uri ) =>
100
- startQSharpDebugging (
84
+ startQdkDebugging (
101
85
resource ,
102
86
{
103
87
name : "Run file and show circuit diagram" ,
@@ -109,97 +93,31 @@ function registerCommands(context: vscode.ExtensionContext) {
109
93
) ,
110
94
) ;
111
95
112
- function startQSharpDebugging (
96
+ function startQdkDebugging (
113
97
resource : vscode . Uri | undefined ,
114
98
config : { name : string ; [ key : string ] : any } ,
115
99
options ?: vscode . DebugSessionOptions ,
116
100
) {
117
101
clearCommandDiagnostics ( ) ;
118
102
119
- if ( vscode . debug . activeDebugSession ?. type === "qsharp " ) {
103
+ if ( vscode . debug . activeDebugSession ?. type === "qdk " ) {
120
104
// Multiple debug sessions disallowed, to reduce confusion
121
105
return ;
122
106
}
123
107
124
- const targetResource = resource || getActiveQSharpDocumentUri ( ) ;
125
-
126
- if ( targetResource ) {
127
- config . programUri = targetResource . toString ( ) ;
128
-
129
- vscode . debug . startDebugging (
130
- undefined ,
131
- {
132
- type : "qsharp" ,
133
- request : "launch" ,
134
- shots : 1 ,
135
- ...config ,
136
- } ,
137
- {
138
- // no need to save the file, in fact better not to, since it may cause the document uri to change
139
- suppressSaveBeforeStart : true ,
140
- ...options ,
141
- } ,
142
- ) ;
143
- }
144
- }
145
-
146
- // Register commands for running and debugging OpenQASM files.
147
- context . subscriptions . push (
148
- vscode . commands . registerCommand (
149
- `${ qsharpExtensionId } .openqasm.runEditorContents` ,
150
- ( resource : vscode . Uri ) => {
151
- startOpenQasmDebugging (
152
- resource ,
153
- { name : "Run OpenQASM File" , stopOnEntry : false } ,
154
- { noDebug : true } ,
155
- ) ;
156
- } ,
157
- ) ,
158
- vscode . commands . registerCommand (
159
- `${ qsharpExtensionId } .openqasm.debugEditorContents` ,
160
- ( resource : vscode . Uri ) => {
161
- startOpenQasmDebugging ( resource , {
162
- name : "Debug OpenQASM File" ,
163
- stopOnEntry : true ,
164
- } ) ;
165
- } ,
166
- ) ,
167
- vscode . commands . registerCommand (
168
- `${ qsharpExtensionId } .openqasm.runEditorContentsWithCircuit` ,
169
- ( resource : vscode . Uri ) =>
170
- startOpenQasmDebugging (
171
- resource ,
172
- {
173
- name : "Run file and show circuit diagram" ,
174
- stopOnEntry : false ,
175
- showCircuit : true ,
176
- } ,
177
- { noDebug : true } ,
178
- ) ,
179
- ) ,
180
- ) ;
181
-
182
- function startOpenQasmDebugging (
183
- resource : vscode . Uri | undefined ,
184
- config : { name : string ; [ key : string ] : any } ,
185
- options ?: vscode . DebugSessionOptions ,
186
- ) {
187
- clearCommandDiagnostics ( ) ;
188
-
189
- if ( vscode . debug . activeDebugSession ?. type === "openqasm" ) {
190
- // Multiple debug sessions disallowed, to reduce confusion
108
+ const targetResource = resource || getActiveQdkDocumentUri ( ) ;
109
+ if ( ! targetResource ) {
110
+ // No active document
191
111
return ;
192
112
}
193
113
194
- const targetResource = resource || getActiveOpenQasmDocumentUri ( ) ;
195
-
196
114
if ( targetResource ) {
197
115
config . programUri = targetResource . toString ( ) ;
198
116
199
117
vscode . debug . startDebugging (
200
118
undefined ,
201
119
{
202
- type : "openqasm " ,
120
+ type : "qdk " ,
203
121
request : "launch" ,
204
122
shots : 1 ,
205
123
...config ,
@@ -245,9 +163,9 @@ class QsDebugConfigProvider implements vscode.DebugConfigurationProvider {
245
163
. toString ( ) ;
246
164
} else {
247
165
// if launch.json is missing or empty, try to launch the active Q# document
248
- const docUri = getActiveQSharpDocumentUri ( ) ;
166
+ const docUri = getActiveQdkDocumentUri ( ) ;
249
167
if ( docUri ) {
250
- config . type = "qsharp " ;
168
+ config . type = "qdk " ;
251
169
config . name = "Launch" ;
252
170
config . request = "launch" ;
253
171
config . programUri = docUri . toString ( ) ;
@@ -283,7 +201,7 @@ class QsDebugConfigProvider implements vscode.DebugConfigurationProvider {
283
201
_token ?: vscode . CancellationToken | undefined ,
284
202
) : vscode . ProviderResult < vscode . DebugConfiguration > {
285
203
// apply defaults if not set
286
- config . type = config . type ?? "qsharp ";
204
+ config . type = "qdk ";
287
205
config . name = config . name ?? "Launch" ;
288
206
config . request = config . request ?? "launch" ;
289
207
config . shots = config . shots ?? 1 ;
@@ -300,90 +218,6 @@ class QsDebugConfigProvider implements vscode.DebugConfigurationProvider {
300
218
}
301
219
}
302
220
303
- class OpenQasmDebugConfigProvider implements vscode . DebugConfigurationProvider {
304
- resolveDebugConfigurationWithSubstitutedVariables (
305
- folder : vscode . WorkspaceFolder | undefined ,
306
- config : vscode . DebugConfiguration ,
307
- _token ?: vscode . CancellationToken | undefined ,
308
- ) : vscode . ProviderResult < vscode . DebugConfiguration > {
309
- if ( config . program && folder ) {
310
- // A program is specified in launch.json.
311
- //
312
- // Variable substitution is a bit odd in VS Code. Variables such as
313
- // ${file} and ${workspaceFolder} are expanded to absolute filesystem
314
- // paths with platform-specific separators. To correctly convert them
315
- // back to a URI, we need to use the vscode.Uri.file constructor.
316
- //
317
- // However, this gives us the URI scheme file:// , which is not correct
318
- // when the workspace uses a virtual filesystem such as qsharp-vfs://
319
- // or vscode-test-web://. So now we also need the workspace folder URI
320
- // to use as the basis for our file URI.
321
- //
322
- // Examples of program paths that can come through variable substitution:
323
- // C:\foo\bar.qs
324
- // \foo\bar.qs
325
- // /foo/bar.qs
326
- const fileUri = vscode . Uri . file ( config . program ) ;
327
- config . programUri = folder . uri
328
- . with ( {
329
- path : fileUri . path ,
330
- } )
331
- . toString ( ) ;
332
- } else {
333
- // if launch.json is missing or empty, try to launch the active Q# document
334
- const docUri = getActiveOpenQasmDocumentUri ( ) ;
335
- if ( docUri ) {
336
- config . type = "openqasm" ;
337
- config . name = "Launch" ;
338
- config . request = "launch" ;
339
- config . programUri = docUri . toString ( ) ;
340
- config . shots = 1 ;
341
- config . noDebug = "noDebug" in config ? config . noDebug : false ;
342
- config . stopOnEntry = ! config . noDebug ;
343
- }
344
- }
345
-
346
- log . trace (
347
- `resolveDebugConfigurationWithSubstitutedVariables config.program=${
348
- config . program
349
- } folder.uri=${ folder ?. uri . toString ( ) } config.programUri=${
350
- config . programUri
351
- } `,
352
- ) ;
353
-
354
- if ( ! config . programUri ) {
355
- // abort launch
356
- return vscode . window
357
- . showInformationMessage ( "Cannot find a OpenQASM program to debug" )
358
- . then ( ( _ ) => {
359
- return undefined ;
360
- } ) ;
361
- }
362
- return config ;
363
- }
364
-
365
- resolveDebugConfiguration (
366
- folder : vscode . WorkspaceFolder | undefined ,
367
- config : vscode . DebugConfiguration ,
368
- _token ?: vscode . CancellationToken | undefined ,
369
- ) : vscode . ProviderResult < vscode . DebugConfiguration > {
370
- // apply defaults if not set
371
- config . type = config . type ?? "openqasm" ;
372
- config . name = config . name ?? "Launch" ;
373
- config . request = config . request ?? "launch" ;
374
- config . shots = config . shots ?? 1 ;
375
- config . trace = config . trace ?? false ;
376
- // noDebug is set to true when the user runs the program without debugging.
377
- // otherwise it usually isn't set, but we default to false.
378
- config . noDebug = config . noDebug ?? false ;
379
- // stopOnEntry is set to true when the user runs the program with debugging.
380
- // unless overridden.
381
- config . stopOnEntry = config . stopOnEntry ?? ! config . noDebug ;
382
-
383
- return config ;
384
- }
385
- }
386
-
387
221
class InlineDebugAdapterFactory
388
222
implements vscode . DebugAdapterDescriptorFactory
389
223
{
0 commit comments