Skip to content

Commit

Permalink
Merge branch 'main' into regulatory-haddock
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz authored Feb 21, 2025
2 parents a8e09c1 + 98d4b8b commit 5ded6fd
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 121 deletions.
Binary file modified src/vs/base/browser/ui/codicons/codicon/codicon.ttf
Binary file not shown.
3 changes: 3 additions & 0 deletions src/vs/base/common/codiconsLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,7 @@ export const codiconsLibrary = {
keyboardTab: register('keyboard-tab', 0xec3c),
copilotBlocked: register('copilot-blocked', 0xec3d),
copilotNotConnected: register('copilot-not-connected', 0xec3e),
flag: register('flag', 0xec3f),
lightbulbEmpty: register('lightbulb-empty', 0xec40),
symbolMethodArrow: register('symbol-method-arrow', 0xec41),
} as const;
1 change: 1 addition & 0 deletions src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ export interface InlineCompletion {

/**
* Is called the first time an inline completion is shown.
* @deprecated. Use `onDidShow` of the provider instead.
*/
readonly shownCommand?: Command;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,17 @@ export class InlineCompletionsModel extends Disposable {
});
}

public async handleInlineCompletionShown(inlineCompletion: InlineCompletionItem): Promise<void> {
if (!inlineCompletion.shownCommand) {
return;
}
public async handleInlineEditShown(inlineCompletion: InlineCompletionItem): Promise<void> {
if (inlineCompletion.didShow) {
return;
}
inlineCompletion.markAsShown();
await this._commandService.executeCommand(inlineCompletion.shownCommand.id, ...(inlineCompletion.shownCommand.arguments || []));

inlineCompletion.source.provider.handleItemDidShow?.(inlineCompletion.source.inlineCompletions, inlineCompletion.sourceInlineCompletion, inlineCompletion.insertText);

if (inlineCompletion.shownCommand) {
await this._commandService.executeCommand(inlineCompletion.shownCommand.id, ...(inlineCompletion.shownCommand.arguments || []));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ export class InlineCompletionItem {
constructor(
readonly filterText: string,
readonly command: Command | undefined,
/** @deprecated. Use handleItemDidShow */
readonly shownCommand: Command | undefined,
readonly action: Command | undefined,
readonly range: Range,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class InlineEditsView extends Disposable {
return undefined;
}

this._model.get()?.handleInlineCompletionShown(edit.inlineCompletion);
this._model.get()?.handleInlineEditShown(edit.inlineCompletion);

let mappings = RangeMapping.fromEdit(edit.edit);
let newText = edit.edit.apply(edit.originalText);
Expand Down Expand Up @@ -157,7 +157,8 @@ export class InlineEditsView extends Disposable {
const item = state?.read(reader);
const completionSource = item?.inlineCompletion?.source;
// TODO: expose the provider (typed) and expose the provider the edit belongs to typing and get correct edit
return (completionSource?.inlineCompletions as any)?.edits?.[0]?.provider?.displayName ?? previousDisplayName ?? localize('inlineEdit', "Inline Edit");
return (completionSource?.inlineCompletions as any)?.edits?.[0]?.provider?.displayName ?? previousDisplayName
?? completionSource?.provider.displayName ?? localize('inlineEdit', "Inline Edit");
}),
tabAction: derived<InlineEditTabAction>(this, reader => {
const m = this._model.read(reader);
Expand Down
1 change: 1 addition & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7301,6 +7301,7 @@ declare namespace monaco.languages {
readonly action?: Command;
/**
* Is called the first time an inline completion is shown.
* @deprecated. Use `onDidShow` of the provider instead.
*/
readonly shownCommand?: Command;
/**
Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
this._registrations.set(handle, this._languageFeaturesService.completionProvider.register(selector, provider));
}

$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[], supportsHandleEvents: boolean, extensionId: string, yieldsToExtensionIds: string[], debounceDelayMs: number | undefined): void {
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[], supportsHandleEvents: boolean, extensionId: string, yieldsToExtensionIds: string[], displayName: string | undefined, debounceDelayMs: number | undefined): void {
const provider: languages.InlineCompletionsProvider<IdentifiableInlineCompletions> = {
provideInlineCompletions: async (model: ITextModel, position: EditorPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<IdentifiableInlineCompletions | undefined> => {
return this._proxy.$provideInlineCompletions(handle, model.uri, position, context, token);
Expand All @@ -635,9 +635,15 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
freeInlineCompletions: (completions: IdentifiableInlineCompletions): void => {
this._proxy.$freeInlineCompletionsList(handle, completions.pid);
},
handleRejection: async (completions, item): Promise<void> => {
if (supportsHandleEvents) {
await this._proxy.$handleInlineCompletionRejection(handle, completions.pid, item.idx);
}
},
groupId: extensionId,
yieldsToGroupIds: yieldsToExtensionIds,
debounceDelayMs,
displayName,
toString() {
return `InlineCompletionsProvider(${extensionId})`;
},
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
$emitDocumentSemanticTokensEvent(eventHandle: number): void;
$registerDocumentRangeSemanticTokensProvider(handle: number, selector: IDocumentFilterDto[], legend: languages.SemanticTokensLegend): void;
$registerCompletionsProvider(handle: number, selector: IDocumentFilterDto[], triggerCharacters: string[], supportsResolveDetails: boolean, extensionId: ExtensionIdentifier): void;
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[], supportsHandleDidShowCompletionItem: boolean, extensionId: string, yieldsToExtensionIds: string[], debounceDelayMs: number | undefined): void;
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[], supportsHandleDidShowCompletionItem: boolean, extensionId: string, yieldsToExtensionIds: string[], displayName: string | undefined, debounceDelayMs: number | undefined): void;
$registerInlineEditProvider(handle: number, selector: IDocumentFilterDto[], extensionId: ExtensionIdentifier, displayName: string): void;
$registerSignatureHelpProvider(handle: number, selector: IDocumentFilterDto[], metadata: ISignatureHelpProviderMetadataDto): void;
$registerInlayHintsProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean, eventHandle: number | undefined, displayName: string | undefined): void;
Expand Down Expand Up @@ -2333,6 +2333,7 @@ export interface ExtHostLanguageFeaturesShape {
$provideInlineEditsForRange(handle: number, resource: UriComponents, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<IdentifiableInlineCompletions | undefined>;
$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<ISignatureHelpDto | undefined>;
$releaseSignatureHelp(handle: number, id: number): void;
Expand Down
72 changes: 40 additions & 32 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,23 +1300,7 @@ class CompletionsAdapter {
}
}

class InlineCompletionAdapterBase {
async provideInlineCompletions(resource: URI, position: IPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
return undefined;
}

async provideInlineEditsForRange(resource: URI, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
return undefined;
}

disposeCompletions(pid: number): void { }

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

handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void { }
}

class InlineCompletionAdapter extends InlineCompletionAdapterBase {
class InlineCompletionAdapter {
private readonly _references = new ReferenceMap<{
dispose(): void;
items: readonly vscode.InlineCompletionItem[];
Expand All @@ -1330,21 +1314,22 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
private readonly _provider: vscode.InlineCompletionItemProvider,
private readonly _commands: CommandsConverter,
) {
super();
}

public get supportsHandleEvents(): boolean {
return isProposedApiEnabled(this._extension, 'inlineCompletionsAdditions')
&& (typeof this._provider.handleDidShowCompletionItem === 'function'
|| typeof this._provider.handleDidPartiallyAcceptCompletionItem === 'function');
|| typeof this._provider.handleDidPartiallyAcceptCompletionItem === 'function'
|| typeof this._provider.handleDidRejectCompletionItem === 'function'
);
}

private readonly languageTriggerKindToVSCodeTriggerKind: Record<languages.InlineCompletionTriggerKind, InlineCompletionTriggerKind> = {
[languages.InlineCompletionTriggerKind.Automatic]: InlineCompletionTriggerKind.Automatic,
[languages.InlineCompletionTriggerKind.Explicit]: InlineCompletionTriggerKind.Invoke,
};

override async provideInlineCompletions(resource: URI, position: IPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
async provideInlineCompletions(resource: URI, position: IPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
const doc = this._documents.getDocument(resource);
const pos = typeConvert.Position.to(position);

Expand Down Expand Up @@ -1407,6 +1392,7 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
insertText: typeof insertText === 'string' ? insertText : { snippet: insertText.value },
filterText: item.filterText,
range: item.range ? typeConvert.Range.from(item.range) : undefined,
showRange: (this._isAdditionsProposedApiEnabled && item.showRange) ? typeConvert.Range.from(item.showRange) : undefined,
command,
action,
idx: idx,
Expand All @@ -1430,7 +1416,7 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
};
}

override async provideInlineEditsForRange(resource: URI, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
async provideInlineEditsForRange(resource: URI, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
if (!this._provider.provideInlineEditsForRange) {
return undefined;
}
Expand Down Expand Up @@ -1516,12 +1502,12 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
};
}

override disposeCompletions(pid: number) {
disposeCompletions(pid: number) {
const data = this._references.disposeReferenceId(pid);
data?.dispose();
}

override handleDidShowCompletionItem(pid: number, idx: number, updatedInsertText: string): void {
handleDidShowCompletionItem(pid: number, idx: number, updatedInsertText: string): void {
const completionItem = this._references.get(pid)?.items[idx];
if (completionItem) {
if (this._provider.handleDidShowCompletionItem && this._isAdditionsProposedApiEnabled) {
Expand All @@ -1530,7 +1516,7 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
}
}

override handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void {
handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void {
const completionItem = this._references.get(pid)?.items[idx];
if (completionItem) {
if (this._provider.handleDidPartiallyAcceptCompletionItem && this._isAdditionsProposedApiEnabled) {
Expand All @@ -1539,6 +1525,15 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
}
}
}

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 {
Expand Down Expand Up @@ -2677,38 +2672,51 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
this._withAdapter(handle, CompletionsAdapter, adapter => adapter.releaseCompletionItems(id), undefined, undefined);
}

// --- ghost test
// --- ghost text

registerInlineCompletionsProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.InlineCompletionItemProvider, metadata: vscode.InlineCompletionItemProviderMetadata | undefined): 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, extension), adapter.supportsHandleEvents,
ExtensionIdentifier.toKey(extension.identifier.value), metadata?.yieldTo?.map(extId => ExtensionIdentifier.toKey(extId)) || [], metadata?.debounceDelayMs);
this._proxy.$registerInlineCompletionsSupport(
handle,
this._transformDocumentSelector(selector, extension),
adapter.supportsHandleEvents,
ExtensionIdentifier.toKey(extension.identifier.value),
metadata?.yieldTo?.map(extId => ExtensionIdentifier.toKey(extId)) || [],
metadata?.displayName,
metadata?.debounceDelayMs,
);
return this._createDisposable(handle);
}

$provideInlineCompletions(handle: number, resource: UriComponents, position: IPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
return this._withAdapter(handle, InlineCompletionAdapterBase, adapter => adapter.provideInlineCompletions(URI.revive(resource), position, context, token), undefined, token);
return this._withAdapter(handle, InlineCompletionAdapter, adapter => adapter.provideInlineCompletions(URI.revive(resource), position, context, token), undefined, token);
}

$provideInlineEditsForRange(handle: number, resource: UriComponents, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
return this._withAdapter(handle, InlineCompletionAdapterBase, adapter => adapter.provideInlineEditsForRange(URI.revive(resource), range, context, token), undefined, token);
return this._withAdapter(handle, InlineCompletionAdapter, adapter => adapter.provideInlineEditsForRange(URI.revive(resource), range, context, token), undefined, token);
}

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

$handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void {
this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => {
this._withAdapter(handle, InlineCompletionAdapter, async adapter => {
adapter.handlePartialAccept(pid, idx, acceptedCharacters, info);
}, undefined, undefined);
}

$handleInlineCompletionRejection(handle: number, pid: number, idx: number): void {
this._withAdapter(handle, InlineCompletionAdapter, 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);
this._withAdapter(handle, InlineCompletionAdapter, async adapter => { adapter.disposeCompletions(pid); }, undefined, undefined);
}

// --- inline edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import { ILanguageService } from '../../../../../../editor/common/languages/lang
import { FileKind, IFileService } from '../../../../../../platform/files/common/files.js';
import { IMenuService, MenuId } from '../../../../../../platform/actions/common/actions.js';
import { getCleanPromptName } from '../../../../../../platform/prompts/common/constants.js';
import { ChatPromptAttachmentModel } from '../../chatAttachmentModel/chatPromptAttachmentModel.js';
import { IContextKeyService } from '../../../../../../platform/contextkey/common/contextkey.js';
import { IContextMenuService } from '../../../../../../platform/contextview/browser/contextView.js';
import { ChatInstructionsAttachmentModel } from '../../chatAttachmentModel/chatInstructionsAttachment.js';
import { getDefaultHoverDelegate } from '../../../../../../base/browser/ui/hover/hoverDelegateFactory.js';
import { getFlatContextMenuActions } from '../../../../../../platform/actions/browser/menuEntryActionViewItem.js';

/**
* Widget for a single prompt instructions attachment.
*/
export class InstructionsAttachmentWidget extends Disposable {
export class PromptAttachmentWidget extends Disposable {
/**
* The root DOM node of the widget.
*/
Expand Down Expand Up @@ -66,7 +66,7 @@ export class InstructionsAttachmentWidget extends Disposable {
private readonly renderDisposables = this._register(new DisposableStore());

constructor(
private readonly model: ChatInstructionsAttachmentModel,
private readonly model: ChatPromptAttachmentModel,
private readonly resourceLabels: ResourceLabels,
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
Expand All @@ -79,7 +79,7 @@ export class InstructionsAttachmentWidget extends Disposable {
) {
super();

this.domNode = dom.$('.chat-prompt-instructions-attachment.chat-attached-context-attachment.show-file-icons.implicit');
this.domNode = dom.$('.chat-prompt-attachment.chat-attached-context-attachment.show-file-icons.implicit');

this.render = this.render.bind(this);
this.dispose = this.dispose.bind(this);
Expand Down
Loading

0 comments on commit 5ded6fd

Please sign in to comment.