UNPKG

6.19 kBTypeScriptView Raw
1import { JSONValue } from '@phosphor/coreutils';
2import URI from '../../common/uri';
3import { Disposable, DisposableCollection, Emitter, Event } from '../../common';
4import { Deferred } from '../../common/promise-util';
5import { PreferenceScope } from './preference-scope';
6import { PreferenceLanguageOverrideService } from './preference-language-override-service';
7export interface PreferenceProviderDataChange {
8 /**
9 * The name of the changed preference.
10 */
11 readonly preferenceName: string;
12 /**
13 * The new value of the changed preference.
14 */
15 readonly newValue?: any;
16 /**
17 * The old value of the changed preference.
18 */
19 readonly oldValue?: any;
20 /**
21 * The {@link PreferenceScope} of the changed preference.
22 */
23 readonly scope: PreferenceScope;
24 /**
25 * URIs of the scopes in which this change applies.
26 */
27 readonly domain?: string[];
28}
29export declare namespace PreferenceProviderDataChange {
30 function affects(change: PreferenceProviderDataChange, resourceUri?: string): boolean;
31}
32export interface PreferenceProviderDataChanges {
33 [preferenceName: string]: PreferenceProviderDataChange;
34}
35export interface PreferenceResolveResult<T> {
36 configUri?: URI;
37 value?: T;
38}
39/**
40 * The {@link PreferenceProvider} is used to store and retrieve preference values. A {@link PreferenceProvider} does not operate in a global scope but is
41 * configured for one or more {@link PreferenceScope}s. The (default implementation for the) {@link PreferenceService} aggregates all {@link PreferenceProvider}s and
42 * serves as a common facade for manipulating preference values.
43 */
44export declare abstract class PreferenceProvider implements Disposable {
45 protected readonly preferenceOverrideService: PreferenceLanguageOverrideService;
46 protected readonly onDidPreferencesChangedEmitter: Emitter<PreferenceProviderDataChanges>;
47 readonly onDidPreferencesChanged: Event<PreferenceProviderDataChanges>;
48 protected readonly toDispose: DisposableCollection;
49 protected readonly _ready: Deferred<void>;
50 constructor();
51 dispose(): void;
52 protected deferredChanges: PreferenceProviderDataChanges | undefined;
53 /**
54 * Informs the listeners that one or more preferences of this provider are changed.
55 * The listeners are able to find what was changed from the emitted event.
56 */
57 protected emitPreferencesChangedEvent(changes: PreferenceProviderDataChanges | PreferenceProviderDataChange[]): Promise<boolean>;
58 protected mergePreferenceProviderDataChange(change: PreferenceProviderDataChange): void;
59 protected fireDidPreferencesChanged: () => Promise<boolean>;
60 /**
61 * Retrieve the stored value for the given preference and resource URI.
62 *
63 * @param preferenceName the preference identifier.
64 * @param resourceUri the uri of the resource for which the preference is stored. This is used to retrieve
65 * a potentially different value for the same preference for different resources, for example `files.encoding`.
66 *
67 * @returns the value stored for the given preference and resourceUri if it exists, otherwise `undefined`.
68 */
69 get<T>(preferenceName: string, resourceUri?: string): T | undefined;
70 /**
71 * Resolve the value for the given preference and resource URI.
72 *
73 * @param preferenceName the preference identifier.
74 * @param resourceUri the URI of the resource for which this provider should resolve the preference. This is used to retrieve
75 * a potentially different value for the same preference for different resources, for example `files.encoding`.
76 *
77 * @returns an object containing the value stored for the given preference and resourceUri if it exists,
78 * otherwise `undefined`.
79 */
80 resolve<T>(preferenceName: string, resourceUri?: string): PreferenceResolveResult<T>;
81 abstract getPreferences(resourceUri?: string): {
82 [p: string]: any;
83 };
84 /**
85 * Stores a new value for the given preference key in the provider.
86 * @param key the preference key (typically the name).
87 * @param value the new preference value.
88 * @param resourceUri the URI of the resource for which the preference is stored.
89 *
90 * @returns a promise that only resolves if all changes were delivered.
91 * If changes were made then implementation must either
92 * await on `this.emitPreferencesChangedEvent(...)` or
93 * `this.pendingChanges` if changes are fired indirectly.
94 */
95 abstract setPreference(key: string, value: any, resourceUri?: string): Promise<boolean>;
96 /**
97 * Resolved when the preference provider is ready to provide preferences
98 * It should be resolved by subclasses.
99 */
100 get ready(): Promise<void>;
101 /**
102 * Retrieve the domain for this provider.
103 *
104 * @returns the domain or `undefined` if this provider is suitable for all domains.
105 */
106 getDomain(): string[] | undefined;
107 /**
108 * Retrieve the configuration URI for the given resource URI.
109 * @param resourceUri the uri of the resource or `undefined`.
110 * @param sectionName the section to return the URI for, e.g. `tasks` or `launch`. Defaults to settings.
111 *
112 * @returns the corresponding resource URI or `undefined` if there is no valid URI.
113 */
114 getConfigUri(resourceUri?: string, sectionName?: string): URI | undefined;
115 /**
116 * Retrieves the first valid configuration URI contained by the given resource.
117 * @param resourceUri the uri of the container resource or `undefined`.
118 *
119 * @returns the first valid configuration URI contained by the given resource `undefined`
120 * if there is no valid configuration URI at all.
121 */
122 getContainingConfigUri?(resourceUri?: string, sectionName?: string): URI | undefined;
123 static merge(source: JSONValue | undefined, target: JSONValue): JSONValue;
124 /**
125 * Handles deep equality with the possibility of `undefined`
126 */
127 static deepEqual(a: JSONValue | undefined, b: JSONValue | undefined): boolean;
128 protected getParsedContent(jsonData: any): {
129 [key: string]: any;
130 };
131}
132//# sourceMappingURL=preference-provider.d.ts.map
\No newline at end of file