src/vs/base/common/observableInternal/logging/debugGetDependencyGraph.ts

159 LOC · 120 covered · 39 uncovered · 15 ranges · 6771 concepts · 3 introducers · 3467 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- devToolsLogger.ts ×24
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 { IObservable, IObserver } from '../base.js';
7 > import { Derived } from '../observables/derivedImpl.js';
8 > import { FromEventObservable } from '../observables/observableFromEvent.js';
9 > import { ObservableValue } from '../observables/observableValue.js';
10 > import { AutorunObserver } from '../reactions/autorunImpl.js';
11 > import { formatValue } from './consoleObservableLogger.js';
12 >
13 > interface IOptions {
14 > type: 'dependencies' | 'observers';
15 > debugNamePostProcessor?: (name: string) => string;
16 > }
17 >
18 > export function debugGetObservableGraph(obs: IObservable<any> | IObserver, options: IOptions): string {
19 > const debugNamePostProcessor = options?.debugNamePostProcessor ?? ((str: string) => str); consoleObservableLogger.ts ×8
20 > const info = Info.from(obs, debugNamePostProcessor);
21 > if (!info) {
22 return '';
23 }
25 > const alreadyListed = new Set<IObservable<any> | IObserver>();
26 >
27 > if (options.type === 'observers') {
28 return formatObservableInfoWithObservers(info, 0, alreadyListed, options).trim();
30 > return formatObservableInfoWithDependencies(info, 0, alreadyListed, options).trim();
31 > }
32 > }
34 > function formatObservableInfoWithDependencies(info: Info, indentLevel: number, alreadyListed: Set<IObservable<any> | IObserver>, options: IOptions): string { consoleObservableLogger.ts ×8
35 > const indent = '\t\t'.repeat(indentLevel);
36 > const lines: string[] = [];
37 >
38 > const isAlreadyListed = alreadyListed.has(info.sourceObj);
39 > if (isAlreadyListed) {
40 > lines.push(`${indent}* ${info.type} ${info.name} (already listed)`);
41 > return lines.join('\n');
42 > }
43 >
44 > alreadyListed.add(info.sourceObj);
45 >
46 > lines.push(`${indent}* ${info.type} ${info.name}:`);
47 > lines.push(`${indent} value: ${formatValue(info.value, 50)}`);
48 > lines.push(`${indent} state: ${info.state}`);
49 >
50 > if (info.dependencies.length > 0) {
51 > lines.push(`${indent} dependencies:`);
52 > for (const dep of info.dependencies) {
53 > const info = Info.from(dep, options.debugNamePostProcessor ?? (name => name)) ?? Info.unknown(dep);
54 > lines.push(formatObservableInfoWithDependencies(info, indentLevel + 1, alreadyListed, options));
55 > }
56 > }
57 >
58 > return lines.join('\n');
59 > }
61 function formatObservableInfoWithObservers(info: Info, indentLevel: number, alreadyListed: Set<IObservable<any> | IObserver>, options: IOptions): string {
62 const indent = '\t\t'.repeat(indentLevel);
63 const lines: string[] = [];
64
65 const isAlreadyListed = alreadyListed.has(info.sourceObj);
66 if (isAlreadyListed) {
67 lines.push(`${indent}* ${info.type} ${info.name} (already listed)`);
68 return lines.join('\n');
69 }
70
71 alreadyListed.add(info.sourceObj);
72
73 lines.push(`${indent}* ${info.type} ${info.name}:`);
74 lines.push(`${indent} value: ${formatValue(info.value, 50)}`);
75 lines.push(`${indent} state: ${info.state}`);
76
77 if (info.observers.length > 0) {
78 lines.push(`${indent} observers:`);
79 for (const observer of info.observers) {
80 const info = Info.from(observer, options.debugNamePostProcessor ?? (name => name)) ?? Info.unknown(observer);
81 lines.push(formatObservableInfoWithObservers(info, indentLevel + 1, alreadyListed, options));
82 }
83 }
84
85 return lines.join('\n');
86 }
88 > class Info {
89 > public static from(obs: IObservable<any> | IObserver, debugNamePostProcessor: (name: string) => string): Info | undefined {
90 > if (obs instanceof AutorunObserver) {
91 > const state = obs.debugGetState(); debugGetDependencyGraph.ts ×2
92 > return new Info(
93 > obs,
94 > debugNamePostProcessor(obs.debugName),
95 > 'autorun',
96 > undefined,
97 > state.stateStr,
98 > Array.from(state.dependencies),
99 > []
100 > );
101 > } else if (obs instanceof Derived) { devToolsLogger.ts ×24
102 > const state = obs.debugGetState();
103 > return new Info(
104 > obs,
105 > debugNamePostProcessor(obs.debugName),
106 > 'derived',
107 > state.value,
108 > state.stateStr,
109 > Array.from(state.dependencies),
110 > Array.from(obs.debugGetObservers())
111 > );
112 > } else if (obs instanceof ObservableValue) {
113 > const state = obs.debugGetState();
114 > return new Info(
115 > obs,
116 > debugNamePostProcessor(obs.debugName),
117 > 'observableValue',
118 > state.value,
119 > 'upToDate',
120 > [],
121 > Array.from(obs.debugGetObservers())
122 > );
123 > } else if (obs instanceof FromEventObservable) {
124 > const state = obs.debugGetState(); debugGetDependencyGraph.ts ×2
125 > return new Info(
126 > obs,
127 > debugNamePostProcessor(obs.debugName),
128 > 'fromEvent',
129 > state.value,
130 > state.hasValue ? 'upToDate' : 'initial',
131 > [],
132 > Array.from(obs.debugGetObservers())
133 > );
134 > }
135 > return undefined;
137 >
138 > public static unknown(obs: IObservable<any> | IObserver): Info {
139 return new Info(
140 obs,
141 '(unknown)',
142 'unknown',
143 undefined,
144 'unknown',
145 [],
146 []
147 );
148 }
150 > constructor(
151 > public readonly sourceObj: IObservable<any> | IObserver, consoleObservableLogger.ts ×8
152 > public readonly name: string,
153 > public readonly type: string,
154 > public readonly value: any,
155 > public readonly state: string,
156 > public readonly dependencies: (IObservable<any> | IObserver)[],
157 > public readonly observers: (IObservable<any> | IObserver)[],
158 > ) { }