@@ -244,7 +244,7 @@ export class InteractiveClient {
244
244
245
245
}
246
246
247
- completion ( kernelName : string , code : string , line : number , character : number ) : Promise < CompletionsProduced > {
247
+ async completion ( kernelName : string , code : string , line : number , character : number ) : Promise < CompletionsProduced > {
248
248
249
249
const command = new KernelCommandEnvelope (
250
250
RequestCompletionsType ,
@@ -257,10 +257,16 @@ export class InteractiveClient {
257
257
targetKernelName : kernelName
258
258
}
259
259
) ;
260
- return this . submitCommandAndGetResult < CompletionsProduced > ( command , CompletionsProducedType ) ;
260
+ let result = await this . submitCommandAndGetResult < CompletionsProduced > ( command , CompletionsProducedType , true ) ;
261
+ if ( result === undefined ) {
262
+ result = {
263
+ completions : [ ]
264
+ } ;
265
+ }
266
+ return result ! ;
261
267
}
262
268
263
- hover ( language : string , code : string , line : number , character : number ) : Promise < HoverTextProduced > {
269
+ async hover ( language : string , code : string , line : number , character : number ) : Promise < HoverTextProduced > {
264
270
const command = new KernelCommandEnvelope (
265
271
RequestHoverTextType ,
266
272
< RequestHoverText > {
@@ -272,10 +278,16 @@ export class InteractiveClient {
272
278
targetKernelName : language
273
279
}
274
280
) ;
275
- return this . submitCommandAndGetResult < HoverTextProduced > ( command , HoverTextProducedType ) ;
281
+ let result = await this . submitCommandAndGetResult < HoverTextProduced > ( command , HoverTextProducedType , true ) ;
282
+ if ( result === undefined ) {
283
+ result = {
284
+ content : [ ]
285
+ } ;
286
+ }
287
+ return result ! ;
276
288
}
277
289
278
- signatureHelp ( language : string , code : string , line : number , character : number ) : Promise < SignatureHelpProduced > {
290
+ async signatureHelp ( language : string , code : string , line : number , character : number ) : Promise < SignatureHelpProduced > {
279
291
const command = new KernelCommandEnvelope (
280
292
RequestSignatureHelpType ,
281
293
< RequestSignatureHelp > {
@@ -287,7 +299,15 @@ export class InteractiveClient {
287
299
targetKernelName : language
288
300
}
289
301
) ;
290
- return this . submitCommandAndGetResult < SignatureHelpProduced > ( command , SignatureHelpProducedType ) ;
302
+ let result = await this . submitCommandAndGetResult < SignatureHelpProduced > ( command , SignatureHelpProducedType , true ) ;
303
+ if ( result === undefined ) {
304
+ result = {
305
+ activeParameterIndex : 0 ,
306
+ activeSignatureIndex : 0 ,
307
+ signatures : [ ]
308
+ } ;
309
+ }
310
+ return result ! ;
291
311
}
292
312
293
313
async getDiagnostics ( kernelName : string , code : string ) : Promise < Array < Diagnostic > > {
@@ -299,7 +319,10 @@ export class InteractiveClient {
299
319
}
300
320
) ;
301
321
302
- const diagsProduced = await this . submitCommandAndGetResult < DiagnosticsProduced > ( command , DiagnosticsProducedType ) ;
322
+ let diagsProduced = await this . submitCommandAndGetResult < DiagnosticsProduced > ( command , DiagnosticsProducedType , true ) ;
323
+ if ( diagsProduced === undefined ) {
324
+ return [ ] ;
325
+ }
303
326
return diagsProduced . diagnostics ;
304
327
}
305
328
@@ -318,18 +341,19 @@ export class InteractiveClient {
318
341
return disposable ;
319
342
}
320
343
321
- requestValueInfos ( kernelName : string ) : Promise < ValueInfosProduced > {
344
+ async requestValueInfos ( kernelName : string ) : Promise < ValueInfosProduced > {
322
345
const command = new KernelCommandEnvelope (
323
346
RequestValueInfosType ,
324
347
< RequestValueInfos > {
325
348
targetKernelName : kernelName ,
326
349
mimeType : "text/plain+summary"
327
350
}
328
351
) ;
329
- return this . submitCommandAndGetResult ( command , ValueInfosProducedType ) ;
352
+ const result = await ( this . submitCommandAndGetResult < ValueInfosProduced > ( command , ValueInfosProducedType ) ) ;
353
+ return result ! ;
330
354
}
331
355
332
- requestValue ( valueName : string , kernelName : string ) : Promise < ValueProduced > {
356
+ async requestValue ( valueName : string , kernelName : string ) : Promise < ValueProduced > {
333
357
const command = new KernelCommandEnvelope (
334
358
RequestValueType ,
335
359
< RequestValue > {
@@ -338,7 +362,8 @@ export class InteractiveClient {
338
362
targetKernelName : kernelName ,
339
363
}
340
364
) ;
341
- return this . submitCommandAndGetResult ( command , ValueProducedType ) ;
365
+ const result = await this . submitCommandAndGetResult < ValueProduced > ( command , ValueProducedType ) ;
366
+ return result ! ;
342
367
}
343
368
344
369
cancel ( ) : Promise < void > {
@@ -364,12 +389,12 @@ export class InteractiveClient {
364
389
this . disposables . push ( disposable ) ;
365
390
}
366
391
367
- private submitCommandAndGetResult < TEvent extends KernelEvent > ( command : KernelCommandEnvelope , expectedEventType : KernelEventType ) : Promise < TEvent > {
368
- return new Promise < TEvent > ( async ( resolve , reject ) => {
392
+ private submitCommandAndGetResult < TEvent extends KernelEvent > ( command : KernelCommandEnvelope , expectedEventType : KernelEventType , eventIsOptional = false ) : Promise < TEvent | undefined > {
393
+ return new Promise < TEvent | undefined > ( async ( resolve , reject ) => {
369
394
let handled = false ;
370
395
const token = command . getOrCreateToken ( ) ;
371
396
let disposable = this . subscribeToKernelTokenEvents ( token , eventEnvelope => {
372
- if ( eventEnvelope . command ?. hasSameRootCommandAs ( command ) && eventEnvelope . eventType === expectedEventType ) {
397
+ if ( eventEnvelope . command ?. hasSameRootCommandAs ( command ) ) {
373
398
switch ( eventEnvelope . eventType ) {
374
399
case CommandFailedType :
375
400
if ( ! handled ) {
@@ -383,7 +408,11 @@ export class InteractiveClient {
383
408
if ( ! handled ) {
384
409
handled = true ;
385
410
disposable . dispose ( ) ;
386
- reject ( 'Command was handled before reporting expected result.' ) ;
411
+ if ( eventIsOptional ) {
412
+ resolve ( undefined ) ;
413
+ } else {
414
+ reject ( 'Command was handled before reporting expected result.' ) ;
415
+ }
387
416
}
388
417
break ;
389
418
default :
0 commit comments