Skip to content

Commit 5ded6fd

Browse files
authored
Merge branch 'main' into regulatory-haddock
2 parents a8e09c1 + 98d4b8b commit 5ded6fd

File tree

20 files changed

+170
-121
lines changed

20 files changed

+170
-121
lines changed
732 Bytes
Binary file not shown.

src/vs/base/common/codiconsLibrary.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,4 +589,7 @@ export const codiconsLibrary = {
589589
keyboardTab: register('keyboard-tab', 0xec3c),
590590
copilotBlocked: register('copilot-blocked', 0xec3d),
591591
copilotNotConnected: register('copilot-not-connected', 0xec3e),
592+
flag: register('flag', 0xec3f),
593+
lightbulbEmpty: register('lightbulb-empty', 0xec40),
594+
symbolMethodArrow: register('symbol-method-arrow', 0xec41),
592595
} as const;

src/vs/editor/common/languages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ export interface InlineCompletion {
789789

790790
/**
791791
* Is called the first time an inline completion is shown.
792+
* @deprecated. Use `onDidShow` of the provider instead.
792793
*/
793794
readonly shownCommand?: Command;
794795

src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -891,15 +891,17 @@ export class InlineCompletionsModel extends Disposable {
891891
});
892892
}
893893

894-
public async handleInlineCompletionShown(inlineCompletion: InlineCompletionItem): Promise<void> {
895-
if (!inlineCompletion.shownCommand) {
896-
return;
897-
}
894+
public async handleInlineEditShown(inlineCompletion: InlineCompletionItem): Promise<void> {
898895
if (inlineCompletion.didShow) {
899896
return;
900897
}
901898
inlineCompletion.markAsShown();
902-
await this._commandService.executeCommand(inlineCompletion.shownCommand.id, ...(inlineCompletion.shownCommand.arguments || []));
899+
900+
inlineCompletion.source.provider.handleItemDidShow?.(inlineCompletion.source.inlineCompletions, inlineCompletion.sourceInlineCompletion, inlineCompletion.insertText);
901+
902+
if (inlineCompletion.shownCommand) {
903+
await this._commandService.executeCommand(inlineCompletion.shownCommand.id, ...(inlineCompletion.shownCommand.arguments || []));
904+
}
903905
}
904906
}
905907

src/vs/editor/contrib/inlineCompletions/browser/model/provideInlineCompletions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ export class InlineCompletionItem {
345345
constructor(
346346
readonly filterText: string,
347347
readonly command: Command | undefined,
348+
/** @deprecated. Use handleItemDidShow */
348349
readonly shownCommand: Command | undefined,
349350
readonly action: Command | undefined,
350351
readonly range: Range,

src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/inlineEditsView.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class InlineEditsView extends Disposable {
9494
return undefined;
9595
}
9696

97-
this._model.get()?.handleInlineCompletionShown(edit.inlineCompletion);
97+
this._model.get()?.handleInlineEditShown(edit.inlineCompletion);
9898

9999
let mappings = RangeMapping.fromEdit(edit.edit);
100100
let newText = edit.edit.apply(edit.originalText);
@@ -157,7 +157,8 @@ export class InlineEditsView extends Disposable {
157157
const item = state?.read(reader);
158158
const completionSource = item?.inlineCompletion?.source;
159159
// TODO: expose the provider (typed) and expose the provider the edit belongs to typing and get correct edit
160-
return (completionSource?.inlineCompletions as any)?.edits?.[0]?.provider?.displayName ?? previousDisplayName ?? localize('inlineEdit', "Inline Edit");
160+
return (completionSource?.inlineCompletions as any)?.edits?.[0]?.provider?.displayName ?? previousDisplayName
161+
?? completionSource?.provider.displayName ?? localize('inlineEdit', "Inline Edit");
161162
}),
162163
tabAction: derived<InlineEditTabAction>(this, reader => {
163164
const m = this._model.read(reader);

src/vs/monaco.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7301,6 +7301,7 @@ declare namespace monaco.languages {
73017301
readonly action?: Command;
73027302
/**
73037303
* Is called the first time an inline completion is shown.
7304+
* @deprecated. Use `onDidShow` of the provider instead.
73047305
*/
73057306
readonly shownCommand?: Command;
73067307
/**

src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
614614
this._registrations.set(handle, this._languageFeaturesService.completionProvider.register(selector, provider));
615615
}
616616

617-
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[], supportsHandleEvents: boolean, extensionId: string, yieldsToExtensionIds: string[], debounceDelayMs: number | undefined): void {
617+
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[], supportsHandleEvents: boolean, extensionId: string, yieldsToExtensionIds: string[], displayName: string | undefined, debounceDelayMs: number | undefined): void {
618618
const provider: languages.InlineCompletionsProvider<IdentifiableInlineCompletions> = {
619619
provideInlineCompletions: async (model: ITextModel, position: EditorPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<IdentifiableInlineCompletions | undefined> => {
620620
return this._proxy.$provideInlineCompletions(handle, model.uri, position, context, token);
@@ -635,9 +635,15 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
635635
freeInlineCompletions: (completions: IdentifiableInlineCompletions): void => {
636636
this._proxy.$freeInlineCompletionsList(handle, completions.pid);
637637
},
638+
handleRejection: async (completions, item): Promise<void> => {
639+
if (supportsHandleEvents) {
640+
await this._proxy.$handleInlineCompletionRejection(handle, completions.pid, item.idx);
641+
}
642+
},
638643
groupId: extensionId,
639644
yieldsToGroupIds: yieldsToExtensionIds,
640645
debounceDelayMs,
646+
displayName,
641647
toString() {
642648
return `InlineCompletionsProvider(${extensionId})`;
643649
},

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
472472
$emitDocumentSemanticTokensEvent(eventHandle: number): void;
473473
$registerDocumentRangeSemanticTokensProvider(handle: number, selector: IDocumentFilterDto[], legend: languages.SemanticTokensLegend): void;
474474
$registerCompletionsProvider(handle: number, selector: IDocumentFilterDto[], triggerCharacters: string[], supportsResolveDetails: boolean, extensionId: ExtensionIdentifier): void;
475-
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[], supportsHandleDidShowCompletionItem: boolean, extensionId: string, yieldsToExtensionIds: string[], debounceDelayMs: number | undefined): void;
475+
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[], supportsHandleDidShowCompletionItem: boolean, extensionId: string, yieldsToExtensionIds: string[], displayName: string | undefined, debounceDelayMs: number | undefined): void;
476476
$registerInlineEditProvider(handle: number, selector: IDocumentFilterDto[], extensionId: ExtensionIdentifier, displayName: string): void;
477477
$registerSignatureHelpProvider(handle: number, selector: IDocumentFilterDto[], metadata: ISignatureHelpProviderMetadataDto): void;
478478
$registerInlayHintsProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean, eventHandle: number | undefined, displayName: string | undefined): void;
@@ -2333,6 +2333,7 @@ export interface ExtHostLanguageFeaturesShape {
23332333
$provideInlineEditsForRange(handle: number, resource: UriComponents, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<IdentifiableInlineCompletions | undefined>;
23342334
$handleInlineCompletionDidShow(handle: number, pid: number, idx: number, updatedInsertText: string): void;
23352335
$handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void;
2336+
$handleInlineCompletionRejection(handle: number, pid: number, idx: number): void;
23362337
$freeInlineCompletionsList(handle: number, pid: number): void;
23372338
$provideSignatureHelp(handle: number, resource: UriComponents, position: IPosition, context: languages.SignatureHelpContext, token: CancellationToken): Promise<ISignatureHelpDto | undefined>;
23382339
$releaseSignatureHelp(handle: number, id: number): void;

src/vs/workbench/api/common/extHostLanguageFeatures.ts

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,23 +1300,7 @@ class CompletionsAdapter {
13001300
}
13011301
}
13021302

1303-
class InlineCompletionAdapterBase {
1304-
async provideInlineCompletions(resource: URI, position: IPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
1305-
return undefined;
1306-
}
1307-
1308-
async provideInlineEditsForRange(resource: URI, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
1309-
return undefined;
1310-
}
1311-
1312-
disposeCompletions(pid: number): void { }
1313-
1314-
handleDidShowCompletionItem(pid: number, idx: number, updatedInsertText: string): void { }
1315-
1316-
handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void { }
1317-
}
1318-
1319-
class InlineCompletionAdapter extends InlineCompletionAdapterBase {
1303+
class InlineCompletionAdapter {
13201304
private readonly _references = new ReferenceMap<{
13211305
dispose(): void;
13221306
items: readonly vscode.InlineCompletionItem[];
@@ -1330,21 +1314,22 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
13301314
private readonly _provider: vscode.InlineCompletionItemProvider,
13311315
private readonly _commands: CommandsConverter,
13321316
) {
1333-
super();
13341317
}
13351318

13361319
public get supportsHandleEvents(): boolean {
13371320
return isProposedApiEnabled(this._extension, 'inlineCompletionsAdditions')
13381321
&& (typeof this._provider.handleDidShowCompletionItem === 'function'
1339-
|| typeof this._provider.handleDidPartiallyAcceptCompletionItem === 'function');
1322+
|| typeof this._provider.handleDidPartiallyAcceptCompletionItem === 'function'
1323+
|| typeof this._provider.handleDidRejectCompletionItem === 'function'
1324+
);
13401325
}
13411326

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

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

@@ -1407,6 +1392,7 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
14071392
insertText: typeof insertText === 'string' ? insertText : { snippet: insertText.value },
14081393
filterText: item.filterText,
14091394
range: item.range ? typeConvert.Range.from(item.range) : undefined,
1395+
showRange: (this._isAdditionsProposedApiEnabled && item.showRange) ? typeConvert.Range.from(item.showRange) : undefined,
14101396
command,
14111397
action,
14121398
idx: idx,
@@ -1430,7 +1416,7 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
14301416
};
14311417
}
14321418

1433-
override async provideInlineEditsForRange(resource: URI, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
1419+
async provideInlineEditsForRange(resource: URI, range: IRange, context: languages.InlineCompletionContext, token: CancellationToken): Promise<extHostProtocol.IdentifiableInlineCompletions | undefined> {
14341420
if (!this._provider.provideInlineEditsForRange) {
14351421
return undefined;
14361422
}
@@ -1516,12 +1502,12 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
15161502
};
15171503
}
15181504

1519-
override disposeCompletions(pid: number) {
1505+
disposeCompletions(pid: number) {
15201506
const data = this._references.disposeReferenceId(pid);
15211507
data?.dispose();
15221508
}
15231509

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

1533-
override handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void {
1519+
handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void {
15341520
const completionItem = this._references.get(pid)?.items[idx];
15351521
if (completionItem) {
15361522
if (this._provider.handleDidPartiallyAcceptCompletionItem && this._isAdditionsProposedApiEnabled) {
@@ -1539,6 +1525,15 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
15391525
}
15401526
}
15411527
}
1528+
1529+
handleRejection(pid: number, idx: number): void {
1530+
const completionItem = this._references.get(pid)?.items[idx];
1531+
if (completionItem) {
1532+
if (this._provider.handleDidRejectCompletionItem && this._isAdditionsProposedApiEnabled) {
1533+
this._provider.handleDidRejectCompletionItem(completionItem);
1534+
}
1535+
}
1536+
}
15421537
}
15431538

15441539
class InlineEditAdapter {
@@ -2677,38 +2672,51 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
26772672
this._withAdapter(handle, CompletionsAdapter, adapter => adapter.releaseCompletionItems(id), undefined, undefined);
26782673
}
26792674

2680-
// --- ghost test
2675+
// --- ghost text
26812676

26822677
registerInlineCompletionsProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.InlineCompletionItemProvider, metadata: vscode.InlineCompletionItemProviderMetadata | undefined): vscode.Disposable {
26832678
const adapter = new InlineCompletionAdapter(extension, this._documents, provider, this._commands.converter);
26842679
const handle = this._addNewAdapter(adapter, extension);
2685-
this._proxy.$registerInlineCompletionsSupport(handle, this._transformDocumentSelector(selector, extension), adapter.supportsHandleEvents,
2686-
ExtensionIdentifier.toKey(extension.identifier.value), metadata?.yieldTo?.map(extId => ExtensionIdentifier.toKey(extId)) || [], metadata?.debounceDelayMs);
2680+
this._proxy.$registerInlineCompletionsSupport(
2681+
handle,
2682+
this._transformDocumentSelector(selector, extension),
2683+
adapter.supportsHandleEvents,
2684+
ExtensionIdentifier.toKey(extension.identifier.value),
2685+
metadata?.yieldTo?.map(extId => ExtensionIdentifier.toKey(extId)) || [],
2686+
metadata?.displayName,
2687+
metadata?.debounceDelayMs,
2688+
);
26872689
return this._createDisposable(handle);
26882690
}
26892691

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

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

26982700
$handleInlineCompletionDidShow(handle: number, pid: number, idx: number, updatedInsertText: string): void {
2699-
this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => {
2701+
this._withAdapter(handle, InlineCompletionAdapter, async adapter => {
27002702
adapter.handleDidShowCompletionItem(pid, idx, updatedInsertText);
27012703
}, undefined, undefined);
27022704
}
27032705

27042706
$handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void {
2705-
this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => {
2707+
this._withAdapter(handle, InlineCompletionAdapter, async adapter => {
27062708
adapter.handlePartialAccept(pid, idx, acceptedCharacters, info);
27072709
}, undefined, undefined);
27082710
}
27092711

2712+
$handleInlineCompletionRejection(handle: number, pid: number, idx: number): void {
2713+
this._withAdapter(handle, InlineCompletionAdapter, async adapter => {
2714+
adapter.handleRejection(pid, idx);
2715+
}, undefined, undefined);
2716+
}
2717+
27102718
$freeInlineCompletionsList(handle: number, pid: number): void {
2711-
this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => { adapter.disposeCompletions(pid); }, undefined, undefined);
2719+
this._withAdapter(handle, InlineCompletionAdapter, async adapter => { adapter.disposeCompletions(pid); }, undefined, undefined);
27122720
}
27132721

27142722
// --- inline edit

0 commit comments

Comments
 (0)