@@ -26,6 +26,7 @@ import { getReadonlyEmptyArray } from '../utils.js';
26
26
import { groupByMap } from '../../../../../base/common/collections.js' ;
27
27
import { DirectedGraph } from './graph.js' ;
28
28
import { CachedFunction } from '../../../../../base/common/cache.js' ;
29
+ import { InlineCompletionViewKind } from '../view/inlineEdits/inlineEditsViewInterface.js' ;
29
30
30
31
export type InlineCompletionContextWithoutUuid = Omit < InlineCompletionContext , 'requestUuid' > ;
31
32
@@ -34,7 +35,7 @@ export async function provideInlineCompletions(
34
35
position : Position ,
35
36
model : ITextModel ,
36
37
context : InlineCompletionContextWithoutUuid ,
37
- editorType : string ,
38
+ editorType : InlineCompletionEditorType ,
38
39
baseToken : CancellationToken = CancellationToken . None ,
39
40
languageConfigurationService ?: ILanguageConfigurationService ,
40
41
) : Promise < InlineCompletionProviderResult > {
@@ -197,7 +198,7 @@ function createInlineCompletionItem(
197
198
textModel : ITextModel ,
198
199
languageConfigurationService : ILanguageConfigurationService | undefined ,
199
200
context : InlineCompletionContext ,
200
- editorType : string ,
201
+ editorType : InlineCompletionEditorType ,
201
202
) : InlineSuggestData {
202
203
let insertText : string ;
203
204
let snippetInfo : SnippetInfo | undefined ;
@@ -276,13 +277,18 @@ function createInlineCompletionItem(
276
277
}
277
278
278
279
export type InlineSuggestViewData = {
279
- editorType : string ;
280
- viewKind ?: string ;
280
+ editorType : InlineCompletionEditorType ;
281
+ viewKind ?: InlineCompletionViewKind ;
281
282
error ?: string ;
282
283
} ;
283
284
284
285
export class InlineSuggestData {
285
286
private _didShow = false ;
287
+ private _showStartTime : number | undefined = undefined ;
288
+ private _shownDuration : number = 0 ;
289
+ private _showUncollapsedStartTime : number | undefined = undefined ;
290
+ private _showUncollapsedDuration : number = 0 ;
291
+
286
292
private _viewData : InlineSuggestViewData ;
287
293
private _didReportEndOfLife = false ;
288
294
private _lastSetEndOfLifeReason : InlineCompletionEndOfLifeReason | undefined = undefined ;
@@ -299,7 +305,7 @@ export class InlineSuggestData {
299
305
public readonly context : InlineCompletionContext ,
300
306
public readonly isInlineEdit : boolean ,
301
307
302
- editorType : string ,
308
+ editorType : InlineCompletionEditorType ,
303
309
) {
304
310
this . _viewData = { editorType } ;
305
311
}
@@ -310,7 +316,9 @@ export class InlineSuggestData {
310
316
return new TextReplacement ( this . range , this . insertText ) ;
311
317
}
312
318
313
- public async reportInlineEditShown ( commandService : ICommandService , updatedInsertText : string , viewKind : string ) : Promise < void > {
319
+ public async reportInlineEditShown ( commandService : ICommandService , updatedInsertText : string , viewKind : InlineCompletionViewKind ) : Promise < void > {
320
+ this . updateShownDuration ( viewKind ) ;
321
+
314
322
if ( this . _didShow ) {
315
323
return ;
316
324
}
@@ -343,6 +351,7 @@ export class InlineSuggestData {
343
351
return ;
344
352
}
345
353
this . _didReportEndOfLife = true ;
354
+ this . reportInlineEditHidden ( ) ;
346
355
347
356
if ( ! reason ) {
348
357
reason = this . _lastSetEndOfLifeReason ?? { kind : InlineCompletionEndOfLifeReasonKind . Ignored , userTypingDisagreed : false , supersededBy : undefined } ;
@@ -356,9 +365,11 @@ export class InlineSuggestData {
356
365
const summary : LifetimeSummary = {
357
366
requestUuid : this . context . requestUuid ,
358
367
shown : this . _didShow ,
368
+ shownDuration : this . _shownDuration ,
369
+ shownDurationUncollapsed : this . _showUncollapsedDuration ,
359
370
editorType : this . _viewData . editorType ,
360
371
viewKind : this . _viewData . viewKind ,
361
- error : this . _viewData . error
372
+ error : this . _viewData . error ,
362
373
} ;
363
374
this . source . provider . handleEndOfLifetime ( this . source . inlineSuggestions , this . sourceInlineCompletion , reason , summary ) ;
364
375
}
@@ -376,8 +387,40 @@ export class InlineSuggestData {
376
387
* Sets the end of life reason, but does not send the event to the provider yet.
377
388
*/
378
389
public setEndOfLifeReason ( reason : InlineCompletionEndOfLifeReason ) : void {
390
+ this . reportInlineEditHidden ( ) ;
379
391
this . _lastSetEndOfLifeReason = reason ;
380
392
}
393
+
394
+ private updateShownDuration ( viewKind : InlineCompletionViewKind ) {
395
+ const timeNow = Date . now ( ) ;
396
+ if ( ! this . _showStartTime ) {
397
+ this . _showStartTime = timeNow ;
398
+ }
399
+
400
+ const isCollapsed = viewKind === InlineCompletionViewKind . Collapsed ;
401
+ if ( ! isCollapsed && this . _showUncollapsedStartTime === undefined ) {
402
+ this . _showUncollapsedStartTime = timeNow ;
403
+ }
404
+
405
+ if ( isCollapsed && this . _showUncollapsedStartTime !== undefined ) {
406
+ this . _showUncollapsedDuration += timeNow - this . _showUncollapsedStartTime ;
407
+ }
408
+ }
409
+
410
+ private reportInlineEditHidden ( ) {
411
+ if ( this . _showStartTime === undefined ) {
412
+ return ;
413
+ }
414
+ const timeNow = Date . now ( ) ;
415
+ this . _shownDuration += timeNow - this . _showStartTime ;
416
+ this . _showStartTime = undefined ;
417
+
418
+ if ( this . _showUncollapsedStartTime === undefined ) {
419
+ return ;
420
+ }
421
+ this . _showUncollapsedDuration += timeNow - this . _showUncollapsedStartTime ;
422
+ this . _showUncollapsedStartTime = undefined ;
423
+ }
381
424
}
382
425
383
426
export interface SnippetInfo {
@@ -391,6 +434,11 @@ export interface IDisplayLocation {
391
434
label : string ;
392
435
}
393
436
437
+ export enum InlineCompletionEditorType {
438
+ TextEditor = 'textEditor' ,
439
+ DiffEditor = 'diffEditor'
440
+ }
441
+
394
442
/**
395
443
* A ref counted pointer to the computed `InlineCompletions` and the `InlineCompletionsProvider` that
396
444
* computed them.
0 commit comments