File size: 1,308 Bytes
4e23b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { CascadeEngine } from '#/_base/di/cascadeEngine';
import type { InstantiationService } from '#/_base/di/instantiationService';

export interface ScopeContainerInfo {
  readonly container: InstantiationService;
  readonly path: string;
  readonly label: string;
}

export function scopeContainerLabel(container: InstantiationService): string {
  return container.debugLabel ?? `#${container.cascadeTree.seqOf(container)}`;
}

export function walkScopeContainers(root: InstantiationService): ScopeContainerInfo[] {
  const out: ScopeContainerInfo[] = [];
  const visit = (container: InstantiationService, path: string): void => {
    out.push({ container, path, label: scopeContainerLabel(container) });
    for (const child of container.children) {
      visit(child, `${path}/${scopeContainerLabel(child)}`);
    }
  };
  visit(root, scopeContainerLabel(root));
  return out;
}

export function resolveScopeContainer(
  root: InstantiationService,
  path: string,
): InstantiationService | undefined {
  return walkScopeContainers(root).find((info) => info.path === path)?.container;
}

export function scopePathOfEngine(
  root: InstantiationService,
  engine: CascadeEngine,
): string | undefined {
  return walkScopeContainers(root).find((info) => info.container.cascade === engine)?.path;
}