Skip to content

Commit d9f21be

Browse files
authored
1 parent 955c13c commit d9f21be

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsSource.ts

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { equalsIfDefined, itemEquals } from '../../../../../base/common/equals.j
88
import { matchesSubString } from '../../../../../base/common/filters.js';
99
import { Disposable, IDisposable, MutableDisposable } from '../../../../../base/common/lifecycle.js';
1010
import { IObservable, IReader, ITransaction, derivedOpts, disposableObservableValue, transaction } from '../../../../../base/common/observable.js';
11+
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
12+
import { ILogService } from '../../../../../platform/log/common/log.js';
13+
import { observableConfigValue } from '../../../../../platform/observable/common/platformObservableUtils.js';
1114
import { Position } from '../../../../common/core/position.js';
1215
import { Range } from '../../../../common/core/range.js';
1316
import { SingleTextEdit } from '../../../../common/core/textEdit.js';
@@ -21,16 +24,22 @@ import { InlineCompletionItem, InlineCompletionProviderResult, provideInlineComp
2124
import { singleTextRemoveCommonPrefix } from './singleTextEditHelpers.js';
2225

2326
export class InlineCompletionsSource extends Disposable {
27+
private static _requestId = 0;
28+
2429
private readonly _updateOperation = this._register(new MutableDisposable<UpdateOperation>());
2530
public readonly inlineCompletions = disposableObservableValue<UpToDateInlineCompletions | undefined>('inlineCompletions', undefined);
2631
public readonly suggestWidgetInlineCompletions = disposableObservableValue<UpToDateInlineCompletions | undefined>('suggestWidgetInlineCompletions', undefined);
2732

33+
private readonly _loggingEnabled = observableConfigValue('editor.inlineSuggest.logFetch', false, this._configurationService).recomputeInitiallyAndOnChange(this._store);
34+
2835
constructor(
2936
private readonly _textModel: ITextModel,
3037
private readonly _versionId: IObservable<number | null>,
3138
private readonly _debounceValue: IFeatureDebounceInformation,
3239
@ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService,
3340
@ILanguageConfigurationService private readonly _languageConfigurationService: ILanguageConfigurationService,
41+
@ILogService private readonly _logService: ILogService,
42+
@IConfigurationService private readonly _configurationService: IConfigurationService,
3443
) {
3544
super();
3645

@@ -39,6 +48,10 @@ export class InlineCompletionsSource extends Disposable {
3948
}));
4049
}
4150

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));
53+
}
54+
4255
public fetch(position: Position, context: InlineCompletionContext, activeInlineCompletion: InlineCompletionWithUpdatedRange | undefined): Promise<boolean> {
4356
const request = new UpdateRequest(position, context, this._textModel.getVersionId());
4457

@@ -66,15 +79,40 @@ export class InlineCompletionsSource extends Disposable {
6679
return false;
6780
}
6881

82+
const requestId = InlineCompletionsSource._requestId++;
83+
if (this._loggingEnabled.get()) {
84+
this._log({ kind: 'start', requestId, uri: this._textModel.uri.toString(), modelVersion: this._textModel.getVersionId(), context: { triggerKind: context.triggerKind } });
85+
}
86+
6987
const startTime = new Date();
70-
const updatedCompletions = await provideInlineCompletions(
71-
this._languageFeaturesService.inlineCompletionsProvider,
72-
position,
73-
this._textModel,
74-
context,
75-
source.token,
76-
this._languageConfigurationService
77-
);
88+
let updatedCompletions: InlineCompletionProviderResult | undefined = undefined;
89+
let error: any = undefined;
90+
try {
91+
updatedCompletions = await provideInlineCompletions(
92+
this._languageFeaturesService.inlineCompletionsProvider,
93+
position,
94+
this._textModel,
95+
context,
96+
source.token,
97+
this._languageConfigurationService
98+
);
99+
} catch (e) {
100+
error = e;
101+
throw e;
102+
} finally {
103+
if (this._loggingEnabled.get()) {
104+
if (source.token.isCancellationRequested) {
105+
error = 'canceled';
106+
}
107+
const result = updatedCompletions?.completions.map(c => ({
108+
range: c.range.toString(),
109+
text: c.insertText,
110+
isInlineEdit: !!c.sourceInlineCompletion.isInlineEdit,
111+
source: c.source.provider.groupId,
112+
}));
113+
this._log({ kind: 'end', requestId, durationMs: (Date.now() - startTime.getTime()), error, result });
114+
}
115+
}
78116

79117
if (source.token.isCancellationRequested || this._store.isDisposed || this._textModel.getVersionId() !== request.versionId) {
80118
return false;
@@ -273,6 +311,7 @@ export class InlineCompletionWithUpdatedRange {
273311
!updatedRange
274312
|| !this.inlineCompletion.range.getStartPosition().equals(updatedRange.getStartPosition())
275313
|| cursorPosition.lineNumber !== minimizedReplacement.range.startLineNumber
314+
|| minimizedReplacement.isEmpty // if the completion is empty after removing the common prefix of the completion and the model, the completion item would not be visible
276315
) {
277316
return false;
278317
}

0 commit comments

Comments
 (0)