Skip to content

Commit

Permalink
Merge pull request #161836 from microsoft/alexd/pr-159226
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Sep 26, 2022
2 parents 8013a36 + 313203e commit 3c9903f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ class Widget {
}
}

// Left-align widgets that should appear :before content
if (this._affinity === PositionAffinity.LeftOfInjectedText &&
this._viewRange.startColumn === 1) {
firstLineMinLeft = 0;
}

let lastLineMinLeft = Constants.MAX_SAFE_SMALL_INTEGER;//lastLine.Constants.MAX_SAFE_SMALL_INTEGER;
for (const visibleRange of lastLine.ranges) {
if (visibleRange.left < lastLineMinLeft) {
Expand Down
12 changes: 11 additions & 1 deletion src/vs/editor/contrib/hover/browser/contentHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ContentWidgetPositionPreference, IActiveCodeEditor, ICodeEditor, IConte
import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { IModelDecoration } from 'vs/editor/common/model';
import { IModelDecoration, PositionAffinity } from 'vs/editor/common/model';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { TokenizationRegistry } from 'vs/editor/common/languages';
import { HoverOperation, HoverStartMode, IHoverComputer } from 'vs/editor/contrib/hover/browser/hoverOperation';
Expand Down Expand Up @@ -261,6 +261,9 @@ export class ContentHoverController extends Disposable {
disposables.add(participant.renderHoverParts(context, hoverParts));
}
}

const isBeforeContent = messages.some(m => m.isBeforeContent);

if (statusBar.hasContent) {
fragment.appendChild(statusBar.hoverElement);
}
Expand All @@ -283,6 +286,7 @@ export class ContentHoverController extends Disposable {
showAtRange,
this._editor.getOption(EditorOption.hover).above,
this._computer.shouldFocus,
isBeforeContent,
anchor.initialMousePosX,
anchor.initialMousePosY,
disposables
Expand Down Expand Up @@ -368,6 +372,7 @@ class ContentHoverVisibleData {
public readonly showAtRange: Range,
public readonly preferAbove: boolean,
public readonly stoleFocus: boolean,
public readonly isBeforeContent: boolean,
public initialMousePosX: number | undefined,
public initialMousePosY: number | undefined,
public readonly disposables: DisposableStore
Expand Down Expand Up @@ -439,6 +444,10 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {
// Prefer rendering above if the suggest widget is visible
preferAbove = true;
}

// :before content can align left of the text content
const affinity = this._visibleData.isBeforeContent ? PositionAffinity.LeftOfInjectedText : undefined;

return {
position: this._visibleData.showAtPosition,
range: this._visibleData.showAtRange,
Expand All @@ -447,6 +456,7 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {
? [ContentWidgetPositionPreference.ABOVE, ContentWidgetPositionPreference.BELOW]
: [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE]
),
positionAffinity: affinity
};
}

Expand Down
5 changes: 5 additions & 0 deletions src/vs/editor/contrib/hover/browser/hoverTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export interface IHoverPart {
* even in the case of multiple hover parts.
*/
readonly forceShowAtRange?: boolean;

/**
* If true, the hover item should appear before content
*/
readonly isBeforeContent?: boolean;
/**
* Is this hover part still valid for this new anchor?
*/
Expand Down
15 changes: 11 additions & 4 deletions src/vs/editor/contrib/hover/browser/markdownHoverParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class MarkdownHover implements IHoverPart {
public readonly owner: IEditorHoverParticipant<MarkdownHover>,
public readonly range: Range,
public readonly contents: IMarkdownString[],
public readonly isBeforeContent: boolean,
public readonly ordinal: number
) { }

Expand All @@ -55,7 +56,7 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
) { }

public createLoadingMessage(anchor: HoverAnchor): MarkdownHover | null {
return new MarkdownHover(this, anchor.range, [new MarkdownString().appendText(nls.localize('modesContentHover.loading', "Loading..."))], 2000);
return new MarkdownHover(this, anchor.range, [new MarkdownString().appendText(nls.localize('modesContentHover.loading', "Loading..."))], false, 2000);
}

public computeSync(anchor: HoverAnchor, lineDecorations: IModelDecoration[]): MarkdownHover[] {
Expand All @@ -78,9 +79,11 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
if (typeof maxTokenizationLineLength === 'number' && lineLength >= maxTokenizationLineLength) {
result.push(new MarkdownHover(this, anchor.range, [{
value: nls.localize('too many characters', "Tokenization is skipped for long lines for performance reasons. This can be configured via `editor.maxTokenizationLineLength`.")
}], index++));
}], false, index++));
}

let isBeforeContent = false;

for (const d of lineDecorations) {
const startColumn = (d.range.startLineNumber === lineNumber) ? d.range.startColumn : 1;
const endColumn = (d.range.endLineNumber === lineNumber) ? d.range.endColumn : maxColumn;
Expand All @@ -90,8 +93,12 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
continue;
}

if (d.options.beforeContentClassName) {
isBeforeContent = true;
}

const range = new Range(anchor.range.startLineNumber, startColumn, anchor.range.startLineNumber, endColumn);
result.push(new MarkdownHover(this, range, asArray(hoverMessage), index++));
result.push(new MarkdownHover(this, range, asArray(hoverMessage), isBeforeContent, index++));
}

return result;
Expand All @@ -113,7 +120,7 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
.filter(item => !isEmptyMarkdownString(item.hover.contents))
.map(item => {
const rng = item.hover.range ? Range.lift(item.hover.range) : anchor.range;
return new MarkdownHover(this, rng, item.hover.contents, item.ordinal);
return new MarkdownHover(this, rng, item.hover.contents, false, item.ordinal);
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/vs/editor/contrib/inlayHints/browser/inlayHintsHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
itemTooltip = part.item.hint.tooltip;
}
if (itemTooltip) {
executor.emitOne(new MarkdownHover(this, anchor.range, [itemTooltip], 0));
executor.emitOne(new MarkdownHover(this, anchor.range, [itemTooltip], false, 0));
}
// (1.2) Inlay dbl-click gesture
if (isNonEmptyArray(part.item.hint.textEdits)) {
executor.emitOne(new MarkdownHover(this, anchor.range, [new MarkdownString().appendText(localize('hint.dbl', "Double click to insert"))], 10001));
executor.emitOne(new MarkdownHover(this, anchor.range, [new MarkdownString().appendText(localize('hint.dbl', "Double click to insert"))], false, 10001));
}

// (2) Inlay Label Part Tooltip
Expand All @@ -107,7 +107,7 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
partTooltip = part.part.tooltip;
}
if (partTooltip) {
executor.emitOne(new MarkdownHover(this, anchor.range, [partTooltip], 1));
executor.emitOne(new MarkdownHover(this, anchor.range, [partTooltip], false, 1));
}

// (2.2) Inlay Label Part Help Hover
Expand All @@ -130,7 +130,7 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
linkHint = new MarkdownString(`[${localize('hint.cmd', "Execute Command")}](${asCommandLink(part.part.command)} "${part.part.command.title}") (${kb})`, { isTrusted: true });
}
if (linkHint) {
executor.emitOne(new MarkdownHover(this, anchor.range, [linkHint], 10000));
executor.emitOne(new MarkdownHover(this, anchor.range, [linkHint], false, 10000));
}
}

Expand All @@ -156,7 +156,7 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
}
return getHover(this._languageFeaturesService.hoverProvider, 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, 2 + item.ordinal));
.map(item => new MarkdownHover(this, part.item.anchor.range, item.hover.contents, false, 2 + item.ordinal));
} finally {
ref.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export class UnicodeHighlighterHoverParticipant implements IEditorHoverParticipa
.appendMarkdown(reason)
.appendText(' ')
.appendLink(uri, adjustSettings);
result.push(new MarkdownHover(this, d.range, [markdown], index++));
result.push(new MarkdownHover(this, d.range, [markdown], false, index++));
}
return result;
}
Expand Down

0 comments on commit 3c9903f

Please sign in to comment.