Skip to content

Commit

Permalink
incorporate API feedback, #16221
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jan 19, 2022
1 parent c333d44 commit 8ef8933
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
9 changes: 5 additions & 4 deletions src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1765,17 +1765,18 @@ export enum InlayHintKind {

export interface InlayHintLabelPart {
label: string;
collapsible?: boolean;
action?: Command | Location
// collapsible?: boolean;
command?: Command
location?: Location;
}

export interface InlayHint {
label: string | InlayHintLabelPart[];
tooltip?: string | IMarkdownString
position: IPosition;
kind: InlayHintKind;
whitespaceBefore?: boolean;
whitespaceAfter?: boolean;
paddingLeft?: boolean;
paddingRight?: boolean;
}

export interface InlayHintList {
Expand Down
20 changes: 10 additions & 10 deletions src/vs/editor/contrib/inlayHints/inlayHintsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
});
Expand Down Expand Up @@ -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);
}

Expand All @@ -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';
Expand All @@ -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);
}

Expand Down
10 changes: 3 additions & 7 deletions src/vs/editor/contrib/inlayHints/inlayHintsHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/vs/editor/contrib/inlayHints/inlayHintsLocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6864,17 +6864,17 @@ declare namespace monaco.languages {

export interface InlayHintLabelPart {
label: string;
collapsible?: boolean;
action?: Command | Location;
command?: Command;
location?: Location;
}

export interface InlayHint {
label: string | InlayHintLabelPart[];
tooltip?: string | IMarkdownString;
position: IPosition;
kind: InlayHintKind;
whitespaceBefore?: boolean;
whitespaceAfter?: boolean;
paddingLeft?: boolean;
paddingRight?: boolean;
}

export interface InlayHintList {
Expand Down
13 changes: 6 additions & 7 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1260,20 +1260,19 @@ 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') {
result.label = hint.label;
} 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;
});
Expand Down
14 changes: 7 additions & 7 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
Expand Down
13 changes: 6 additions & 7 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 16 additions & 11 deletions src/vscode-dts/vscode.proposed.inlayHints.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ declare module 'vscode' {
}

export class InlayHintLabelPart {

label: string;

// todo@API implement this!
collapsible?: boolean;
// invokes provider
location?: Location;

command?: Command;

// todo@api better name!
action?: Command | Location; // invokes provider
// todo@api
// context menu, contextMenuCommands
// secondaryCommands?: Command[];

constructor(label: string);
}
Expand All @@ -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);
Expand Down

0 comments on commit 8ef8933

Please sign in to comment.