Path: blob/main/src/vs/workbench/contrib/notebook/browser/viewModel/OutlineEntry.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import { Codicon } from '../../../../../base/common/codicons.js';5import { ThemeIcon } from '../../../../../base/common/themables.js';6import { IMarkerService, MarkerSeverity } from '../../../../../platform/markers/common/markers.js';7import { ICellViewModel } from '../notebookBrowser.js';8import { executingStateIcon } from '../notebookIcons.js';9import { CellKind } from '../../common/notebookCommon.js';10import { IRange } from '../../../../../editor/common/core/range.js';11import { SymbolKind, SymbolKinds } from '../../../../../editor/common/languages.js';1213export interface IOutlineMarkerInfo {14readonly count: number;15readonly topSev: MarkerSeverity;16}1718export class OutlineEntry {19private _children: OutlineEntry[] = [];20private _parent: OutlineEntry | undefined;21private _markerInfo: IOutlineMarkerInfo | undefined;2223get icon(): ThemeIcon {24if (this.symbolKind) {25return SymbolKinds.toIcon(this.symbolKind);26}27return this.isExecuting && this.isPaused ? executingStateIcon :28this.isExecuting ? ThemeIcon.modify(executingStateIcon, 'spin') :29this.cell.cellKind === CellKind.Markup ? Codicon.markdown : Codicon.code;30}3132constructor(33readonly index: number,34readonly level: number,35readonly cell: ICellViewModel,36readonly label: string,37readonly isExecuting: boolean,38readonly isPaused: boolean,39readonly range?: IRange,40readonly symbolKind?: SymbolKind,41) { }4243addChild(entry: OutlineEntry) {44this._children.push(entry);45entry._parent = this;46}4748get parent(): OutlineEntry | undefined {49return this._parent;50}5152get children(): Iterable<OutlineEntry> {53return this._children;54}5556get markerInfo(): IOutlineMarkerInfo | undefined {57return this._markerInfo;58}5960get position() {61if (this.range) {62return { startLineNumber: this.range.startLineNumber, startColumn: this.range.startColumn };63}64return undefined;65}6667updateMarkers(markerService: IMarkerService): void {68if (this.cell.cellKind === CellKind.Code) {69// a code cell can have marker70const marker = markerService.read({ resource: this.cell.uri, severities: MarkerSeverity.Error | MarkerSeverity.Warning });71if (marker.length === 0) {72this._markerInfo = undefined;73} else {74const topSev = marker.find(a => a.severity === MarkerSeverity.Error)?.severity ?? MarkerSeverity.Warning;75this._markerInfo = { topSev, count: marker.length };76}77} else {78// a markdown cell can inherit markers from its children79let topChild: MarkerSeverity | undefined;80for (const child of this.children) {81child.updateMarkers(markerService);82if (child.markerInfo) {83topChild = !topChild ? child.markerInfo.topSev : Math.max(child.markerInfo.topSev, topChild);84}85}86this._markerInfo = topChild && { topSev: topChild, count: 0 };87}88}8990clearMarkers(): void {91this._markerInfo = undefined;92for (const child of this.children) {93child.clearMarkers();94}95}9697find(cell: ICellViewModel, parents: OutlineEntry[]): OutlineEntry | undefined {98if (cell.id === this.cell.id) {99return this;100}101parents.push(this);102for (const child of this.children) {103const result = child.find(cell, parents);104if (result) {105return result;106}107}108parents.pop();109return undefined;110}111112asFlatList(bucket: OutlineEntry[]): void {113bucket.push(this);114for (const child of this.children) {115child.asFlatList(bucket);116}117}118}119120121