1
>
/*---------------------------------------------------------------------------------------------
preferences.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 { IStringDictionary } from '../../../../base/common/collections.js';
7
>
import { Event } from '../../../../base/common/event.js';
8
>
import { IMatch } from '../../../../base/common/filters.js';
9
>
import { IJSONSchema, IJSONSchemaMap } from '../../../../base/common/jsonSchema.js';
10
>
import { ResolvedKeybinding } from '../../../../base/common/keybindings.js';
11
>
import { URI } from '../../../../base/common/uri.js';
12
>
import { IRange } from '../../../../editor/common/core/range.js';
13
>
import { IEditorContribution } from '../../../../editor/common/editorCommon.js';
14
>
import { ConfigurationTarget } from '../../../../platform/configuration/common/configuration.js';
15
>
import { ConfigurationDefaultValueSource, ConfigurationScope, EditPresentationTypes, IExtensionInfo } from '../../../../platform/configuration/common/configurationRegistry.js';
16
>
import { IEditorOptions } from '../../../../platform/editor/common/editor.js';
17
>
import { IExtensionDescription } from '../../../../platform/extensions/common/extensions.js';
18
>
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
19
>
import { ResolvedKeybindingItem } from '../../../../platform/keybinding/common/resolvedKeybindingItem.js';
20
>
import { DEFAULT_EDITOR_ASSOCIATION, IEditorPane } from '../../../common/editor.js';
21
>
import { EditorInput } from '../../../common/editor/editorInput.js';
22
>
import { Settings2EditorModel } from './preferencesModels.js';
23
>
24
>
export enum SettingValueType {
25
>
Null = 'null',
26
>
Enum = 'enum',
27
>
String = 'string',
28
>
MultilineString = 'multiline-string',
29
>
Integer = 'integer',
30
>
Number = 'number',
31
>
Boolean = 'boolean',
32
>
Array = 'array',
33
>
Exclude = 'exclude',
34
>
Include = 'include',
35
>
Complex = 'complex',
36
>
NullableInteger = 'nullable-integer',
37
>
NullableNumber = 'nullable-number',
38
>
Object = 'object',
39
>
BooleanObject = 'boolean-object',
40
>
LanguageTag = 'language-tag',
41
>
ExtensionToggle = 'extension-toggle',
42
>
ComplexObject = 'complex-object',
43
>
}
44
>
45
>
export interface ISettingsGroup {
46
>
id: string;
47
>
range: IRange;
48
>
title: string;
49
>
titleRange: IRange;
50
>
sections: ISettingsSection[];
51
>
order?: number;
52
>
extensionInfo?: IExtensionInfo;
53
>
}
54
>
55
>
export interface ISettingsSection {
56
>
title?: string;
57
>
settings: ISetting[];
58
>
}
59
>
60
>
export interface ISetting {
61
>
range: IRange;
62
>
key: string;
63
>
keyRange: IRange;
64
>
value: any;
65
>
valueRange: IRange;
66
>
description: string[];
67
>
keywords?: string[];
68
>
descriptionIsMarkdown?: boolean;
69
>
descriptionRanges: IRange[];
70
>
overrides?: ISetting[];
71
>
overrideOf?: ISetting;
72
>
deprecationMessage?: string;
73
>
deprecationMessageIsMarkdown?: boolean;
74
>
75
>
scope?: ConfigurationScope;
76
>
type?: string | string[];
77
>
order?: number;
78
>
arrayItemType?: string;
79
>
objectProperties?: IJSONSchemaMap;
80
>
objectPatternProperties?: IJSONSchemaMap;
81
>
objectAdditionalProperties?: boolean | IJSONSchema;
82
>
propertyNames?: IJSONSchema;
83
>
enum?: string[];
84
>
enumDescriptions?: string[];
85
>
enumDescriptionsAreMarkdown?: boolean;
86
>
uniqueItems?: boolean;
87
>
tags?: string[];
88
>
disallowSyncIgnore?: boolean;
89
>
restricted?: boolean;
90
>
extensionInfo?: IExtensionInfo;
91
>
validator?: (value: any) => string | null;
92
>
enumItemLabels?: string[];
93
>
editPresentation?: EditPresentationTypes;
94
>
nonLanguageSpecificDefaultValueSource?: ConfigurationDefaultValueSource;
95
>
isLanguageTagSetting?: boolean;
96
>
categoryLabel?: string;
97
>
98
>
// Internal properties
99
>
allKeysAreBoolean?: boolean;
100
>
displayExtensionId?: string;
101
>
title?: string;
102
>
extensionGroupTitle?: string;
103
>
internalOrder?: number;
104
>
}
105
>
106
>
export interface IExtensionSetting extends ISetting {
107
>
extensionName?: string;
108
>
extensionPublisher?: string;
109
>
}
110
>
111
>
export interface ISearchResult {
112
>
filterMatches: ISettingMatch[];
113
>
exactMatch: boolean;
114
>
metadata?: IFilterMetadata;
115
>
}
116
>
117
>
export interface ISearchResultGroup {
118
>
id: string;
119
>
label: string;
120
>
result: ISearchResult;
121
>
order: number;
122
>
}
123
>
124
>
export interface IFilterResult {
125
>
query?: string;
126
>
filteredGroups: ISettingsGroup[];
127
>
allGroups: ISettingsGroup[];
128
>
matches: IRange[];
129
>
metadata?: IStringDictionary<IFilterMetadata>;
130
>
exactMatch?: boolean;
131
>
}
132
>
133
>
/**
134
>
* The ways a setting could match a query,
135
>
* sorted in increasing order of relevance.
136
>
*/
137
>
export enum SettingMatchType {
138
>
None = 0,
139
>
LanguageTagSettingMatch = 1 << 0,
140
>
RemoteMatch = 1 << 1,
141
>
NonContiguousQueryInSettingId = 1 << 2,
142
>
DescriptionOrValueMatch = 1 << 3,
143
>
NonContiguousWordsInSettingsLabel = 1 << 4,
144
>
ContiguousWordsInSettingsLabel = 1 << 5,
145
>
ContiguousQueryInSettingId = 1 << 6,
146
>
AllWordsInSettingsLabel = 1 << 7,
147
>
ExactMatch = 1 << 8,
148
>
}
149
>
export const SettingKeyMatchTypes = (SettingMatchType.AllWordsInSettingsLabel
150
>
| SettingMatchType.ContiguousWordsInSettingsLabel
151
>
| SettingMatchType.NonContiguousWordsInSettingsLabel
152
>
| SettingMatchType.NonContiguousQueryInSettingId
153
>
| SettingMatchType.ContiguousQueryInSettingId);
154
>
155
>
export interface ISettingMatch {
156
>
setting: ISetting;
157
>
matches: IRange[] | null;
158
>
matchType: SettingMatchType;
159
>
keyMatchScore: number;
160
>
score: number;
161
>
providerName?: string;
162
>
}
163
>
164
>
export interface IScoredResults {
165
>
[key: string]: IRemoteSetting;
166
>
}
167
>
168
>
export interface IRemoteSetting {
169
>
score: number;
170
>
key: string;
171
>
id: string;
172
>
defaultValue: string;
173
>
description: string;
174
>
packageId: string;
175
>
extensionName?: string;
176
>
extensionPublisher?: string;
177
>
}
178
>
179
>
export interface IFilterMetadata {
180
>
requestUrl: string;
181
>
requestBody: string;
182
>
timestamp: number;
183
>
duration: number;
184
>
scoredResults: IScoredResults;
185
>
186
>
/** The number of requests made, since requests are split by number of filters */
187
>
requestCount?: number;
188
>
189
>
/** The name of the server that actually served the request */
190
>
context: string;
191
>
}
192
>
193
>
export interface IPreferencesEditorModel<T> {
194
>
uri?: URI;
195
>
getPreference(key: string): T | undefined;
196
>
dispose(): void;
197
>
}
198
>
199
>
export type IGroupFilter = (group: ISettingsGroup) => boolean | null;
200
>
export type ISettingMatcher = (setting: ISetting, group: ISettingsGroup) => { matches: IRange[]; matchType: SettingMatchType; keyMatchScore: number; score: number } | null;
201
>
202
>
export interface ISettingsEditorModel extends IPreferencesEditorModel<ISetting> {
203
>
readonly onDidChangeGroups: Event<void>;
204
>
settingsGroups: ISettingsGroup[];
205
>
filterSettings(filter: string, groupFilter: IGroupFilter, settingMatcher: ISettingMatcher): ISettingMatch[];
206
>
updateResultGroup(id: string, resultGroup: ISearchResultGroup | undefined): IFilterResult | undefined;
207
>
}
208
>
209
>
export interface ISettingsEditorOptions extends IEditorOptions {
210
>
target?: ConfigurationTarget;
211
>
folderUri?: URI;
212
>
query?: string;
213
>
/**
214
>
* Only works when opening the json settings file. Use `query` for settings editor.
215
>
*/
216
>
revealSetting?: {
217
>
key: string;
218
>
edit?: boolean;
219
>
};
220
>
focusSearch?: boolean;
221
>
}
222
>
223
>
export interface IOpenSettingsOptions extends ISettingsEditorOptions {
224
>
jsonEditor?: boolean;
225
>
openToSide?: boolean;
226
>
groupId?: number;
227
>
}
228
>
229
>
export function validateSettingsEditorOptions(options: ISettingsEditorOptions): ISettingsEditorOptions {
230
return {
231
// Inherit provided options