Skip to content

Commit 797fb52

Browse files
Test
1 parent 59b4df0 commit 797fb52

File tree

9 files changed

+53
-11
lines changed

9 files changed

+53
-11
lines changed

src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ class Widget {
431431
firstLineMinLeft = visibleRange.left;
432432
}
433433
}
434+
if (this._affinity === PositionAffinity.LeftOfInjectedText &&
435+
this._viewRange.startColumn === 1) {
436+
firstLineMinLeft = 0;
437+
}
434438

435439
let lastLineMinLeft = Constants.MAX_SAFE_SMALL_INTEGER;//lastLine.Constants.MAX_SAFE_SMALL_INTEGER;
436440
for (const visibleRange of lastLine.ranges) {

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,14 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
13591359
const opts = this._resolveDecorationOptions(typeKey, !!decorationOption.hoverMessage);
13601360
if (decorationOption.hoverMessage) {
13611361
opts.hoverMessage = decorationOption.hoverMessage;
1362+
1363+
if (decorationOption.renderOptions?.before ||
1364+
decorationOption.renderOptions?.dark?.before ||
1365+
decorationOption.renderOptions?.light?.before) {
1366+
opts.hoverMessageBefore = true;
1367+
}
13621368
}
1369+
13631370
newModelDecorations.push({ range: decorationOption.range, options: opts });
13641371
}
13651372

src/vs/editor/common/model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export interface IModelDecorationOptions {
100100
* Array of MarkdownString to render as the decoration message.
101101
*/
102102
hoverMessage?: IMarkdownString | IMarkdownString[] | null;
103+
/**
104+
* If true, hover message will be left-aligned to the beforecontent on the line
105+
*/
106+
hoverMessageBefore?: boolean | null;
103107
/**
104108
* Should the decoration expand to encompass a whole line.
105109
*/

src/vs/editor/contrib/hover/browser/contentHover.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ContentWidgetPositionPreference, IActiveCodeEditor, ICodeEditor, IConte
1313
import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions';
1414
import { Position } from 'vs/editor/common/core/position';
1515
import { Range } from 'vs/editor/common/core/range';
16-
import { IModelDecoration } from 'vs/editor/common/model';
16+
import { IModelDecoration, PositionAffinity } from 'vs/editor/common/model';
1717
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
1818
import { TokenizationRegistry } from 'vs/editor/common/languages';
1919
import { HoverOperation, HoverStartMode, IHoverComputer } from 'vs/editor/contrib/hover/browser/hoverOperation';
@@ -139,6 +139,8 @@ export class ContentHoverController extends Disposable {
139139

140140
this._hoverOperation.cancel();
141141

142+
// console.log(`--- HOVER CHANGE s-line: ${anchor.range.startLineNumber} s-col: ${anchor.range.startColumn} e-line: ${anchor.range.endLineNumber} e-col: ${anchor.range.endColumn}`);
143+
142144
if (this._widget.position) {
143145
// The range might have changed, but the hover is visible
144146
// Instead of hiding it completely, filter out messages that are still in the new range and
@@ -224,6 +226,9 @@ export class ContentHoverController extends Disposable {
224226
disposables.add(participant.renderHoverParts(context, hoverParts));
225227
}
226228
}
229+
230+
const isBefore = messages.some(m => m.isBeforeContent);
231+
227232
if (statusBar.hasContent) {
228233
fragment.appendChild(statusBar.hoverElement);
229234
}
@@ -256,6 +261,7 @@ export class ContentHoverController extends Disposable {
256261
showAtRange,
257262
this._editor.getOption(EditorOption.hover).above,
258263
this._computer.shouldFocus,
264+
isBefore,
259265
disposables
260266
));
261267
} else {
@@ -303,6 +309,7 @@ class ContentHoverVisibleData {
303309
public readonly showAtRange: Range,
304310
public readonly preferAbove: boolean,
305311
public readonly stoleFocus: boolean,
312+
public readonly isBefore: boolean,
306313
public readonly disposables: DisposableStore
307314
) { }
308315
}
@@ -372,6 +379,9 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {
372379
// Prefer rendering above if the suggest widget is visible
373380
preferAbove = true;
374381
}
382+
383+
const affinity = this._visibleData.isBefore ? PositionAffinity.LeftOfInjectedText : undefined;
384+
375385
return {
376386
position: this._visibleData.showAtPosition,
377387
range: this._visibleData.showAtRange,
@@ -380,6 +390,7 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {
380390
? [ContentWidgetPositionPreference.ABOVE, ContentWidgetPositionPreference.BELOW]
381391
: [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE]
382392
),
393+
positionAffinity: affinity
383394
};
384395
}
385396

src/vs/editor/contrib/hover/browser/hoverTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface IHoverPart {
2626
* even in the case of multiple hover parts.
2727
*/
2828
readonly forceShowAtRange?: boolean;
29+
30+
readonly isBeforeContent?: boolean;
2931
/**
3032
* Is this hover part still valid for this new anchor?
3133
*/

src/vs/editor/contrib/hover/browser/markdownHoverParticipant.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class MarkdownHover implements IHoverPart {
3030
public readonly owner: IEditorHoverParticipant<MarkdownHover>,
3131
public readonly range: Range,
3232
public readonly contents: IMarkdownString[],
33+
public readonly isBeforeContent: boolean,
3334
public readonly ordinal: number
3435
) { }
3536

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

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

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

85+
let isBeforeContent = false;
86+
8487
for (const d of lineDecorations) {
8588
const startColumn = (d.range.startLineNumber === lineNumber) ? d.range.startColumn : 1;
8689
const endColumn = (d.range.endLineNumber === lineNumber) ? d.range.endColumn : maxColumn;
@@ -90,8 +93,15 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
9093
continue;
9194
}
9295

96+
// if (d.options.hoverMessageBefore) {
97+
// isBeforeContent = true;
98+
// }
99+
if (d.options.beforeContentClassName) {
100+
isBeforeContent = true;
101+
}
102+
93103
const range = new Range(anchor.range.startLineNumber, startColumn, anchor.range.startLineNumber, endColumn);
94-
result.push(new MarkdownHover(this, range, asArray(hoverMessage), index++));
104+
result.push(new MarkdownHover(this, range, asArray(hoverMessage), isBeforeContent, index++));
95105
}
96106

97107
return result;
@@ -113,7 +123,7 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
113123
.filter(item => !isEmptyMarkdownString(item.hover.contents))
114124
.map(item => {
115125
const rng = item.hover.range ? Range.lift(item.hover.range) : anchor.range;
116-
return new MarkdownHover(this, rng, item.hover.contents, item.ordinal);
126+
return new MarkdownHover(this, rng, item.hover.contents, false, item.ordinal);
117127
});
118128
}
119129

src/vs/editor/contrib/inlayHints/browser/inlayHintsHover.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
8787
itemTooltip = part.item.hint.tooltip;
8888
}
8989
if (itemTooltip) {
90-
executor.emitOne(new MarkdownHover(this, anchor.range, [itemTooltip], 0));
90+
executor.emitOne(new MarkdownHover(this, anchor.range, [itemTooltip], false, 0));
9191
}
9292
// (1.2) Inlay dbl-click gesture
9393
if (isNonEmptyArray(part.item.hint.textEdits)) {
94-
executor.emitOne(new MarkdownHover(this, anchor.range, [new MarkdownString().appendText(localize('hint.dbl', "Double click to insert"))], 10001));
94+
executor.emitOne(new MarkdownHover(this, anchor.range, [new MarkdownString().appendText(localize('hint.dbl', "Double click to insert"))], false, 10001));
9595
}
9696

9797
// (2) Inlay Label Part Tooltip
@@ -102,7 +102,7 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
102102
partTooltip = part.part.tooltip;
103103
}
104104
if (partTooltip) {
105-
executor.emitOne(new MarkdownHover(this, anchor.range, [partTooltip], 1));
105+
executor.emitOne(new MarkdownHover(this, anchor.range, [partTooltip], false, 1));
106106
}
107107

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

@@ -151,7 +151,7 @@ export class InlayHintsHover extends MarkdownHoverParticipant implements IEditor
151151
}
152152
return getHover(this._languageFeaturesService.hoverProvider, model, new Position(range.startLineNumber, range.startColumn), token)
153153
.filter(item => !isEmptyMarkdownString(item.hover.contents))
154-
.map(item => new MarkdownHover(this, part.item.anchor.range, item.hover.contents, 2 + item.ordinal));
154+
.map(item => new MarkdownHover(this, part.item.anchor.range, item.hover.contents, false, 2 + item.ordinal));
155155
} finally {
156156
ref.dispose();
157157
}

src/vs/editor/contrib/unicodeHighlighter/browser/unicodeHighlighter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ export class UnicodeHighlighterHoverParticipant implements IEditorHoverParticipa
483483
.appendMarkdown(reason)
484484
.appendText(' ')
485485
.appendLink(uri, adjustSettings);
486-
result.push(new MarkdownHover(this, d.range, [markdown], index++));
486+
result.push(new MarkdownHover(this, d.range, [markdown], false, index++));
487487
}
488488
return result;
489489
}

src/vs/monaco.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,10 @@ declare namespace monaco.editor {
14961496
* Array of MarkdownString to render as the decoration message.
14971497
*/
14981498
hoverMessage?: IMarkdownString | IMarkdownString[] | null;
1499+
/**
1500+
* If true, hover message will be left-aligned to the beforecontent on the line
1501+
*/
1502+
hoverMessageBefore?: boolean | null;
14991503
/**
15001504
* Should the decoration expand to encompass a whole line.
15011505
*/

0 commit comments

Comments
 (0)