diff --git a/src/vs/editor/common/languages.ts b/src/vs/editor/common/languages.ts index 42ab35a3a1c..e012f79787a 100644 --- a/src/vs/editor/common/languages.ts +++ b/src/vs/editor/common/languages.ts @@ -655,6 +655,11 @@ export interface InlineCompletionsProvider = { provideInlineCompletions: async (model: ITextModel, position: EditorPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise => { return this._proxy.$provideInlineCompletions(handle, model.uri, position, context, token); }, handleItemDidShow: async (completions: IdentifiableInlineCompletions, item: IdentifiableInlineCompletion): Promise => { - if (supportsHandleDidShowCompletionItem) { + if (supportsHandleEvents) { await this._proxy.$handleInlineCompletionDidShow(handle, completions.pid, item.idx); } }, + handlePartialAccept: async (completions, item, acceptedCharacters): Promise => { + if (supportsHandleEvents) { + await this._proxy.$handleInlineCompletionPartialAccept(handle, completions.pid, item.idx, acceptedCharacters); + } + }, freeInlineCompletions: (completions: IdentifiableInlineCompletions): void => { this._proxy.$freeInlineCompletionsList(handle, completions.pid); } diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 52779636b0a..c33c3e72bfe 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -551,6 +551,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I if (provider.handleDidShowCompletionItem) { checkProposedApiEnabled(extension, 'inlineCompletionsAdditions'); } + if (provider.handleDidPartiallyAcceptCompletionItem) { + checkProposedApiEnabled(extension, 'inlineCompletionsAdditions'); + } return extHostLanguageFeatures.registerInlineCompletionsProvider(extension, checkSelector(selector), provider); }, registerDocumentLinkProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentLinkProvider): vscode.Disposable { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 202605da3be..32078f50af6 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1784,6 +1784,7 @@ export interface ExtHostLanguageFeaturesShape { $releaseCompletionItems(handle: number, id: number): void; $provideInlineCompletions(handle: number, resource: UriComponents, position: IPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise; $handleInlineCompletionDidShow(handle: number, pid: number, idx: number): void; + $handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: 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 5b2b58a9e40..087fb2df70c 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -1074,6 +1074,8 @@ class InlineCompletionAdapterBase { disposeCompletions(pid: number): void { } handleDidShowCompletionItem(pid: number, idx: number): void { } + + handlePartialAccept(pid: number, idx: number, acceptedCharacters: number): void { } } class InlineCompletionAdapter extends InlineCompletionAdapterBase { @@ -1093,8 +1095,10 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase { super(); } - public get supportsHandleDidShowCompletionItem(): boolean { - return isProposedApiEnabled(this._extension, 'inlineCompletionsAdditions') && typeof this._provider.handleDidShowCompletionItem === 'function'; + public get supportsHandleEvents(): boolean { + return isProposedApiEnabled(this._extension, 'inlineCompletionsAdditions') + && (typeof this._provider.handleDidShowCompletionItem === 'function' + || typeof this._provider.handleDidPartiallyAcceptCompletionItem === 'function'); } private readonly languageTriggerKindToVSCodeTriggerKind: Record = { @@ -1182,6 +1186,15 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase { } } } + + override handlePartialAccept(pid: number, idx: number, acceptedCharacters: number): void { + const completionItem = this._references.get(pid)?.items[idx]; + if (completionItem) { + if (this._provider.handleDidPartiallyAcceptCompletionItem && this._isAdditionsProposedApiEnabled) { + this._provider.handleDidPartiallyAcceptCompletionItem(completionItem, acceptedCharacters); + } + } + } } class ReferenceMap { @@ -2145,7 +2158,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF registerInlineCompletionsProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.InlineCompletionItemProvider): vscode.Disposable { const adapter = new InlineCompletionAdapter(extension, this._documents, provider, this._commands.converter); const handle = this._addNewAdapter(adapter, extension); - this._proxy.$registerInlineCompletionsSupport(handle, this._transformDocumentSelector(selector), adapter.supportsHandleDidShowCompletionItem); + this._proxy.$registerInlineCompletionsSupport(handle, this._transformDocumentSelector(selector), adapter.supportsHandleEvents); return this._createDisposable(handle); } @@ -2159,6 +2172,12 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF }, undefined, undefined); } + $handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number): void { + this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => { + adapter.handlePartialAccept(pid, idx, acceptedCharacters); + }, 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 3b6a8722e4e..8db8257950a 100644 --- a/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts +++ b/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts @@ -18,6 +18,13 @@ declare module 'vscode' { export interface InlineCompletionItemProvider { // eslint-disable-next-line local/vscode-dts-provider-naming handleDidShowCompletionItem?(completionItem: InlineCompletionItem): void; + + /** + * Is called when an inline completion item was accepted partially. + * @param acceptedLength The length of the substring of the inline completion that was accepted already. + */ + // eslint-disable-next-line local/vscode-dts-provider-naming + handleDidPartiallyAcceptCompletionItem?(completionItem: InlineCompletionItem, acceptedLength: number): void; } // When finalizing `commands`, make sure to add a corresponding constructor parameter.