Skip to content

Commit

Permalink
vscode: support label part tooltip in addition to item tooltip, micro…
Browse files Browse the repository at this point in the history
…soft/vscode#16221 (comment)

Commit: d4dde3aa066c1da8ab10a73091cc66845c13c7e2
  • Loading branch information
Johannes Rieken authored and sourcegraph-bot committed Jan 19, 2022
1 parent b1f5364 commit 44e7d3f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions vscode/src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,7 @@ export enum InlayHintKind {

export interface InlayHintLabelPart {
label: string;
tooltip?: string | IMarkdownString
// collapsible?: boolean;
command?: Command
location?: Location;
Expand Down
26 changes: 17 additions & 9 deletions vscode/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -91,9 +102,6 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
}

private async _resolveInlayHintLabelPartHover(part: RenderedInlayHintLabelPart, token: CancellationToken): Promise<AsyncIterableObject<MarkdownHover>> {
if (typeof part.item.hint.label === 'string') {
return AsyncIterableObject.EMPTY;
}
if (!part.part.location) {
return AsyncIterableObject.EMPTY;
}
Expand All @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions vscode/src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6864,6 +6864,7 @@ declare namespace monaco.languages {

export interface InlayHintLabelPart {
label: string;
tooltip?: string | IMarkdownString;
command?: Command;
location?: Location;
}
Expand Down
9 changes: 5 additions & 4 deletions vscode/src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion vscode/src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions vscode/src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,9 @@ export enum InlayHintKind {

@es5ClassCompat
export class InlayHintLabelPart {

label: string;
tooltip?: string | vscode.MarkdownString;
location?: Location;
command?: vscode.Command;

Expand Down
12 changes: 10 additions & 2 deletions vscode/src/vscode-dts/vscode.proposed.inlayHints.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44e7d3f

Please sign in to comment.