src/vs/base/common/observableInternal/debugName.ts
148 LOC · 130 covered · 18 uncovered · 33 ranges · 6771 concepts · 5 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.
/*---------------------------------------------------------------------------------------------
devToolsLogger.ts ×24
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export interface IDebugNameData {
/**
* The owner object of an observable.
* Used for debugging only, such as computing a name for the observable by iterating over the fields of the owner.
*/
readonly owner?: DebugOwner | undefined;
/**
* A string or function that returns a string that represents the name of the observable.
* Used for debugging only.
*/
readonly debugName?: DebugNameSource | undefined;
/**
* A function that points to the defining function of the object.
* Used for debugging only.
*/
readonly debugReferenceFn?: Function | undefined;
}
export class DebugNameData {
constructor(
public readonly debugNameSource: DebugNameSource | undefined,
public readonly referenceFn: Function | undefined,
) { }
public getDebugName(target: object): string | undefined {
}
/**
* The owning object of an observable.
* Is only used for debugging purposes, such as computing a name for the observable by iterating over the fields of the owner.
*/
export type DebugOwner = object | undefined;
export type DebugNameSource = string | (() => string | undefined);
const countPerName = new Map<string, number>();
const cachedDebugName = new WeakMap<object, string>();
export function getDebugName(target: object, data: DebugNameData): string | undefined {
if (cached) {
}
const dbgName = computeDebugName(target, data);
if (dbgName) {
count++;
countPerName.set(dbgName, count);
const result = count === 1 ? dbgName : `${dbgName}#${count}`;
cachedDebugName.set(target, result);
return result;
}
}
function computeDebugName(self: object, data: DebugNameData): string | undefined {
debugName.ts ×9
const cached = cachedDebugName.get(self);
if (cached) {
return cached;
}
const ownerStr = data.owner ? formatOwner(data.owner) + `.` : '';
let result: string | undefined;
const debugNameSource = data.debugNameSource;
if (debugNameSource !== undefined) {
result = debugNameSource();
if (result !== undefined) {
return ownerStr + result;
}
return ownerStr + debugNameSource;
}
}
const referenceFn = data.referenceFn;
if (referenceFn !== undefined) {
if (result !== undefined) {
return ownerStr + result;
}
if (data.owner !== undefined) {
if (key !== undefined) {
return ownerStr + key;
}
}
for (const key in obj) {
if ((obj as Record<string, unknown>)[key] === value) {
return key;
}
return undefined;
}
const countPerClassName = new Map<string, number>();
const ownerId = new WeakMap<object, string>();
const id = ownerId.get(owner);
if (id) {
return id;
}
let count = countPerClassName.get(className) ?? 0;
count++;
countPerClassName.set(className, count);
const result = count === 1 ? className : `${className}#${count}`;
ownerId.set(owner, result);
return result;
}
export function getClassName(obj: object): string | undefined {
if (ctor) {
if (ctor.name === 'Object') {
return undefined;
}
}
return undefined;
}
export function getFunctionName(fn: Function): string | undefined {
// Pattern: /** @description ... */
const regexp = /\/\*\*\s*@description\s*([^*]*)\*\//;
const match = regexp.exec(fnSrc);
const result = match ? match[1] : undefined;
return result?.trim();
}