Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/notebook/browser/viewModel/OutlineEntry.ts
3296 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
import { Codicon } from '../../../../../base/common/codicons.js';
6
import { ThemeIcon } from '../../../../../base/common/themables.js';
7
import { IMarkerService, MarkerSeverity } from '../../../../../platform/markers/common/markers.js';
8
import { ICellViewModel } from '../notebookBrowser.js';
9
import { executingStateIcon } from '../notebookIcons.js';
10
import { CellKind } from '../../common/notebookCommon.js';
11
import { IRange } from '../../../../../editor/common/core/range.js';
12
import { SymbolKind, SymbolKinds } from '../../../../../editor/common/languages.js';
13
14
export interface IOutlineMarkerInfo {
15
readonly count: number;
16
readonly topSev: MarkerSeverity;
17
}
18
19
export class OutlineEntry {
20
private _children: OutlineEntry[] = [];
21
private _parent: OutlineEntry | undefined;
22
private _markerInfo: IOutlineMarkerInfo | undefined;
23
24
get icon(): ThemeIcon {
25
if (this.symbolKind) {
26
return SymbolKinds.toIcon(this.symbolKind);
27
}
28
return this.isExecuting && this.isPaused ? executingStateIcon :
29
this.isExecuting ? ThemeIcon.modify(executingStateIcon, 'spin') :
30
this.cell.cellKind === CellKind.Markup ? Codicon.markdown : Codicon.code;
31
}
32
33
constructor(
34
readonly index: number,
35
readonly level: number,
36
readonly cell: ICellViewModel,
37
readonly label: string,
38
readonly isExecuting: boolean,
39
readonly isPaused: boolean,
40
readonly range?: IRange,
41
readonly symbolKind?: SymbolKind,
42
) { }
43
44
addChild(entry: OutlineEntry) {
45
this._children.push(entry);
46
entry._parent = this;
47
}
48
49
get parent(): OutlineEntry | undefined {
50
return this._parent;
51
}
52
53
get children(): Iterable<OutlineEntry> {
54
return this._children;
55
}
56
57
get markerInfo(): IOutlineMarkerInfo | undefined {
58
return this._markerInfo;
59
}
60
61
get position() {
62
if (this.range) {
63
return { startLineNumber: this.range.startLineNumber, startColumn: this.range.startColumn };
64
}
65
return undefined;
66
}
67
68
updateMarkers(markerService: IMarkerService): void {
69
if (this.cell.cellKind === CellKind.Code) {
70
// a code cell can have marker
71
const marker = markerService.read({ resource: this.cell.uri, severities: MarkerSeverity.Error | MarkerSeverity.Warning });
72
if (marker.length === 0) {
73
this._markerInfo = undefined;
74
} else {
75
const topSev = marker.find(a => a.severity === MarkerSeverity.Error)?.severity ?? MarkerSeverity.Warning;
76
this._markerInfo = { topSev, count: marker.length };
77
}
78
} else {
79
// a markdown cell can inherit markers from its children
80
let topChild: MarkerSeverity | undefined;
81
for (const child of this.children) {
82
child.updateMarkers(markerService);
83
if (child.markerInfo) {
84
topChild = !topChild ? child.markerInfo.topSev : Math.max(child.markerInfo.topSev, topChild);
85
}
86
}
87
this._markerInfo = topChild && { topSev: topChild, count: 0 };
88
}
89
}
90
91
clearMarkers(): void {
92
this._markerInfo = undefined;
93
for (const child of this.children) {
94
child.clearMarkers();
95
}
96
}
97
98
find(cell: ICellViewModel, parents: OutlineEntry[]): OutlineEntry | undefined {
99
if (cell.id === this.cell.id) {
100
return this;
101
}
102
parents.push(this);
103
for (const child of this.children) {
104
const result = child.find(cell, parents);
105
if (result) {
106
return result;
107
}
108
}
109
parents.pop();
110
return undefined;
111
}
112
113
asFlatList(bucket: OutlineEntry[]): void {
114
bucket.push(this);
115
for (const child of this.children) {
116
child.asFlatList(bucket);
117
}
118
}
119
}
120
121