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 { Emitter, Event } from '../../../../base/common/event.js';
7
>
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
8
>
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
9
>
import type { IAssignmentFilter } from './assignmentService.js';
10
>
11
>
/**
12
>
* Applies the registered {@link IAssignmentFilter assignment filters} to the assignment context
13
>
* and remembers, per filter, which assignment-context ids each filter excluded.
14
>
*
15
>
* The excluded ids are persisted so that they stay filtered out across reloads even before the
16
>
* owning filter has been registered again. Once a filter is registered it becomes authoritative
17
>
* for its own id: the persisted state is repopulated from the ids it currently excludes and any
18
>
* id that is no longer excluded is dropped from storage.
19
>
*/
20
>
export class AssignmentContextFilter extends Disposable {
21
>
22
>
private static readonly STORAGE_KEY = 'workbench.assignment.filteredOutAssignmentContextIds';
23
>
24
>
private readonly _filters: IAssignmentFilter[] = [];
25
>
private readonly _filterDisposables = this._register(new DisposableStore());
26
>
27
>
/**
28
>
* Assignment-context ids that were filtered out, keyed by the id of the filter that
29
>
* excluded them. Entries owned by a filter that has not been registered yet are honored
30
>
* across reloads so those ids stay excluded until the filter takes over.
31
>
*/
32
>
private _cachedFilteredOutIds: Map<string, Set<string>>;
33
>
34
>
/**
35
>
* Ids of filters that have been registered this session. Once a filter is registered it
36
>
* becomes authoritative for its own id and the persisted cache is repopulated from the
37
>
* ids it actually excludes.
38
>
*/
39
>
private readonly _registeredFilterIds = new Set<string>();
40
>
41
>
private readonly _onDidChange = this._register(new Emitter<void>());
42
>
/** Fires when a filter is added or an already registered filter changes its exclusions. */
43
>
readonly onDidChange: Event<void> = this._onDidChange.event;
44
>
45
>
constructor(
46
private readonly storageService: IStorageService
47
) {