Skip to content

Commit

Permalink
Fixes #159479
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet committed Apr 21, 2023
1 parent d2f563a commit 784d504
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,9 @@ export interface InlineCompletionsProvider<T extends InlineCompletions = InlineC

/**
* Will be called when an item is shown.
* @param updatedInsertText Is useful to understand bracket completion.
*/
handleItemDidShow?(completions: T, item: T['items'][number]): void;
handleItemDidShow?(completions: T, item: T['items'][number], updatedInsertText: string): void;

/**
* Will be called when an item is partially accepted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ export class InlineCompletionsModel extends Disposable {
if (completion?.semanticId !== lastItem?.semanticId) {
lastItem = completion;
if (completion) {
const src = completion.inlineCompletion.source;
src.provider.handleItemDidShow?.(src.inlineCompletions, completion.inlineCompletion.sourceInlineCompletion);
const i = completion.inlineCompletion;
const src = i.source;
src.provider.handleItemDidShow?.(src.inlineCompletions, i.sourceInlineCompletion, i.insertText);
}
}
}));
Expand Down
3 changes: 2 additions & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6895,8 +6895,9 @@ declare namespace monaco.languages {
provideInlineCompletions(model: editor.ITextModel, position: Position, context: InlineCompletionContext, token: CancellationToken): ProviderResult<T>;
/**
* Will be called when an item is shown.
* @param updatedInsertText Is useful to understand bracket completion.
*/
handleItemDidShow?(completions: T, item: T['items'][number]): void;
handleItemDidShow?(completions: T, item: T['items'][number], updatedInsertText: string): void;
/**
* Will be called when an item is partially accepted.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
provideInlineCompletions: async (model: ITextModel, position: EditorPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<IdentifiableInlineCompletions | undefined> => {
return this._proxy.$provideInlineCompletions(handle, model.uri, position, context, token);
},
handleItemDidShow: async (completions: IdentifiableInlineCompletions, item: IdentifiableInlineCompletion): Promise<void> => {
handleItemDidShow: async (completions: IdentifiableInlineCompletions, item: IdentifiableInlineCompletion, updatedInsertText: string): Promise<void> => {
if (supportsHandleEvents) {
await this._proxy.$handleInlineCompletionDidShow(handle, completions.pid, item.idx);
await this._proxy.$handleInlineCompletionDidShow(handle, completions.pid, item.idx, updatedInsertText);
}
},
handlePartialAccept: async (completions, item, acceptedCharacters): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ export interface ExtHostLanguageFeaturesShape {
$resolveCompletionItem(handle: number, id: ChainedCacheId, token: CancellationToken): Promise<ISuggestDataDto | undefined>;
$releaseCompletionItems(handle: number, id: number): void;
$provideInlineCompletions(handle: number, resource: UriComponents, position: IPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<IdentifiableInlineCompletions | undefined>;
$handleInlineCompletionDidShow(handle: number, pid: number, idx: number): void;
$handleInlineCompletionDidShow(handle: number, pid: number, idx: number, updatedInsertText: string): 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<ISignatureHelpDto | undefined>;
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ class InlineCompletionAdapterBase {

disposeCompletions(pid: number): void { }

handleDidShowCompletionItem(pid: number, idx: number): void { }
handleDidShowCompletionItem(pid: number, idx: number, updatedInsertText: string): void { }

handlePartialAccept(pid: number, idx: number, acceptedCharacters: number): void { }
}
Expand Down Expand Up @@ -1209,11 +1209,11 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
data?.dispose();
}

override handleDidShowCompletionItem(pid: number, idx: number): void {
override handleDidShowCompletionItem(pid: number, idx: number, updatedInsertText: string): void {
const completionItem = this._references.get(pid)?.items[idx];
if (completionItem) {
if (this._provider.handleDidShowCompletionItem && this._isAdditionsProposedApiEnabled) {
this._provider.handleDidShowCompletionItem(completionItem);
this._provider.handleDidShowCompletionItem(completionItem, updatedInsertText);
}
}
}
Expand Down Expand Up @@ -2207,9 +2207,9 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
return this._withAdapter(handle, InlineCompletionAdapterBase, adapter => adapter.provideInlineCompletions(URI.revive(resource), position, context, token), undefined, token);
}

$handleInlineCompletionDidShow(handle: number, pid: number, idx: number): void {
$handleInlineCompletionDidShow(handle: number, pid: number, idx: number, updatedInsertText: string): void {
this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => {
adapter.handleDidShowCompletionItem(pid, idx);
adapter.handleDidShowCompletionItem(pid, idx, updatedInsertText);
}, undefined, undefined);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ declare module 'vscode' {
}

export interface InlineCompletionItemProvider {
/**
* @param completionItem The completion item that was shown.
* @param updatedInsertText The actual insert text (after brackets were fixed).
*/
// eslint-disable-next-line local/vscode-dts-provider-naming
handleDidShowCompletionItem?(completionItem: InlineCompletionItem): void;
handleDidShowCompletionItem?(completionItem: InlineCompletionItem, updatedInsertText: string): void;

/**
* Is called when an inline completion item was accepted partially.
Expand Down

0 comments on commit 784d504

Please sign in to comment.