Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/hover/browser/glyphHoverComputer.ts
4779 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { asArray } from '../../../../base/common/arrays.js';
7
import { IMarkdownString, isEmptyMarkdownString } from '../../../../base/common/htmlContent.js';
8
import { ICodeEditor } from '../../../browser/editorBrowser.js';
9
import { IHoverComputer } from './hoverOperation.js';
10
import { GlyphMarginLane } from '../../../common/model.js';
11
12
export type LaneOrLineNumber = GlyphMarginLane | 'lineNo';
13
14
export interface IHoverMessage {
15
value: IMarkdownString;
16
}
17
18
export interface GlyphHoverComputerOptions {
19
lineNumber: number;
20
laneOrLine: LaneOrLineNumber;
21
}
22
23
export class GlyphHoverComputer implements IHoverComputer<GlyphHoverComputerOptions, IHoverMessage> {
24
25
constructor(
26
private readonly _editor: ICodeEditor
27
) {
28
}
29
30
public computeSync(opts: GlyphHoverComputerOptions): IHoverMessage[] {
31
32
const toHoverMessage = (contents: IMarkdownString): IHoverMessage => {
33
return {
34
value: contents
35
};
36
};
37
38
const lineDecorations = this._editor.getLineDecorations(opts.lineNumber);
39
40
const result: IHoverMessage[] = [];
41
const isLineHover = opts.laneOrLine === 'lineNo';
42
if (!lineDecorations) {
43
return result;
44
}
45
46
for (const d of lineDecorations) {
47
const lane = d.options.glyphMargin?.position ?? GlyphMarginLane.Center;
48
if (!isLineHover && lane !== opts.laneOrLine) {
49
continue;
50
}
51
52
const hoverMessage = isLineHover ? d.options.lineNumberHoverMessage : d.options.glyphMarginHoverMessage;
53
if (!hoverMessage || isEmptyMarkdownString(hoverMessage)) {
54
continue;
55
}
56
57
result.push(...asArray(hoverMessage).map(toHoverMessage));
58
}
59
60
return result;
61
}
62
}
63
64