From d4dde3aa066c1da8ab10a73091cc66845c13c7e2 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 19 Jan 2022 13:54:35 +0100 Subject: [PATCH] support label part tooltip in addition to item tooltip, https://github.com/microsoft/vscode/issues/16221#issuecomment-264527520 --- src/vs/editor/common/languages.ts | 1 + .../contrib/inlayHints/inlayHintsHover.ts | 26 ++++++++++++------- src/vs/monaco.d.ts | 1 + .../api/common/extHostLanguageFeatures.ts | 9 ++++--- .../api/common/extHostTypeConverters.ts | 4 ++- src/vs/workbench/api/common/extHostTypes.ts | 2 ++ .../vscode.proposed.inlayHints.d.ts | 12 +++++++-- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/vs/editor/common/languages.ts b/src/vs/editor/common/languages.ts index 566872323a353..126f4bf63351c 100644 --- a/src/vs/editor/common/languages.ts +++ b/src/vs/editor/common/languages.ts @@ -1765,6 +1765,7 @@ export enum InlayHintKind { export interface InlayHintLabelPart { label: string; + tooltip?: string | IMarkdownString // collapsible?: boolean; command?: Command location?: Location; diff --git a/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts b/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts index 578f37c42db63..102c8de52a53a 100644 --- a/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts +++ b/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts @@ -72,17 +72,28 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor } // (1) Inlay Tooltip - let contents: IMarkdownString | undefined; + let itemTooltip: IMarkdownString | undefined; if (typeof part.item.hint.tooltip === 'string') { - contents = new MarkdownString().appendText(part.item.hint.tooltip); + itemTooltip = new MarkdownString().appendText(part.item.hint.tooltip); } else if (part.item.hint.tooltip) { - contents = part.item.hint.tooltip; + itemTooltip = part.item.hint.tooltip; } - if (contents) { - executor.emitOne(new MarkdownHover(this, anchor.range, [contents], 0)); + if (itemTooltip) { + executor.emitOne(new MarkdownHover(this, anchor.range, [itemTooltip], 0)); } // (2) Inlay Label Part Tooltip + let partTooltip: IMarkdownString | undefined; + if (typeof part.part.tooltip === 'string') { + partTooltip = new MarkdownString().appendText(part.part.tooltip); + } else if (part.part.tooltip) { + partTooltip = part.part.tooltip; + } + if (partTooltip) { + executor.emitOne(new MarkdownHover(this, anchor.range, [partTooltip], 1)); + } + + // (3) Inlay Label Part Location tooltip const iterable = await this._resolveInlayHintLabelPartHover(part, token); for await (let item of iterable) { executor.emitOne(item); @@ -91,9 +102,6 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor } private async _resolveInlayHintLabelPartHover(part: RenderedInlayHintLabelPart, token: CancellationToken): Promise> { - if (typeof part.item.hint.label === 'string') { - return AsyncIterableObject.EMPTY; - } if (!part.part.location) { return AsyncIterableObject.EMPTY; } @@ -106,7 +114,7 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor } return getHover(model, new Position(range.startLineNumber, range.startColumn), token) .filter(item => !isEmptyMarkdownString(item.hover.contents)) - .map(item => new MarkdownHover(this, part.item.anchor.range, item.hover.contents, item.ordinal)); + .map(item => new MarkdownHover(this, part.item.anchor.range, item.hover.contents, 2 + item.ordinal)); } finally { ref.dispose(); } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index f8b02befc1899..d71d3de374976 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -6864,6 +6864,7 @@ declare namespace monaco.languages { export interface InlayHintLabelPart { label: string; + tooltip?: string | IMarkdownString; command?: Command; location?: Location; } diff --git a/src/vs/workbench/api/common/extHostLanguageFeatures.ts b/src/vs/workbench/api/common/extHostLanguageFeatures.ts index 22180d832a769..3b240c5d35614 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -1268,13 +1268,14 @@ class InlayHintsAdapter { result.label = hint.label; } else { result.label = hint.label.map(part => { - let r: modes.InlayHintLabelPart = { label: part.label }; + let result: modes.InlayHintLabelPart = { label: part.label }; + result.tooltip = part.tooltip && typeConvert.MarkdownString.from(part.tooltip); if (Location.isLocation(part.location)) { - r.location = typeConvert.location.from(part.location); + result.location = typeConvert.location.from(part.location); } else if (part.command) { - r.command = this._commands.toInternal(part.command, disposables); + result.command = this._commands.toInternal(part.command, disposables); } - return r; + return result; }); } return result; diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 6a5e23cb24edd..78e3da5776491 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1169,7 +1169,9 @@ export namespace InlayHintLabelPart { export function to(converter: CommandsConverter, part: modes.InlayHintLabelPart): types.InlayHintLabelPart { const result = new types.InlayHintLabelPart(part.label); - + result.tooltip = htmlContent.isMarkdownString(part.tooltip) + ? MarkdownString.to(part.tooltip) + : part.tooltip; if (modes.Command.is(part.command)) { result.command = converter.fromInternal(part.command); } else if (part.location) { diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index b29442ff19261..c204ba85776f4 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -1423,7 +1423,9 @@ export enum InlayHintKind { @es5ClassCompat export class InlayHintLabelPart { + label: string; + tooltip?: string | vscode.MarkdownString; location?: Location; command?: vscode.Command; diff --git a/src/vscode-dts/vscode.proposed.inlayHints.d.ts b/src/vscode-dts/vscode.proposed.inlayHints.d.ts index fd0b0ab4a3463..8510c24713531 100644 --- a/src/vscode-dts/vscode.proposed.inlayHints.d.ts +++ b/src/vscode-dts/vscode.proposed.inlayHints.d.ts @@ -39,12 +39,20 @@ declare module 'vscode' { export class InlayHintLabelPart { + /** + * The value of this label part. + */ label: string; + /** + * The tooltip text when you hover over this label part. + */ + tooltip?: string | MarkdownString | undefined; + // invokes provider - location?: Location; + location?: Location | undefined; - command?: Command; + command?: Command | undefined; // todo@api // context menu, contextMenuCommands