enablement.ts ×17

Frontier kind: Code frontier

unlabeled · c_5fdc082973f0

418 tests · 21733 LOC · 120 files · introduces 0 tests · 71 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges71 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2409 ranges21733 lines · 120 files · Browse complete extent
All tests (intent)
418 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 71 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/enablement.ts 71 introduced LOC · 17 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- enablement.ts
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 { Disposable } from '../../../../base/common/lifecycle.js';
7 > import { IObservable, IReader, ITransaction, transaction } from '../../../../base/common/observable.js';
8 > import { ObservableMemento, observableMemento } from '../../../../platform/observable/common/observableMemento.js';
9 > import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
10 >
11 > export const enum ContributionEnablementState {
12 > DisabledProfile,
13 > DisabledWorkspace,
14 > EnabledProfile,
15 > EnabledWorkspace,
16 > }
17 >
18 > export function isContributionEnabled(state: ContributionEnablementState): boolean {
19 return state === ContributionEnablementState.EnabledProfile || state === ContributionEnablementState.EnabledWorkspace;
20 }
22 > export function isContributionDisabled(state: ContributionEnablementState): boolean {
23 return !isContributionEnabled(state);
24 }
26 > export interface IEnablementModel {
27 > readEnabled(key: string, reader?: IReader): ContributionEnablementState;
28 > setEnabled(key: string, state: ContributionEnablementState, tx?: ITransaction): void;
29 > remove(key: string): void;
30 > }
31 >
32 > type EnablementMap = ReadonlyMap<string, boolean>;
33 >
34 function mapToStorage(value: EnablementMap): string {
35 return JSON.stringify([...value]);
36 }
38 function mapFromStorage(value: string): EnablementMap {
39 const parsed = JSON.parse(value);
40 return new Map(Array.isArray(parsed) ? parsed : []);
41 }
43 > /**
44 > * A reusable enablement model for string-keyed contributions. Uses
45 > * `observableMemento` to persist enable/disable state in both profile-scoped
46 > * and workspace-scoped storage.
47 > *
48 > * Resolution order: if a workspace-scoped entry exists for a key, it wins.
49 > * Otherwise, the profile-scoped entry is used. The default (absence of any
50 > * entry) is {@link ContributionEnablementState.EnabledProfile}.
51 > */
52 > export class EnablementModel extends Disposable implements IEnablementModel {
53 > private readonly _profileState: ObservableMemento<EnablementMap>;
54 > private readonly _workspaceState: ObservableMemento<EnablementMap>;
55 >
56 > constructor(
57 storageKey: string,
58 @IStorageService storageService: IStorageService,
75 );
76 }
78 > readEnabled(key: string, reader?: IReader): ContributionEnablementState {
79 return this.readEnabledWithWorkspaceKey(key, key, reader);
80 }
82 > readEnabledWithWorkspaceKey(profileKey: string, workspaceKey: string | undefined, reader?: IReader): ContributionEnablementState {
83 const wsMap = this._workspaceState.read(reader);
84 if (workspaceKey !== undefined && wsMap.has(workspaceKey)) {
97 return ContributionEnablementState.EnabledProfile;
98 }
100 > setEnabled(key: string, state: ContributionEnablementState, tx?: ITransaction): void {
101 this.setEnabledWithWorkspaceKey(key, key, state, tx);
102 }
104 > setEnabledWithWorkspaceKey(profileKey: string, workspaceKey: string | undefined, state: ContributionEnablementState, tx?: ITransaction): void {
105 switch (state) {
106 case ContributionEnablementState.EnabledProfile: {
140
141 }
143 > remove(key: string): void {
144 this._deleteFromMap(this._profileState, key);
145 this._deleteFromMap(this._workspaceState, key);
146 }
148 > private _setInMap(memento: ObservableMemento<EnablementMap>, key: string, value: boolean, tx?: ITransaction): void {
149 const current = memento.get();
150 if (current.get(key) === value) {
155 memento.set(next, tx);
156 }
158 > private _deleteFromMap(memento: ObservableMemento<EnablementMap>, key: string, tx?: ITransaction): void {
159 const current = memento.get();
160 if (!current.has(key)) {
165 memento.set(next, tx);
166 }
167 > } enablement.ts
168 >
169 > export class CollisionEnablementModel implements IEnablementModel {
170 >
171 > constructor(
172 private readonly _base: IEnablementModel,
173 private readonly _collisionGroups: IObservable<ReadonlyMap<string, readonly string[]>>,
174 ) { }
176 > readEnabled(key: string, reader?: IReader): ContributionEnablementState {
177 const baseState = this._base.readEnabled(key, reader);
178
196 return baseState;
197 }
199 > setEnabled(key: string, state: ContributionEnablementState, tx?: ITransaction): void {
200 const isEnabling = state === ContributionEnablementState.EnabledProfile || state === ContributionEnablementState.EnabledWorkspace;
201 const group = isEnabling ? this._collisionGroups.get().get(key) : undefined;