diff --git a/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts b/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts index c744021cf31d8..b4393ec99b119 100644 --- a/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts +++ b/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts @@ -632,6 +632,11 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread await this._proxy.$handleInlineCompletionPartialAccept(handle, completions.pid, item.idx, acceptedCharacters, info); } }, + handleRejection: async (completions, item): Promise => { + if (supportsHandleEvents) { + await this._proxy.$handleInlineCompletionRejection(handle, completions.pid, item.idx); + } + }, freeInlineCompletions: (completions: IdentifiableInlineCompletions): void => { this._proxy.$freeInlineCompletionsList(handle, completions.pid); }, diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 0e4072c38d904..853347b81e47a 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -2333,6 +2333,7 @@ export interface ExtHostLanguageFeaturesShape { $provideInlineEditsForRange(handle: number, resource: UriComponents, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise; $handleInlineCompletionDidShow(handle: number, pid: number, idx: number, updatedInsertText: string): void; $handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void; + $handleInlineCompletionRejection(handle: number, pid: number, idx: number): void; $freeInlineCompletionsList(handle: number, pid: number): void; $provideSignatureHelp(handle: number, resource: UriComponents, position: IPosition, context: languages.SignatureHelpContext, token: CancellationToken): Promise; $releaseSignatureHelp(handle: number, id: number): void; diff --git a/src/vs/workbench/api/common/extHostLanguageFeatures.ts b/src/vs/workbench/api/common/extHostLanguageFeatures.ts index a44a8709b8ba2..89c0a65611b7a 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -1314,6 +1314,8 @@ class InlineCompletionAdapterBase { handleDidShowCompletionItem(pid: number, idx: number, updatedInsertText: string): void { } handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void { } + + handleRejection(pid: number, idx: number): void { } } class InlineCompletionAdapter extends InlineCompletionAdapterBase { @@ -1538,6 +1540,15 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase { } } } + + override handleRejection(pid: number, idx: number): void { + const completionItem = this._references.get(pid)?.items[idx]; + if (completionItem) { + if (this._provider.handleDidRejectCompletionItem && this._isAdditionsProposedApiEnabled) { + this._provider.handleDidRejectCompletionItem(completionItem); + } + } + } } class InlineEditAdapter { @@ -2706,6 +2717,12 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF }, undefined, undefined); } + $handleInlineCompletionRejection(handle: number, pid: number, idx: number): void { + this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => { + adapter.handleRejection(pid, idx); + }, undefined, undefined); + } + $freeInlineCompletionsList(handle: number, pid: number): void { this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => { adapter.disposeCompletions(pid); }, undefined, undefined); } diff --git a/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts b/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts index 8ab645ba5f98a..cea764b6ef58b 100644 --- a/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts +++ b/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts @@ -76,6 +76,13 @@ declare module 'vscode' { // eslint-disable-next-line local/vscode-dts-provider-naming handleDidPartiallyAcceptCompletionItem?(completionItem: InlineCompletionItem, info: PartialAcceptInfo): void; + /** + * Is called when an inline completion item was rejected. + * @param completionItem The completion item that was rejected. + */ + // eslint-disable-next-line local/vscode-dts-provider-naming + handleDidRejectCompletionItem?(completionItem: InlineCompletionItem): void; + provideInlineEditsForRange?(document: TextDocument, range: Range, context: InlineCompletionContext, token: CancellationToken): ProviderResult; readonly debounceDelayMs?: number;