Skip to content

Commit ffdeff7

Browse files
committed
show error when inlay hints command fails, annotate error with source (e.g extension name), fixes microsoft#141588
1 parent 4f9c935 commit ffdeff7

File tree

8 files changed

+33
-12
lines changed

8 files changed

+33
-12
lines changed

src/vs/editor/common/languages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ export interface InlayHintList {
18461846
}
18471847

18481848
export interface InlayHintsProvider {
1849+
displayName?: string
18491850
onDidChangeInlayHints?: Event<void>;
18501851
provideInlayHints(model: model.ITextModel, range: Range, token: CancellationToken): ProviderResult<InlayHintList>;
18511852
resolveInlayHint?(hint: InlayHint, token: CancellationToken): ProviderResult<InlayHint>;

src/vs/editor/contrib/inlayHints/browser/inlayHints.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ export class InlayHintItem {
2020
private _isResolved: boolean = false;
2121
private _currentResolve?: Promise<void>;
2222

23-
constructor(readonly hint: InlayHint, readonly anchor: InlayHintAnchor, private readonly _provider: InlayHintsProvider) { }
23+
constructor(readonly hint: InlayHint, readonly anchor: InlayHintAnchor, readonly provider: InlayHintsProvider) { }
2424

2525
with(delta: { anchor: InlayHintAnchor; }): InlayHintItem {
26-
const result = new InlayHintItem(this.hint, delta.anchor, this._provider);
26+
const result = new InlayHintItem(this.hint, delta.anchor, this.provider);
2727
result._isResolved = this._isResolved;
2828
result._currentResolve = this._currentResolve;
2929
return result;
3030
}
3131

3232
async resolve(token: CancellationToken): Promise<void> {
33-
if (typeof this._provider.resolveInlayHint !== 'function') {
33+
if (typeof this.provider.resolveInlayHint !== 'function') {
3434
return;
3535
}
3636
if (this._currentResolve) {
@@ -51,7 +51,7 @@ export class InlayHintItem {
5151

5252
private async _doResolve(token: CancellationToken) {
5353
try {
54-
const newHint = await Promise.resolve(this._provider.resolveInlayHint!(this.hint, token));
54+
const newHint = await Promise.resolve(this.provider.resolveInlayHint!(this.hint, token));
5555
this.hint.tooltip = newHint?.tooltip ?? this.hint.tooltip;
5656
this.hint.label = newHint?.label ?? this.hint.label;
5757
this._isResolved = true;

src/vs/editor/contrib/inlayHints/browser/inlayHintsController.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { goToDefinitionWithLocation, showGoToContextMenu } from 'vs/editor/contr
2828
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
2929
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
3030
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
31-
import { INotificationService } from 'vs/platform/notification/common/notification';
31+
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
3232
import * as colors from 'vs/platform/theme/common/colorRegistry';
3333
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
3434

@@ -254,7 +254,7 @@ export class InlayHintsController implements IEditorContribution {
254254
}
255255
});
256256
gesture.onCancel(removeHighlight);
257-
gesture.onExecute(e => {
257+
gesture.onExecute(async e => {
258258
const label = this._getInlayHintLabelPart(e);
259259
if (label) {
260260
const part = label.part;
@@ -263,7 +263,15 @@ export class InlayHintsController implements IEditorContribution {
263263
this._instaService.invokeFunction(goToDefinitionWithLocation, e, this._editor as IActiveCodeEditor, part.location);
264264
} else if (languages.Command.is(part.command)) {
265265
// command -> execute it
266-
this._commandService.executeCommand(part.command.id, ...(part.command.arguments ?? [])).catch(err => this._notificationService.error(err));
266+
try {
267+
await this._commandService.executeCommand(part.command.id, ...(part.command.arguments ?? []));
268+
} catch (err) {
269+
this._notificationService.notify({
270+
severity: Severity.Error,
271+
source: label.item.provider.displayName,
272+
message: err
273+
});
274+
}
267275
}
268276
}
269277
});

src/vs/editor/contrib/inlayHints/browser/inlayHintsLocations.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
2121
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2222
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
2323
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
24+
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
2425

2526
export async function showGoToContextMenu(accessor: ServicesAccessor, editor: ICodeEditor, anchor: HTMLElement, part: RenderedInlayHintLabelPart) {
2627

2728
const resolverService = accessor.get(ITextModelService);
2829
const contextMenuService = accessor.get(IContextMenuService);
2930
const commandService = accessor.get(ICommandService);
3031
const instaService = accessor.get(IInstantiationService);
32+
const notificationService = accessor.get(INotificationService);
3133

3234
await part.item.resolve(CancellationToken.None);
3335

@@ -60,8 +62,16 @@ export async function showGoToContextMenu(accessor: ServicesAccessor, editor: IC
6062
if (part.part.command) {
6163
const { command } = part.part;
6264
menuActions.push(new Separator());
63-
menuActions.push(new Action(command.id, command.title, undefined, true, () => {
64-
commandService.executeCommand(command.id, ...(command.arguments ?? []));
65+
menuActions.push(new Action(command.id, command.title, undefined, true, async () => {
66+
try {
67+
await commandService.executeCommand(command.id, ...(command.arguments ?? []));
68+
} catch (err) {
69+
notificationService.notify({
70+
severity: Severity.Error,
71+
source: part.item.provider.displayName,
72+
message: err
73+
});
74+
}
6575
}));
6676
}
6777

src/vs/monaco.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6908,6 +6908,7 @@ declare namespace monaco.languages {
69086908
}
69096909

69106910
export interface InlayHintsProvider {
6911+
displayName?: string;
69116912
onDidChangeInlayHints?: IEvent<void>;
69126913
provideInlayHints(model: editor.ITextModel, range: Range, token: CancellationToken): ProviderResult<InlayHintList>;
69136914
resolveInlayHint?(hint: InlayHint, token: CancellationToken): ProviderResult<InlayHint>;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,9 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
552552

553553
// --- inline hints
554554

555-
$registerInlayHintsProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean, eventHandle: number | undefined): void {
555+
$registerInlayHintsProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean, eventHandle: number | undefined, displayName: string | undefined): void {
556556
const provider = <modes.InlayHintsProvider>{
557+
displayName,
557558
provideInlayHints: async (model: ITextModel, range: EditorRange, token: CancellationToken): Promise<modes.InlayHintList | undefined> => {
558559
const result = await this._proxy.$provideInlayHints(handle, model.uri, range, token);
559560
if (!result) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
441441
$registerSuggestSupport(handle: number, selector: IDocumentFilterDto[], triggerCharacters: string[], supportsResolveDetails: boolean, displayName: string): void;
442442
$registerInlineCompletionsSupport(handle: number, selector: IDocumentFilterDto[]): void;
443443
$registerSignatureHelpProvider(handle: number, selector: IDocumentFilterDto[], metadata: ISignatureHelpProviderMetadataDto): void;
444-
$registerInlayHintsProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean, eventHandle: number | undefined): void;
444+
$registerInlayHintsProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean, eventHandle: number | undefined, displayName: string | undefined): void;
445445
$emitInlayHintsEvent(eventHandle: number): void;
446446
$registerDocumentLinkProvider(handle: number, selector: IDocumentFilterDto[], supportsResolve: boolean): void;
447447
$registerDocumentColorProvider(handle: number, selector: IDocumentFilterDto[]): void;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
20862086
const eventHandle = typeof provider.onDidChangeInlayHints === 'function' ? this._nextHandle() : undefined;
20872087
const handle = this._addNewAdapter(new InlayHintsAdapter(this._documents, this._commands.converter, provider, this._logService, extension), extension);
20882088

2089-
this._proxy.$registerInlayHintsProvider(handle, this._transformDocumentSelector(selector), typeof provider.resolveInlayHint === 'function', eventHandle);
2089+
this._proxy.$registerInlayHintsProvider(handle, this._transformDocumentSelector(selector), typeof provider.resolveInlayHint === 'function', eventHandle, ExtHostLanguageFeatures._extLabel(extension));
20902090
let result = this._createDisposable(handle);
20912091

20922092
if (eventHandle !== undefined) {

0 commit comments

Comments
 (0)