@@ -7,8 +7,9 @@ import { CancellationToken, CancellationTokenSource } from '../../../../../base/
7
7
import { equalsIfDefined , itemEquals } from '../../../../../base/common/equals.js' ;
8
8
import { matchesSubString } from '../../../../../base/common/filters.js' ;
9
9
import { Disposable , IDisposable , MutableDisposable } from '../../../../../base/common/lifecycle.js' ;
10
- import { IObservable , IReader , ITransaction , derivedOpts , disposableObservableValue , observableValue , transaction } from '../../../../../base/common/observable.js' ;
10
+ import { IObservable , IReader , ITransaction , derivedOpts , disposableObservableValue , observableFromEvent , observableValue , transaction } from '../../../../../base/common/observable.js' ;
11
11
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
12
+ import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js' ;
12
13
import { ILogService } from '../../../../../platform/log/common/log.js' ;
13
14
import { observableConfigValue } from '../../../../../platform/observable/common/platformObservableUtils.js' ;
14
15
import { Position } from '../../../../common/core/position.js' ;
@@ -31,6 +32,7 @@ export class InlineCompletionsSource extends Disposable {
31
32
public readonly suggestWidgetInlineCompletions = disposableObservableValue < UpToDateInlineCompletions | undefined > ( 'suggestWidgetInlineCompletions' , undefined ) ;
32
33
33
34
private readonly _loggingEnabled = observableConfigValue ( 'editor.inlineSuggest.logFetch' , false , this . _configurationService ) . recomputeInitiallyAndOnChange ( this . _store ) ;
35
+ private readonly _recordingLoggingEnabled = observableContextKey ( 'editor.inlineSuggest.logFetch' , this . _contextKeyService ) . recomputeInitiallyAndOnChange ( this . _store ) ;
34
36
35
37
constructor (
36
38
private readonly _textModel : ITextModel ,
@@ -40,6 +42,7 @@ export class InlineCompletionsSource extends Disposable {
40
42
@ILanguageConfigurationService private readonly _languageConfigurationService : ILanguageConfigurationService ,
41
43
@ILogService private readonly _logService : ILogService ,
42
44
@IConfigurationService private readonly _configurationService : IConfigurationService ,
45
+ @IContextKeyService private readonly _contextKeyService : IContextKeyService ,
43
46
) {
44
47
super ( ) ;
45
48
@@ -48,8 +51,11 @@ export class InlineCompletionsSource extends Disposable {
48
51
} ) ) ;
49
52
}
50
53
51
- private _log ( entry : { kind : 'start' ; uri : string ; modelVersion : number ; requestId : number ; context : unknown } | { kind : 'end' ; error : any ; durationMs : number ; result : unknown ; requestId : number } ) {
52
- this . _logService . info ( 'InlineCompletionsSource.fetch ' + JSON . stringify ( entry ) ) ;
54
+ private _log ( entry :
55
+ { kind : 'start' ; requestId : number ; context : unknown } & IRecordableEditorLogEntry
56
+ | { kind : 'end' ; error : any ; durationMs : number ; result : unknown ; requestId : number } & IRecordableLogEntry
57
+ ) {
58
+ this . _logService . info ( formatRecordableLogEntry ( 'InlineCompletions.fetch' , entry ) ) ;
53
59
}
54
60
55
61
public readonly loading = observableValue ( this , false ) ;
@@ -84,8 +90,8 @@ export class InlineCompletionsSource extends Disposable {
84
90
}
85
91
86
92
const requestId = InlineCompletionsSource . _requestId ++ ;
87
- if ( this . _loggingEnabled . get ( ) ) {
88
- this . _log ( { kind : 'start' , requestId, uri : this . _textModel . uri . toString ( ) , modelVersion : this . _textModel . getVersionId ( ) , context : { triggerKind : context . triggerKind } } ) ;
93
+ if ( this . _loggingEnabled . get ( ) || this . _recordingLoggingEnabled . get ( ) ) {
94
+ this . _log ( { kind : 'start' , requestId, modelUri : this . _textModel . uri . toString ( ) , modelVersion : this . _textModel . getVersionId ( ) , context : { triggerKind : context . triggerKind } , time : Date . now ( ) } ) ;
89
95
}
90
96
91
97
const startTime = new Date ( ) ;
@@ -104,7 +110,7 @@ export class InlineCompletionsSource extends Disposable {
104
110
error = e ;
105
111
throw e ;
106
112
} finally {
107
- if ( this . _loggingEnabled . get ( ) ) {
113
+ if ( this . _loggingEnabled . get ( ) || this . _recordingLoggingEnabled . get ( ) ) {
108
114
if ( source . token . isCancellationRequested ) {
109
115
error = 'canceled' ;
110
116
}
@@ -114,7 +120,7 @@ export class InlineCompletionsSource extends Disposable {
114
120
isInlineEdit : ! ! c . sourceInlineCompletion . isInlineEdit ,
115
121
source : c . source . provider . groupId ,
116
122
} ) ) ;
117
- this . _log ( { kind : 'end' , requestId, durationMs : ( Date . now ( ) - startTime . getTime ( ) ) , error, result } ) ;
123
+ this . _log ( { kind : 'end' , requestId, durationMs : ( Date . now ( ) - startTime . getTime ( ) ) , error, result, time : Date . now ( ) } ) ;
118
124
}
119
125
}
120
126
@@ -367,3 +373,23 @@ export class InlineCompletionWithUpdatedRange {
367
373
}
368
374
369
375
const emptyRange = new Range ( 1 , 1 , 1 , 1 ) ;
376
+
377
+ interface IRecordableLogEntry {
378
+ time : number ;
379
+ }
380
+
381
+ export interface IRecordableEditorLogEntry extends IRecordableLogEntry {
382
+ modelUri : string ;
383
+ modelVersion : number ;
384
+ }
385
+
386
+ /**
387
+ * The sourceLabel must not contain '@'!
388
+ */
389
+ export function formatRecordableLogEntry < T extends IRecordableLogEntry > ( sourceId : string , entry : T ) : string {
390
+ return sourceId + ' @@ ' + JSON . stringify ( entry ) ;
391
+ }
392
+
393
+ export function observableContextKey ( key : string , contextKeyService : IContextKeyService ) : IObservable < unknown > {
394
+ return observableFromEvent ( contextKeyService . onDidChangeContext , ( ) => contextKeyService . getContextKeyValue ( key ) ) ;
395
+ }
0 commit comments