diff --git a/extensions/typescript-language-features/src/languageFeatures/inlayHints.ts b/extensions/typescript-language-features/src/languageFeatures/inlayHints.ts index a31cbd1ea52..a57584c491e 100644 --- a/extensions/typescript-language-features/src/languageFeatures/inlayHints.ts +++ b/extensions/typescript-language-features/src/languageFeatures/inlayHints.ts @@ -75,8 +75,8 @@ class TypeScriptInlayHintsProvider extends Disposable implements vscode.InlayHin Position.fromLocation(hint.position), hint.kind && fromProtocolInlayHintKind(hint.kind) ); - result.whitespaceBefore = hint.whitespaceBefore; - result.whitespaceAfter = hint.whitespaceAfter; + result.paddingLeft = hint.whitespaceBefore; + result.paddingRight = hint.whitespaceAfter; return result; }); } diff --git a/src/vs/editor/common/languages.ts b/src/vs/editor/common/languages.ts index 52c84e3e2e7..566872323a3 100644 --- a/src/vs/editor/common/languages.ts +++ b/src/vs/editor/common/languages.ts @@ -1765,8 +1765,9 @@ export enum InlayHintKind { export interface InlayHintLabelPart { label: string; - collapsible?: boolean; - action?: Command | Location + // collapsible?: boolean; + command?: Command + location?: Location; } export interface InlayHint { @@ -1774,8 +1775,8 @@ export interface InlayHint { tooltip?: string | IMarkdownString position: IPosition; kind: InlayHintKind; - whitespaceBefore?: boolean; - whitespaceAfter?: boolean; + paddingLeft?: boolean; + paddingRight?: boolean; } export interface InlayHintList { diff --git a/src/vs/editor/contrib/inlayHints/inlayHintsController.ts b/src/vs/editor/contrib/inlayHints/inlayHintsController.ts index 78ab52cd83f..1ad65220100 100644 --- a/src/vs/editor/contrib/inlayHints/inlayHintsController.ts +++ b/src/vs/editor/contrib/inlayHints/inlayHintsController.ts @@ -184,8 +184,8 @@ export class InlayHintsController implements IEditorContribution { return; } - // render link => when the modifier is pressed and when there is an action - if (mouseEvent.hasTriggerModifier && labelPart.part.action) { + // render link => when the modifier is pressed and when there is a command or location + if (mouseEvent.hasTriggerModifier && (labelPart.part.command || labelPart.part.location)) { // resolve the item const cts = new CancellationTokenSource(); @@ -214,13 +214,13 @@ export class InlayHintsController implements IEditorContribution { const label = this._getInlayHintLabelPart(e); if (label) { const part = label.part; - if (languages.Command.is(part.action)) { + if (languages.Command.is(part.command)) { // command -> execute it - this._commandService.executeCommand(part.action.id, ...(part.action.arguments ?? [])).catch(err => this._notificationService.error(err)); + this._commandService.executeCommand(part.command.id, ...(part.command.arguments ?? [])).catch(err => this._notificationService.error(err)); - } else if (part.action) { + } else if (part.location) { // location -> execute go to def - this._instaService.invokeFunction(goToDefinitionWithLocation, e, this._editor as IActiveCodeEditor, part.action); + this._instaService.invokeFunction(goToDefinitionWithLocation, e, this._editor as IActiveCodeEditor, part.location); } } }); @@ -331,7 +331,7 @@ export class InlayHintsController implements IEditorContribution { for (const item of items) { // whitespace leading the actual label - if (item.hint.whitespaceBefore) { + if (item.hint.paddingLeft) { addInjectedWhitespace(item, false); } @@ -354,7 +354,7 @@ export class InlayHintsController implements IEditorContribution { this._fillInColors(cssProperties, item.hint); - if (part.action && this._activeInlayHintPart?.item === item && this._activeInlayHintPart.index === i) { + if ((part.command || part.location) && this._activeInlayHintPart?.item === item && this._activeInlayHintPart.index === i) { // active link! cssProperties.textDecoration = 'underline'; cssProperties.cursor = 'pointer'; @@ -381,13 +381,13 @@ export class InlayHintsController implements IEditorContribution { item, this._ruleFactory.createClassNameRef(cssProperties), fixSpace(part.label), - isLast && !item.hint.whitespaceAfter ? InjectedTextCursorStops.Right : InjectedTextCursorStops.None, + isLast && !item.hint.paddingRight ? InjectedTextCursorStops.Right : InjectedTextCursorStops.None, new RenderedInlayHintLabelPart(item, i) ); } // whitespace trailing the actual label - if (item.hint.whitespaceAfter) { + if (item.hint.paddingRight) { addInjectedWhitespace(item, true); } diff --git a/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts b/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts index b379c88d373..578f37c42db 100644 --- a/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts +++ b/src/vs/editor/contrib/inlayHints/inlayHintsHover.ts @@ -8,7 +8,7 @@ import { CancellationToken } from 'vs/base/common/cancellation'; import { IMarkdownString, isEmptyMarkdownString, MarkdownString } from 'vs/base/common/htmlContent'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { Position } from 'vs/editor/common/core/position'; -import { Command, HoverProviderRegistry } from 'vs/editor/common/languages'; +import { HoverProviderRegistry } from 'vs/editor/common/languages'; import { IModelDecoration } from 'vs/editor/common/model'; import { ModelDecorationInjectedTextOptions } from 'vs/editor/common/model/textModel'; import { HoverAnchor, HoverForeignElementAnchor, IEditorHoverParticipant } from 'vs/editor/contrib/hover/hoverTypes'; @@ -94,14 +94,10 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor if (typeof part.item.hint.label === 'string') { return AsyncIterableObject.EMPTY; } - - const candidate = part.part.action; - - if (!candidate || Command.is(candidate)) { - // LOCATION + if (!part.part.location) { return AsyncIterableObject.EMPTY; } - const { uri, range } = candidate; + const { uri, range } = part.part.location; const ref = await this._resolverService.createModelReference(uri); try { const model = ref.object.textEditorModel; diff --git a/src/vs/editor/contrib/inlayHints/inlayHintsLocations.ts b/src/vs/editor/contrib/inlayHints/inlayHintsLocations.ts index 0df51db6870..356863216f8 100644 --- a/src/vs/editor/contrib/inlayHints/inlayHintsLocations.ts +++ b/src/vs/editor/contrib/inlayHints/inlayHintsLocations.ts @@ -10,7 +10,7 @@ import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser' import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions'; import { EditorOption } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; -import { Command, Location } from 'vs/editor/common/languages'; +import { Location } from 'vs/editor/common/languages'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { DefinitionAction, SymbolNavigationAction, SymbolNavigationAnchor } from 'vs/editor/contrib/gotoSymbol/goToCommands'; import { ClickLinkMouseEvent } from 'vs/editor/contrib/gotoSymbol/link/clickLinkGesture'; @@ -29,11 +29,11 @@ export async function showGoToContextMenu(accessor: ServicesAccessor, editor: IC await part.item.resolve(CancellationToken.None); - if (!part.part.action || Command.is(part.part.action)) { + if (!part.part.location) { return; } - const location: Location = part.part.action; + const location: Location = part.part.location; const menuActions: IAction[] = []; // from all registered (not active) context menu actions select those diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 1de2d4856c7..f8b02befc18 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -6864,8 +6864,8 @@ declare namespace monaco.languages { export interface InlayHintLabelPart { label: string; - collapsible?: boolean; - action?: Command | Location; + command?: Command; + location?: Location; } export interface InlayHint { @@ -6873,8 +6873,8 @@ declare namespace monaco.languages { tooltip?: string | IMarkdownString; position: IPosition; kind: InlayHintKind; - whitespaceBefore?: boolean; - whitespaceAfter?: boolean; + paddingLeft?: boolean; + paddingRight?: boolean; } export interface InlayHintList { diff --git a/src/vs/workbench/api/common/extHostLanguageFeatures.ts b/src/vs/workbench/api/common/extHostLanguageFeatures.ts index a16f72fdb12..22180d832a7 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -1260,8 +1260,8 @@ class InlayHintsAdapter { tooltip: hint.tooltip && typeConvert.MarkdownString.from(hint.tooltip), position: typeConvert.Position.from(hint.position), kind: typeConvert.InlayHintKind.from(hint.kind ?? InlayHintKind.Other), - whitespaceBefore: hint.whitespaceBefore, - whitespaceAfter: hint.whitespaceAfter, + whitespaceBefore: hint.paddingLeft, + whitespaceAfter: hint.paddingRight, }; if (typeof hint.label === 'string') { @@ -1269,11 +1269,10 @@ class InlayHintsAdapter { } else { result.label = hint.label.map(part => { let r: modes.InlayHintLabelPart = { label: part.label }; - r.collapsible = part.collapsible; - if (Location.isLocation(part.action)) { - r.action = typeConvert.location.from(part.action); - } else if (part.action) { - r.action = this._commands.toInternal(part.action, disposables); + if (Location.isLocation(part.location)) { + r.location = typeConvert.location.from(part.location); + } else if (part.command) { + r.command = this._commands.toInternal(part.command, disposables); } return r; }); diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 79e3d9aa20e..6a5e23cb24e 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1159,8 +1159,8 @@ export namespace InlayHint { InlayHintKind.to(hint.kind) ); res.tooltip = htmlContent.isMarkdownString(hint.tooltip) ? MarkdownString.to(hint.tooltip) : hint.tooltip; - res.whitespaceAfter = hint.whitespaceAfter; - res.whitespaceBefore = hint.whitespaceBefore; + res.paddingLeft = hint.paddingLeft; + res.paddingRight = hint.paddingRight; return res; } } @@ -1169,11 +1169,11 @@ export namespace InlayHintLabelPart { export function to(converter: CommandsConverter, part: modes.InlayHintLabelPart): types.InlayHintLabelPart { const result = new types.InlayHintLabelPart(part.label); - result.collapsible = part.collapsible; - if (modes.Command.is(part.action)) { - result.action = converter.fromInternal(part.action); - } else if (part.action) { - result.action = location.to(part.action); + + if (modes.Command.is(part.command)) { + result.command = converter.fromInternal(part.command); + } else if (part.location) { + result.location = location.to(part.location); } return result; } diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index d08fb7bd57a..b29442ff192 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -1424,24 +1424,23 @@ export enum InlayHintKind { @es5ClassCompat export class InlayHintLabelPart { label: string; - collapsible?: boolean; - action?: vscode.Command | Location; // invokes provider + location?: Location; + command?: vscode.Command; + constructor(label: string) { this.label = label; } - toString(): string { - return this.label; - } } @es5ClassCompat export class InlayHint implements vscode.InlayHint { + label: string | InlayHintLabelPart[]; tooltip?: string | vscode.MarkdownString; position: Position; kind?: vscode.InlayHintKind; - whitespaceBefore?: boolean; - whitespaceAfter?: boolean; + paddingLeft?: boolean; + paddingRight?: boolean; constructor(label: string | InlayHintLabelPart[], position: Position, kind?: vscode.InlayHintKind) { this.label = label; diff --git a/src/vscode-dts/vscode.proposed.inlayHints.d.ts b/src/vscode-dts/vscode.proposed.inlayHints.d.ts index ffcba60018c..fd0b0ab4a34 100644 --- a/src/vscode-dts/vscode.proposed.inlayHints.d.ts +++ b/src/vscode-dts/vscode.proposed.inlayHints.d.ts @@ -38,13 +38,17 @@ declare module 'vscode' { } export class InlayHintLabelPart { + label: string; - // todo@API implement this! - collapsible?: boolean; + // invokes provider + location?: Location; - // todo@api better name! - action?: Command | Location; // invokes provider + command?: Command; + + // todo@api + // context menu, contextMenuCommands + // secondaryCommands?: Command[]; constructor(label: string); } @@ -64,22 +68,23 @@ declare module 'vscode' { /** * The tooltip text when you hover over this item. */ - // todo@API better name, more model'ish description, detail tooltip?: string | MarkdownString | undefined; /** * The kind of this hint. */ kind?: InlayHintKind; + /** - * Whitespace before the hint. + * Render padding before the hint. */ - // todo@API better name - whitespaceBefore?: boolean; + paddingLeft?: boolean; /** - * Whitespace after the hint. + * Render padding after the hint. */ - // todo@API better name - whitespaceAfter?: boolean; + paddingRight?: boolean; + + // emphemeral overlay mode + // overlayRange?: Range; // todo@API make range first argument constructor(label: string | InlayHintLabelPart[], position: Position, kind?: InlayHintKind);