8000 Improves inline completion provider change event by hediet · Pull Request #252312 · microsoft/vscode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improves inline completion provider change event #252312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
< 8000 td id="diff-6ea3e2b5ce46c8d78a5406b831688788f6bbdf4e5ff23194da0434cce995219fR161" data-line-number="161" class="blob-num blob-num-addition js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { itemsEquals } from '../../../../../base/common/equals.js';
import { BugIndicatingError, onUnexpectedError, onUnexpectedExternalError } from '../../../../../base/common/errors.js';
import { Emitter } from '../../../../../base/common/event.js';
import { Disposable } from '../../../../../base/common/lifecycle.js';
import { IObservable, IObservableWithChange, IReader, ITransaction, autorun, autorunWithStore, constObservable, derived, derivedHandleChanges, derivedOpts, observableFromEvent, observableSignal, observableValue, recomputeInitiallyAndOnChange, subtransaction, transaction } from '../../../../../base/common/observable.js';
import { IObservable, IObservableWithChange, IReader, ITransaction, autorun, constObservable, derived, derivedHandleChanges, derivedOpts, mapObservableArrayCached, observableFromEvent, observableSignal, observableValue, recomputeInitiallyAndOnChange, subtransaction, transaction } from '../../../../../base/common/observable.js';
import { commonPrefixLength, firstNonWhitespaceIndex } from '../../../../../base/common/strings.js';
import { isDefined } from '../../../../../base/common/types.js';
import { IAccessibilityService } from '../../../../../platform/accessibility/common/accessibility.js';
Expand Down Expand Up @@ -150,11 +150,15 @@ export class InlineCompletionsModel extends Disposable {
onlyRequestInlineEdits: false,
shouldDebounce: true,
provider: undefined as InlineCompletionsProvider | undefined,
textChange: false,
}),
handleChange: (ctx, changeSummary) => {
/** @description fetch inline completions */
if (ctx.didChange(this._textModelVersionId) && this._preserveCurrentCompletionReasons.has(this._getReason(ctx.change))) {
changeSummary.preserveCurrentCompletion = true;
if (ctx.didChange(this._textModelVersionId)) {
if (this._preserveCurrentCompletionReasons.has(this._getReason(ctx.change))) {
changeSummary.preserveCurrentCompletion = true;
}
changeSummary.textChange = true;
} else if (ctx.didChange(this._forceUpdateExplicitlySignal)) {
changeSummary.inlineCompletionTriggerKind = InlineCompletionTriggerKind.Explicit;
} else if (ctx.didChange(this.dontRefetchSignal)) {
Expand Down Expand Up @@ -206,7 +210,7 @@ export class InlineCompletionsModel extends Disposable {
includeInlineEdits: this._inlineEditsEnabled.read(reader),
};

if (context.triggerKind === InlineCompletionTriggerKind.Automatic) {
if (context.triggerKind === InlineCompletionTriggerKind.Automatic && changeSummary.textChange) {
if (this.textModel.getAlternativeVersionId() === this._lastShownInlineCompletionInfo?.alternateTextModelVersionId) {
// When undoing back to a version where an inline edit/completion was shown,
// we want to show an inline edit (or completion) again if it was originally an inline edit (or completion).
Expand Down Expand Up @@ -572,32 +576,29 @@ export class InlineCompletionsModel extends Disposable {
}));

const inlineCompletionProviders = observableFromEvent(this._languageFeaturesService.inlineCompletionsProvider.onDidChange, () => this._languageFeaturesService.inlineCompletionsProvider.all(textModel));
this._register(autorunWithStore((reader, store) => {
const providers = inlineCompletionProviders.read(reader);
for (const provider of providers) {
if (!provider.onDidChangeInlineCompletions) {
continue;
}
mapObservableArrayCached(this, inlineCompletionProviders, (provider, store) => {
if (!provider.onDidChangeInlineCompletions) {
return;
}

store.add(provider.onDidChangeInlineCompletions(() => {
if (!this._enabled.get()) {
return;
}
store.add(provider.onDidChangeInlineCompletions(() => {
if (!this._enabled.get()) {
return;
}

// If there is an active suggestion from a different provider, we ignore the update
const activeState = this.state.get();
if (activeState && (activeState.inlineCompletion || activeState.edits) && activeState.inlineCompletion?.source.provider !== provider) {
return;
}
// If there is an active suggestion from a different provider, we ignore the update
const activeState = this.state.get();
if (activeState && (activeState.inlineCompletion || activeState.edits) && activeState.inlineCompletion?.source.provider !== provider) {
return;
}

transaction(tx => {
this._fetchSpecificProviderSignal.trigger(tx, provider);
this.trigger(tx);
});
transaction(tx => {
this._fetchSpecificProviderSignal.trigger(tx, provider);
this.trigger(tx);
});

}));
}
}));
}));
}).recomputeInitiallyAndOnChange(this._store);

this._didUndoInlineEdits.recomputeInitiallyAndOnChange(this._store);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class InlineCompletionsSource extends Disposable {

public fetch(providers: InlineCompletionsProvider[], context: InlineCompletionContextWithoutUuid, activeInlineCompletion: InlineSuggestionIdentity | undefined, withDebounce: boolean, userJumpedToActiveCompletion: IObservable<boolean>, providerhasChangedCompletion: boolean, editorType: InlineCompletionEditorType): Promise<boolean> {
const position = this._cursorPosition.get();
const request = new UpdateRequest(position, context, this._textModel.getVersionId());
const request = new UpdateRequest(position, context, this._textModel.getVersionId(), new Set(providers));

const target = context.selectedSuggestionInfo ? this.suggestWidgetInlineCompletions.get() : this.inlineCompletions.get();

Expand Down Expand Up @@ -307,6 +307,7 @@ class UpdateRequest {
public readonly position: Position,
public readonly context: InlineCompletionContextWithoutUuid,
public readonly versionId: number,
public readonly providers: Set<InlineCompletionsProvider>,
) {
}

Expand All @@ -315,14 +316,19 @@ class UpdateRequest {
&& equalsIfDefined(this.context.selectedSuggestionInfo, other.context.selectedSuggestionInfo, itemEquals())
&& (other.context.triggerKind === InlineCompletionTriggerKind.Automatic
|| this.context.triggerKind === InlineCompletionTriggerKind.Explicit)
&& this.versionId === other.versionId;
&& this.versionId === other.versionId
&& isSubset(other.providers, this.providers);
}

public get isExplicitRequest() {
return this.context.triggerKind === InlineCompletionTriggerKind.Explicit;
}
}

function isSubset<T>(set1: Set<T>, set2: Set<T>): boolean {
return [...set1].every(item => set2.has(item));
}

class UpdateOperation implements IDisposable {
constructor(
public readonly request: UpdateRequest,
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,12 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
return `InlineCompletionsProvider(${extensionId})`;
},
};
this._registrations.set(handle, this._languageFeaturesService.inlineCompletionsProvider.register(selector, provider));

if (typeof eventHandle === 'number') {
const emitter = new Emitter<void>();
this._registrations.set(eventHandle, emitter);
provider.onDidChangeInlineCompletions = emitter.event;
}
this._registrations.set(handle, this._languageFeaturesService.inlineCompletionsProvider.register(selector, provider));
}

$emitInlineCompletionsChange(handle: number): void {
Expand Down
Loading
0