@@ -45,6 +45,9 @@ export interface ISuggestController {
45
45
acceptSelectedSuggestion ( suggestion ?: Pick < ISimpleSelectedSuggestion < TerminalCompletionItem > , 'item' | 'model' > ) : void ;
46
46
hideSuggestWidget ( cancelAnyRequests : boolean , wasClosedByUser ?: boolean ) : void ;
47
47
}
48
+
49
+
50
+ let firstShownTracker : { shell : Set < TerminalShellType > ; window : boolean } | undefined = undefined ;
48
51
export class SuggestAddon extends Disposable implements ITerminalAddon , ISuggestController {
49
52
private _terminal ?: Terminal ;
50
53
@@ -135,6 +138,8 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
135
138
private _shouldSyncWhenReady : boolean = false ;
136
139
private _suggestTelemetry : TerminalSuggestTelemetry | undefined ;
137
140
141
+ private _completionRequestTimestamp : number | undefined ;
142
+
138
143
constructor (
139
144
private readonly _sessionId : string ,
140
145
shellType : TerminalShellType | undefined ,
@@ -214,6 +219,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
214
219
this . _model ?. forceRefilterAll ( ) ;
215
220
}
216
221
} ) ) ;
222
+ this . _register ( this . _extensionService . onWillStop ( ( ) => firstShownTracker = undefined ) ) ;
217
223
}
218
224
219
225
activate ( xterm : Terminal ) : void {
@@ -333,8 +339,10 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
333
339
lineContext
334
340
) ;
335
341
if ( token . isCancellationRequested ) {
342
+ this . _completionRequestTimestamp = undefined ;
336
343
return ;
337
344
}
345
+
338
346
this . _showCompletions ( model , explicitlyInvoked ) ;
339
347
}
340
348
@@ -377,7 +385,16 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
377
385
}
378
386
this . _cancellationTokenSource = new CancellationTokenSource ( ) ;
379
387
const token = this . _cancellationTokenSource . token ;
388
+
389
+ // Track the time when completions are requested
390
+ this . _completionRequestTimestamp = Date . now ( ) ;
391
+
380
392
await this . _handleCompletionProviders ( this . _terminal , token , explicitlyInvoked ) ;
393
+
394
+ // If completions are not shown (widget not visible), reset the tracker
395
+ if ( ! this . _terminalSuggestWidgetVisibleContextKey . get ( ) ) {
396
+ this . _completionRequestTimestamp = undefined ;
397
+ }
381
398
}
382
399
383
400
private _addPropertiesToInlineCompletionItem ( completions : ITerminalCompletion [ ] ) : void {
@@ -679,6 +696,16 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
679
696
if ( ! cursorPosition ) {
680
697
return ;
681
698
}
699
+ // Track the time when completions are shown for the first time
700
+ if ( this . _completionRequestTimestamp !== undefined ) {
701
+ const completionLatency = Date . now ( ) - this . _completionRequestTimestamp ;
702
+ if ( this . _suggestTelemetry && this . shellType ) {
703
+ const firstShown = this . getFirstShown ( this . shellType ) ;
704
+ this . updateShown ( ) ;
705
+ this . _suggestTelemetry . logCompletionLatency ( this . _sessionId , completionLatency , firstShown ) ;
706
+ }
707
+ this . _completionRequestTimestamp = undefined ;
708
+ }
682
709
suggestWidget . showSuggestions ( 0 , false , ! explicitlyInvoked , cursorPosition ) ;
683
710
}
684
711
@@ -853,6 +880,37 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
853
880
this . _leadingLineContent = undefined ;
854
881
this . _suggestWidget ?. hide ( ) ;
855
882
}
883
+
884
+ getFirstShown ( shellType : TerminalShellType ) : { window : boolean ; shell : boolean } {
885
+ if ( ! firstShownTracker ) {
886
+ firstShownTracker = {
887
+ window : true ,
888
+ shell : new Set ( [ shellType ] )
889
+ } ;
890
+ return { window : true , shell : true } ;
891
+ }
892
+
893
+ const isFirstForWindow = firstShownTracker . window ;
894
+ const isFirstForShell = ! firstShownTracker . shell . has ( shellType ) ;
895
+
896
+ if ( isFirstForWindow || isFirstForShell ) {
897
+ this . updateShown ( ) ;
898
+ }
899
+
900
+ return {
901
+ window : isFirstForWindow ,
902
+ shell : isFirstForShell
903
+ } ;
904
+ }
905
+
906
+ updateShown ( ) : void {
907
+ if ( ! this . shellType || ! firstShownTracker ) {
908
+ return ;
909
+ }
910
+
911
+ firstShownTracker . window = false ;
912
+ firstShownTracker . shell . add ( this . shellType ) ;
913
+ }
856
914
}
857
915
858
916
class PersistedWidgetSize {
0 commit comments