@@ -11,6 +11,7 @@ import * as vscode from "vscode";
11
11
import {
12
12
isCircuitDocument ,
13
13
isOpenQasmDocument ,
14
+ isOpenQasmNotebookCell ,
14
15
isQsharpDocument ,
15
16
isQsharpNotebookCell ,
16
17
openqasmLanguageId ,
@@ -212,71 +213,41 @@ function registerDocumentUpdateHandlers(
212
213
languageService : ILanguageService ,
213
214
) : vscode . Disposable [ ] {
214
215
vscode . workspace . textDocuments . forEach ( ( document ) => {
215
- updateIfQsharpDocument ( document ) ;
216
- updateIfOpenQasmDocument ( document ) ;
216
+ updateIfSupportedDocument ( document ) ;
217
217
} ) ;
218
218
219
219
// we manually send an OpenDocument telemetry event if this is a Q# document, because the
220
220
// below subscriptions won't fire for documents that are already open when the extension is activated
221
221
vscode . workspace . textDocuments . forEach ( ( document ) => {
222
- if ( isQsharpDocument ( document ) ) {
223
- const documentType = isQsharpNotebookCell ( document )
224
- ? QsharpDocumentType . JupyterCell
225
- : isCircuitDocument ( document )
226
- ? QsharpDocumentType . Circuit
227
- : QsharpDocumentType . Qsharp ;
228
- sendTelemetryEvent (
229
- EventType . OpenedDocument ,
230
- { documentType } ,
231
- { linesOfCode : document . lineCount } ,
232
- ) ;
233
- }
234
- if ( isOpenQasmDocument ( document ) ) {
235
- const documentType = QsharpDocumentType . OpenQasm ;
236
- sendTelemetryEvent (
237
- EventType . OpenedDocument ,
238
- { documentType } ,
239
- { linesOfCode : document . lineCount } ,
240
- ) ;
241
- }
222
+ sendDocumentOpenedEvent ( document ) ;
242
223
} ) ;
243
224
244
225
const subscriptions = [ ] ;
245
226
subscriptions . push (
246
227
vscode . workspace . onDidOpenTextDocument ( ( document ) => {
247
- const documentType = isQsharpNotebookCell ( document )
248
- ? QsharpDocumentType . JupyterCell
249
- : isCircuitDocument ( document )
250
- ? QsharpDocumentType . Circuit
251
- : isQsharpDocument ( document )
252
- ? QsharpDocumentType . Qsharp
253
- : isOpenQasmDocument ( document )
254
- ? QsharpDocumentType . OpenQasm
255
- : QsharpDocumentType . Other ;
228
+ const documentType = determineDocumentType ( document ) ;
256
229
if ( documentType !== QsharpDocumentType . Other ) {
257
230
sendTelemetryEvent (
258
231
EventType . OpenedDocument ,
259
232
{ documentType } ,
260
233
{ linesOfCode : document . lineCount } ,
261
234
) ;
262
235
}
263
- updateIfQsharpDocument ( document ) ;
264
- updateIfOpenQasmDocument ( document ) ;
236
+ updateIfSupportedDocument ( document ) ;
265
237
} ) ,
266
238
) ;
267
239
268
240
subscriptions . push (
269
241
vscode . workspace . onDidChangeTextDocument ( ( evt ) => {
270
- updateIfQsharpDocument ( evt . document ) ;
271
- updateIfOpenQasmDocument ( evt . document ) ;
242
+ updateIfSupportedDocument ( evt . document ) ;
272
243
} ) ,
273
244
) ;
274
245
275
246
subscriptions . push (
276
247
vscode . workspace . onDidCloseTextDocument ( ( document ) => {
277
248
if (
278
249
( isQsharpDocument ( document ) && ! isQsharpNotebookCell ( document ) ) ||
279
- ( isOpenQasmDocument ( document ) && ! isQsharpNotebookCell ( document ) )
250
+ ( isOpenQasmDocument ( document ) && ! isOpenQasmNotebookCell ( document ) )
280
251
) {
281
252
languageService . closeDocument ( document . uri . toString ( ) ) ;
282
253
}
@@ -333,7 +304,7 @@ function registerDocumentUpdateHandlers(
333
304
}
334
305
335
306
async function updateIfOpenQasmDocument ( document : vscode . TextDocument ) {
336
- if ( isOpenQasmDocument ( document ) && ! isQsharpNotebookCell ( document ) ) {
307
+ if ( isOpenQasmDocument ( document ) && ! isOpenQasmNotebookCell ( document ) ) {
337
308
const content = document . getText ( ) ;
338
309
339
310
languageService . updateDocument (
@@ -344,9 +315,45 @@ function registerDocumentUpdateHandlers(
344
315
}
345
316
}
346
317
318
+ async function updateIfSupportedDocument ( document : vscode . TextDocument ) {
319
+ updateIfQsharpDocument ( document ) ;
320
+ updateIfOpenQasmDocument ( document ) ;
321
+ }
322
+
347
323
return subscriptions ;
348
324
}
349
325
326
+ function determineDocumentType ( document : vscode . TextDocument ) {
327
+ return isQsharpNotebookCell ( document ) || isOpenQasmNotebookCell ( document )
328
+ ? QsharpDocumentType . JupyterCell
329
+ : isCircuitDocument ( document )
330
+ ? QsharpDocumentType . Circuit
331
+ : isQsharpDocument ( document )
332
+ ? QsharpDocumentType . Qsharp
333
+ : isOpenQasmDocument ( document )
334
+ ? QsharpDocumentType . OpenQasm
335
+ : QsharpDocumentType . Other ;
336
+ }
337
+
338
+ function sendDocumentOpenedEvent ( document : vscode . TextDocument ) {
339
+ if ( isQsharpDocument ( document ) ) {
340
+ const documentType = determineDocumentType ( document ) ;
341
+ sendTelemetryEvent (
342
+ EventType . OpenedDocument ,
343
+ { documentType } ,
344
+ { linesOfCode : document . lineCount } ,
345
+ ) ;
346
+ }
347
+ if ( isOpenQasmDocument ( document ) ) {
348
+ const documentType = QsharpDocumentType . OpenQasm ;
349
+ sendTelemetryEvent (
350
+ EventType . OpenedDocument ,
351
+ { documentType } ,
352
+ { linesOfCode : document . lineCount } ,
353
+ ) ;
354
+ }
355
+ }
356
+
350
357
function registerConfigurationChangeHandlers (
351
358
languageService : ILanguageService ,
352
359
) {
0 commit comments