settingsEditor2.ts 23.8 KB
Newer Older
R
Rob Lourens 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as DOM from 'vs/base/browser/dom';
7
import { Button } from 'vs/base/browser/ui/button/button';
R
Rob Lourens 已提交
8
import { IAction } from 'vs/base/common/actions';
9
import * as arrays from 'vs/base/common/arrays';
R
Rob Lourens 已提交
10
import { Delayer, ThrottledDelayer } from 'vs/base/common/async';
R
Rob Lourens 已提交
11
import { Color } from 'vs/base/common/color';
12
import { getErrorMessage, isPromiseCanceledError } from 'vs/base/common/errors';
13
import * as objects from 'vs/base/common/objects';
R
Rob Lourens 已提交
14 15 16 17 18 19
import { TPromise } from 'vs/base/common/winjs.base';
import 'vs/css!./media/settingsEditor2';
import { localize } from 'vs/nls';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
20
import { IEditor } from 'vs/platform/editor/common/editor';
R
Rob Lourens 已提交
21
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
22
import { WorkbenchList, WorkbenchTree } from 'vs/platform/list/browser/listService';
23
import { ILogService } from 'vs/platform/log/common/log';
R
Rob Lourens 已提交
24
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
25
import { registerColor } from 'vs/platform/theme/common/colorRegistry';
26
import { attachButtonStyler, attachInputBoxStyler, attachSelectBoxStyler, attachStyler } from 'vs/platform/theme/common/styler';
27
import { IThemeService, registerThemingParticipant, ICssStyleCollector, ITheme } from 'vs/platform/theme/common/themeService';
R
Rob Lourens 已提交
28 29
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorOptions } from 'vs/workbench/common/editor';
30
import { SearchWidget, SettingsTarget, SettingsTargetsWidget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets';
31
import { IPreferencesService, ISearchResult, ISetting, ISettingsEditorModel, ISettingsGroup } from 'vs/workbench/services/preferences/common/preferences';
32
import { SettingsEditor2Input } from 'vs/workbench/services/preferences/common/preferencesEditorInput';
R
Rob Lourens 已提交
33
import { DefaultSettingsEditorModel } from 'vs/workbench/services/preferences/common/preferencesModels';
34 35
import { IPreferencesSearchService, ISearchProvider } from 'vs/workbench/parts/preferences/common/preferences';
import { KeyCode } from 'vs/base/common/keyCodes';
36
import { SettingsRenderer, SettingsDataSource, SettingsTreeController, SettingsAccessibilityProvider, TreeElement, TreeItemType, ISettingsEditorViewState } from 'vs/workbench/parts/preferences/browser/settingsTree';
R
Rob Lourens 已提交
37

38

R
Rob Lourens 已提交
39 40 41 42 43
enum SearchResultIdx {
	Local = 0,
	Remote = 1
}

44 45
const $ = DOM.$;

R
Rob Lourens 已提交
46 47 48 49 50 51 52 53 54 55
export class SettingsEditor2 extends BaseEditor {

	public static readonly ID: string = 'workbench.editor.settings2';

	private defaultSettingsEditorModel: DefaultSettingsEditorModel;

	private headerContainer: HTMLElement;
	private searchWidget: SearchWidget;
	private settingsTargetsWidget: SettingsTargetsWidget;

56
	private showConfiguredSettingsOnlyCheckbox: HTMLInputElement;
R
Rob Lourens 已提交
57

58 59 60
	private settingsTreeContainer: HTMLElement;
	private settingsTree: WorkbenchTree;
	private treeDataSource: SettingsDataSource;
R
Rob Lourens 已提交
61 62 63 64

	private dimension: DOM.Dimension;
	private searchFocusContextKey: IContextKey<boolean>;

65
	private delayedModifyLogging: Delayer<void>;
R
Rob Lourens 已提交
66 67 68 69 70 71 72
	private delayedFilterLogging: Delayer<void>;
	private localSearchDelayer: Delayer<void>;
	private remoteSearchThrottle: ThrottledDelayer<void>;

	private currentLocalSearchProvider: ISearchProvider;
	private currentRemoteSearchProvider: ISearchProvider;

73
	private pendingSettingModifiedReport: { key: string, value: any };
R
Rob Lourens 已提交
74

75 76
	private focusedElement: TreeElement;

77
	private viewState: ISettingsEditorViewState;
78 79 80
	// <TODO@roblou> factor out tree/list viewmodel to somewhere outside this class
	private searchResultModel: SearchResultModel;
	private showConfiguredSettingsOnly = false;
81
	private inRender = false;
82
	// </TODO>
83

R
Rob Lourens 已提交
84 85 86 87 88 89
	constructor(
		@ITelemetryService telemetryService: ITelemetryService,
		@IConfigurationService private configurationService: IConfigurationService,
		@IThemeService themeService: IThemeService,
		@IContextMenuService contextMenuService: IContextMenuService,
		@IPreferencesService private preferencesService: IPreferencesService,
R
Rob Lourens 已提交
90 91 92
		@IInstantiationService private instantiationService: IInstantiationService,
		@IPreferencesSearchService private preferencesSearchService: IPreferencesSearchService,
		@ILogService private logService: ILogService
R
Rob Lourens 已提交
93 94
	) {
		super(SettingsEditor2.ID, telemetryService, themeService);
95
		this.delayedModifyLogging = new Delayer<void>(1000);
R
Rob Lourens 已提交
96 97 98
		this.delayedFilterLogging = new Delayer<void>(1000);
		this.localSearchDelayer = new Delayer(100);
		this.remoteSearchThrottle = new ThrottledDelayer(200);
99
		this.searchResultModel = new SearchResultModel();
100
		this.viewState = { settingsTarget: ConfigurationTarget.USER };
R
Rob Lourens 已提交
101

102
		this._register(configurationService.onDidChangeConfiguration(() => this.settingsTree.refresh()));
R
Rob Lourens 已提交
103 104 105 106 107 108 109 110 111
	}

	createEditor(parent: HTMLElement): void {
		const prefsEditorElement = DOM.append(parent, $('div', { class: 'settings-editor' }));

		this.createHeader(prefsEditorElement);
		this.createBody(prefsEditorElement);
	}

112
	setInput(input: SettingsEditor2Input, options: EditorOptions): TPromise<void> {
R
Rob Lourens 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
		const oldInput = this.input;
		return super.setInput(input)
			.then(() => {
				if (!input.matches(oldInput)) {
					this.render();
				}
			});
	}

	clearInput(): void {
		super.clearInput();
	}

	layout(dimension: DOM.Dimension): void {
		this.dimension = dimension;
		this.searchWidget.layout(dimension);

		this.layoutSettingsList();
		this.render();
	}

	focus(): void {
		this.searchWidget.focus();
	}

	getSecondaryActions(): IAction[] {
		return <IAction[]>[
		];
	}

	search(filter: string): void {
		this.searchWidget.focus();
	}

	clearSearchResults(): void {
		this.searchWidget.clear();
	}

	private createHeader(parent: HTMLElement): void {
		this.headerContainer = DOM.append(parent, $('.settings-header'));

154
		const previewHeader = DOM.append(this.headerContainer, $('.settings-preview-header'));
R
Rob Lourens 已提交
155 156 157 158 159 160

		const previewAlert = DOM.append(previewHeader, $('span.settings-preview-warning'));
		previewAlert.textContent = localize('previewWarning', "Preview");

		const previewTextLabel = DOM.append(previewHeader, $('span.settings-preview-label'));
		previewTextLabel.textContent = localize('previewLabel', "This is a preview of our new settings editor. You can also ");
161 162 163 164 165 166
		const openSettingsButton = this._register(new Button(previewHeader, { title: true, buttonBackground: null, buttonHoverBackground: null }));
		this._register(attachButtonStyler(openSettingsButton, this.themeService, {
			buttonBackground: Color.transparent.toString(),
			buttonHoverBackground: Color.transparent.toString(),
			buttonForeground: 'foreground'
		}));
R
Rob Lourens 已提交
167
		openSettingsButton.label = localize('openSettingsLabel', "open the original editor.");
168 169 170 171
		openSettingsButton.element.classList.add('open-settings-button');

		this._register(openSettingsButton.onDidClick(() => this.openSettingsFile()));

R
Rob Lourens 已提交
172 173 174 175 176 177
		const searchContainer = DOM.append(this.headerContainer, $('.search-container'));
		this.searchWidget = this._register(this.instantiationService.createInstance(SearchWidget, searchContainer, {
			ariaLabel: localize('SearchSettings.AriaLabel', "Search settings"),
			placeholder: localize('SearchSettings.Placeholder', "Search settings"),
			focusKey: this.searchFocusContextKey
		}));
178
		this._register(this.searchWidget.onDidChange(() => this.onSearchInputChanged()));
179 180 181 182 183 184
		// this._register(DOM.addStandardDisposableListener(this.searchWidget.domNode, 'keydown', e => {
		// 	if (e.keyCode === KeyCode.DownArrow) {
		// 		this.settingsList.focusFirst();
		// 		this.settingsList.domFocus();
		// 	}
		// }));
R
Rob Lourens 已提交
185

186
		const headerControlsContainer = DOM.append(this.headerContainer, $('.settings-header-controls'));
R
Rob Lourens 已提交
187 188 189
		const targetWidgetContainer = DOM.append(headerControlsContainer, $('.settings-target-container'));
		this.settingsTargetsWidget = this._register(this.instantiationService.createInstance(SettingsTargetsWidget, targetWidgetContainer));
		this.settingsTargetsWidget.settingsTarget = ConfigurationTarget.USER;
190 191 192 193
		this.settingsTargetsWidget.onDidTargetChange(() => {
			this.viewState.settingsTarget = this.settingsTargetsWidget.settingsTarget;
			this.settingsTree.refresh();
		});
R
Rob Lourens 已提交
194

195
		this.createHeaderControls(headerControlsContainer);
R
Rob Lourens 已提交
196 197
	}

198 199 200
	private createHeaderControls(parent: HTMLElement): void {
		const headerControlsContainerRight = DOM.append(parent, $('.settings-header-controls-right'));

201 202 203
		this.showConfiguredSettingsOnlyCheckbox = DOM.append(headerControlsContainerRight, $('input#configured-only-checkbox'));
		this.showConfiguredSettingsOnlyCheckbox.type = 'checkbox';
		const showConfiguredSettingsOnlyLabel = <HTMLLabelElement>DOM.append(headerControlsContainerRight, $('label.configured-only-label'));
204
		showConfiguredSettingsOnlyLabel.textContent = localize('showOverriddenOnly', "Show modified only");
205
		showConfiguredSettingsOnlyLabel.htmlFor = 'configured-only-checkbox';
206

207
		this._register(DOM.addDisposableListener(this.showConfiguredSettingsOnlyCheckbox, 'change', e => this.onShowConfiguredOnlyClicked()));
208 209 210 211 212 213 214 215 216 217 218 219
	}

	private openSettingsFile(): TPromise<IEditor> {
		const currentSettingsTarget = this.settingsTargetsWidget.settingsTarget;

		if (currentSettingsTarget === ConfigurationTarget.USER) {
			return this.preferencesService.openGlobalSettings();
		} else if (currentSettingsTarget === ConfigurationTarget.WORKSPACE) {
			return this.preferencesService.openWorkspaceSettings();
		} else {
			return this.preferencesService.openFolderSettings(currentSettingsTarget);
		}
R
Rob Lourens 已提交
220 221 222 223 224 225
	}

	private createBody(parent: HTMLElement): void {
		const bodyContainer = DOM.append(parent, $('.settings-body'));

		this.createList(bodyContainer);
226
		this.createFeedbackButton(bodyContainer);
R
Rob Lourens 已提交
227 228 229
	}

	private createList(parent: HTMLElement): void {
230
		this.settingsTreeContainer = DOM.append(parent, $('.settings-tree-container'));
231

232 233
		this.treeDataSource = this.instantiationService.createInstance(SettingsDataSource, { settingsTarget: ConfigurationTarget.USER });
		const renderer = this.instantiationService.createInstance(SettingsRenderer, {});
234 235
		this._register(renderer.onDidChangeSetting(e => this.onDidChangeSetting(e.key, e.value)));
		this._register(renderer.onDidClickButton(e => this.onDidClickShowAllSettings()));
236

237
		this.settingsTree = this.instantiationService.createInstance(WorkbenchTree, this.settingsTreeContainer,
R
Rob Lourens 已提交
238
			{
239 240 241 242 243 244 245 246 247 248 249
				dataSource: this.treeDataSource,
				renderer: renderer,
				controller: this.instantiationService.createInstance(SettingsTreeController),
				accessibilityProvider: this.instantiationService.createInstance(SettingsAccessibilityProvider),
			},
			{
				ariaLabel: localize('treeAriaLabel', "Settings"),
				showLoading: false,
				indentPixels: 0,
				twistiePixels: 15
			});
250

251 252 253 254
		this.settingsTree.onDidChangeFocus(e => {
			if (this.focusedElement && this.focusedElement.type === TreeItemType.setting) {
				const row = document.getElementById(this.focusedElement.id);
				setTabindexes(row, -1);
255 256
			}

257
			this.focusedElement = e.focus;
258

259 260 261
			if (this.focusedElement && this.focusedElement.type === TreeItemType.setting) {
				const row = document.getElementById(this.focusedElement.id);
				setTabindexes(row, 0);
262
			}
263
		});
264 265
	}

266 267 268 269 270 271 272 273 274 275 276 277
	private createFeedbackButton(parent: HTMLElement): void {
		const feedbackButton = this._register(new Button(parent));
		feedbackButton.label = localize('feedbackButtonLabel', "Provide Feedback");
		feedbackButton.element.classList.add('settings-feedback-button');

		this._register(attachButtonStyler(feedbackButton, this.themeService));
		this._register(feedbackButton.onDidClick(() => {
			// Github master issue
			window.open('https://go.microsoft.com/fwlink/?linkid=2000807');
		}));
	}

278
	private onShowConfiguredOnlyClicked(): void {
279
		this.showConfiguredSettingsOnly = this.showConfiguredSettingsOnlyCheckbox.checked;
280 281 282
		this.render();
	}

283 284 285 286 287 288 289 290 291
	private onDidChangeSetting(key: string, value: any): void {
		// ConfigurationService displays the error if this fails.
		// Force a render afterwards because onDidConfigurationUpdate doesn't fire if the update doesn't result in an effective setting value change
		this.configurationService.updateValue(key, value, <ConfigurationTarget>this.settingsTargetsWidget.settingsTarget)
			.then(() => this.settingsTree.refresh());

		const reportModifiedProps = {
			key,
			query: this.searchWidget.getValue(),
292 293
			searchResults: this.searchResultModel && this.searchResultModel.getUniqueResults(),
			rawResults: this.searchResultModel && this.searchResultModel.getRawResults(),
294 295 296 297
			showConfiguredOnly: this.showConfiguredSettingsOnly,
			isReset: typeof value === 'undefined',
			settingsTarget: this.settingsTargetsWidget.settingsTarget as SettingsTarget
		};
298

299 300 301
		if (this.pendingSettingModifiedReport && key !== this.pendingSettingModifiedReport.key) {
			this.reportModifiedSetting(reportModifiedProps);
		}
302

303 304 305
		this.pendingSettingModifiedReport = { key, value };
		this.delayedModifyLogging.trigger(() => this.reportModifiedSetting(reportModifiedProps));
	}
306

307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
	private onDidClickShowAllSettings(): void {
		this.viewState.showAllSettings = !this.viewState.showAllSettings;
	}

	private reportModifiedSetting(props: { key: string, query: string, searchResults: ISearchResult[], rawResults: ISearchResult[], showConfiguredOnly: boolean, isReset: boolean, settingsTarget: SettingsTarget }): void {
		this.pendingSettingModifiedReport = null;

		const remoteResult = props.searchResults && props.searchResults[SearchResultIdx.Remote];
		const localResult = props.searchResults && props.searchResults[SearchResultIdx.Local];

		let groupId = undefined;
		let nlpIndex = undefined;
		let displayIndex = undefined;
		if (props.searchResults) {
			const localIndex = arrays.firstIndex(localResult.filterMatches, m => m.setting.key === props.key);
			groupId = localIndex >= 0 ?
				'local' :
				'remote';

			displayIndex = localIndex >= 0 ?
				localIndex :
				remoteResult && (arrays.firstIndex(remoteResult.filterMatches, m => m.setting.key === props.key) + localResult.filterMatches.length);

330 331 332 333 334 335
			if (this.searchResultModel) {
				const rawResults = this.searchResultModel.getRawResults();
				if (rawResults[SearchResultIdx.Remote]) {
					const _nlpIndex = arrays.firstIndex(rawResults[SearchResultIdx.Remote].filterMatches, m => m.setting.key === props.key);
					nlpIndex = _nlpIndex >= 0 ? _nlpIndex : undefined;
				}
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
			}
		}

		const reportedTarget = props.settingsTarget === ConfigurationTarget.USER ? 'user' :
			props.settingsTarget === ConfigurationTarget.WORKSPACE ? 'workspace' :
				'folder';

		const data = {
			key: props.key,
			query: props.query,
			groupId,
			nlpIndex,
			displayIndex,
			showConfiguredOnly: props.showConfiguredOnly,
			isReset: props.isReset,
			target: reportedTarget
		};

		/* __GDPR__
			"settingsEditor.settingModified" : {
				"key" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
				"query" : { "classification": "CustomerContent", "purpose": "FeatureInsight" },
				"groupId" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
				"nlpIndex" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
				"displayIndex" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
				"showConfiguredOnly" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
				"isReset" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
				"target" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
			}
		*/
		this.telemetryService.publicLog('settingsEditor.settingModified', data);
	}
R
Rob Lourens 已提交
368 369 370 371

	private render(): TPromise<any> {
		if (this.input) {
			return this.input.resolve()
372 373 374 375
				.then((model: DefaultSettingsEditorModel) => {
					this.defaultSettingsEditorModel = model;
					if (!this.settingsTree.getInput()) {
						this.settingsTree.setInput(this.defaultSettingsEditorModel);
376
						this.expandCommonlyUsedSettings();
377 378
					}
				});
R
Rob Lourens 已提交
379 380 381 382
		}
		return TPromise.as(null);
	}

383
	private onSearchInputChanged(): void {
R
Rob Lourens 已提交
384 385
		const query = this.searchWidget.getValue().trim();
		this.delayedFilterLogging.cancel();
386
		this.triggerSearch(query).then(() => {
387
			if (query && this.searchResultModel) {
388
				this.delayedFilterLogging.trigger(() => this.reportFilteringUsed(query, this.searchResultModel.getUniqueResults()));
389 390
			}
		});
R
Rob Lourens 已提交
391 392 393 394 395 396
	}

	private triggerSearch(query: string): TPromise<void> {
		if (query) {
			return TPromise.join([
				this.localSearchDelayer.trigger(() => this.localFilterPreferences(query)),
397
				this.remoteSearchThrottle.trigger(() => this.remoteSearchPreferences(query), 500)
398 399 400
			]).then(() => {
				this.settingsTree.setInput(this.searchResultModel.resultsAsGroup());
			});
R
Rob Lourens 已提交
401 402 403 404 405
		} else {
			// When clearing the input, update immediately to clear it
			this.localSearchDelayer.cancel();
			this.remoteSearchThrottle.cancel();

406 407 408 409
			this.searchResultModel = null;
			this.settingsTree.setInput(this.defaultSettingsEditorModel);
			this.expandCommonlyUsedSettings();

R
Rob Lourens 已提交
410 411 412 413
			return TPromise.wrap(null);
		}
	}

414 415 416 417 418
	private expandCommonlyUsedSettings(): void {
		const commonlyUsedGroup = this.defaultSettingsEditorModel.settingsGroups[0];
		this.settingsTree.expand(this.treeDataSource.getGroupElement(commonlyUsedGroup));
	}

419 420 421 422 423 424 425 426 427 428 429
	private reportFilteringUsed(query: string, results: ISearchResult[]): void {
		const nlpResult = results[SearchResultIdx.Remote];
		const nlpMetadata = nlpResult && nlpResult.metadata;

		const durations = {};
		durations['nlpResult'] = nlpMetadata && nlpMetadata.duration;

		// Count unique results
		const counts = {};
		const filterResult = results[SearchResultIdx.Local];
		counts['filterResult'] = filterResult.filterMatches.length;
430 431
		if (nlpResult) {
			counts['nlpResult'] = nlpResult.filterMatches.length;
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
		}

		const requestCount = nlpMetadata && nlpMetadata.requestCount;

		const data = {
			query,
			durations,
			counts,
			requestCount
		};

		/* __GDPR__
			"settingsEditor.filter" : {
				"query": { "classification": "CustomerContent", "purpose": "FeatureInsight" },
				"durations.nlpResult" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
				"counts.nlpResult" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
				"counts.filterResult" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
				"requestCount" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
			}
		*/
452
		this.telemetryService.publicLog('settingsEditor.filter', data);
453 454
	}

R
Rob Lourens 已提交
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
	private localFilterPreferences(query: string): TPromise<void> {
		this.currentLocalSearchProvider = this.preferencesSearchService.getLocalSearchProvider(query);
		return this.filterOrSearchPreferences(query, SearchResultIdx.Local, this.currentLocalSearchProvider);
	}

	private remoteSearchPreferences(query: string): TPromise<void> {
		this.currentRemoteSearchProvider = this.preferencesSearchService.getRemoteSearchProvider(query);
		return this.filterOrSearchPreferences(query, SearchResultIdx.Remote, this.currentRemoteSearchProvider);
	}

	private filterOrSearchPreferences(query: string, type: SearchResultIdx, searchProvider: ISearchProvider): TPromise<void> {
		const filterPs: TPromise<ISearchResult>[] = [this._filterOrSearchPreferencesModel(query, this.defaultSettingsEditorModel, searchProvider)];

		return TPromise.join(filterPs).then(results => {
			const [result] = results;
470
			this.searchResultModel.setResult(type, result);
471
			return this.render();
R
Rob Lourens 已提交
472 473 474 475 476 477 478 479 480 481 482
		});
	}

	private _filterOrSearchPreferencesModel(filter: string, model: ISettingsEditorModel, provider: ISearchProvider): TPromise<ISearchResult> {
		const searchP = provider ? provider.searchModel(model) : TPromise.wrap(null);
		return searchP
			.then<ISearchResult>(null, err => {
				if (isPromiseCanceledError(err)) {
					return TPromise.wrapError(err);
				} else {
					/* __GDPR__
483
						"settingsEditor.searchError" : {
R
Rob Lourens 已提交
484 485 486 487 488 489 490
							"message": { "classification": "CallstackOrException", "purpose": "FeatureInsight" },
							"filter": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
						}
					*/
					const message = getErrorMessage(err).trim();
					if (message && message !== 'Error') {
						// "Error" = any generic network error
491
						this.telemetryService.publicLog('settingsEditor.searchError', { message, filter });
R
Rob Lourens 已提交
492 493 494 495 496 497 498
						this.logService.info('Setting search error: ' + message);
					}
					return null;
				}
			});
	}

R
Rob Lourens 已提交
499 500
	private layoutSettingsList(): void {
		const listHeight = this.dimension.height - (DOM.getDomNodePagePosition(this.headerContainer).height + 12 /*padding*/);
501 502
		this.settingsTreeContainer.style.height = `${listHeight}px`;
		this.settingsTree.layout(listHeight, 800);
R
Rob Lourens 已提交
503 504 505
	}
}

506 507 508 509 510
function setTabindexes(element: HTMLElement, tabIndex: number): void {
	const focusableElements = element.querySelectorAll('input, button, select, a');
	for (let i = 0; focusableElements && i < focusableElements.length; i++) {
		const element = focusableElements[i];
		(<HTMLElement>element).tabIndex = tabIndex;
R
Rob Lourens 已提交
511 512 513
	}
}

514
// class SettingItemDelegate implements IDelegate<ListEntry> {
515

516
// 	constructor(private measureContainer: HTMLElement) {
R
Rob Lourens 已提交
517

518
// 	}
519

520 521 522 523
// 	getHeight(entry: ListEntry) {
// 		if (entry.templateId === SETTINGS_GROUP_ENTRY_TEMPLATE_ID) {
// 			return 30;
// 		}
524

525 526 527 528 529 530 531
// 		if (entry.templateId === SETTINGS_ENTRY_TEMPLATE_ID) {
// 			if (entry.isExpanded) {
// 				return this.getDynamicHeight(entry);
// 			} else {
// 				return 68;
// 			}
// 		}
R
Rob Lourens 已提交
532

533 534 535
// 		if (entry.templateId === BUTTON_ROW_ENTRY_TEMPLATE) {
// 			return 60;
// 		}
536

537 538
// 		return 0;
// 	}
539

540 541 542
// 	getTemplateId(element: ListEntry) {
// 		return element.templateId;
// 	}
543

544 545 546 547
// 	private getDynamicHeight(entry: ISettingItemEntry): number {
// 		return measureSettingItemEntry(entry, this.measureContainer);
// 	}
// }
548

549 550
// function measureSettingItemEntry(entry: ISettingItemEntry, measureContainer: HTMLElement): number {
// 	const measureHelper = DOM.append(measureContainer, $('.setting-item-measure-helper.monaco-list-row'));
551

552 553
// 	const template = SettingItemRenderer.renderTemplate(measureHelper);
// 	SettingItemRenderer.renderElement(entry, 0, template);
554

555 556 557 558
// 	const height = measureHelper.offsetHeight;
// 	measureContainer.removeChild(measureHelper);
// 	return height;
// }
559 560


561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
class SearchResultModel {
	private rawSearchResults: ISearchResult[];
	private cachedUniqueSearchResults: ISearchResult[];

	getUniqueResults(): ISearchResult[] {
		if (this.cachedUniqueSearchResults) {
			return this.cachedUniqueSearchResults;
		}

		if (!this.rawSearchResults) {
			return null;
		}

		const localMatchKeys = new Set();
		const localResult = objects.deepClone(this.rawSearchResults[SearchResultIdx.Local]);
		if (localResult) {
			localResult.filterMatches.forEach(m => localMatchKeys.add(m.setting.key));
		}

		const remoteResult = objects.deepClone(this.rawSearchResults[SearchResultIdx.Remote]);
		if (remoteResult) {
			remoteResult.filterMatches = remoteResult.filterMatches.filter(m => !localMatchKeys.has(m.setting.key));
		}

		this.cachedUniqueSearchResults = [localResult, remoteResult];
		return this.cachedUniqueSearchResults;
	}

	getRawResults(): ISearchResult[] {
		return this.rawSearchResults;
	}

	setResult(type: SearchResultIdx, result: ISearchResult): void {
		this.cachedUniqueSearchResults = null;
		this.rawSearchResults = this.rawSearchResults || [];
		this.rawSearchResults[type] = result;
	}
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617

	resultsAsGroup(): ISettingsGroup {
		const flatSettings: ISetting[] = [];
		this.getUniqueResults()
			.filter(r => !!r)
			.forEach(r => {
				flatSettings.push(
					...r.filterMatches.map(m => m.setting));
			});

		return <ISettingsGroup>{
			id: 'settingsSearchResultGroup',
			range: null,
			sections: [
				{ settings: flatSettings }
			],
			title: 'searchResults',
			titleRange: null
		};
	}
618
}