Path: blob/main/src/vs/workbench/contrib/preferences/common/preferencesContribution.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Disposable, dispose, IDisposable } from '../../../../base/common/lifecycle.js';6import { isEqual } from '../../../../base/common/resources.js';7import * as nls from '../../../../nls.js';8import { ConfigurationTarget, IConfigurationService } from '../../../../platform/configuration/common/configuration.js';9import { ConfigurationScope, Extensions, IConfigurationRegistry } from '../../../../platform/configuration/common/configurationRegistry.js';10import { Registry } from '../../../../platform/registry/common/platform.js';11import { IWorkspaceContextService, WorkbenchState } from '../../../../platform/workspace/common/workspace.js';12import { workbenchConfigurationNodeBase } from '../../../common/configuration.js';13import { IWorkbenchContribution } from '../../../common/contributions.js';14import { EditorInputWithOptions } from '../../../common/editor.js';15import { SideBySideEditorInput } from '../../../common/editor/sideBySideEditorInput.js';16import { RegisteredEditorPriority, IEditorResolverService } from '../../../services/editor/common/editorResolverService.js';17import { ITextEditorService } from '../../../services/textfile/common/textEditorService.js';18import { DEFAULT_SETTINGS_EDITOR_SETTING, FOLDER_SETTINGS_PATH, IPreferencesService, USE_SPLIT_JSON_SETTING } from '../../../services/preferences/common/preferences.js';19import { IUserDataProfileService } from '../../../services/userDataProfile/common/userDataProfile.js';20import { IFileService } from '../../../../platform/files/common/files.js';21import { SettingsFileSystemProvider } from './settingsFilesystemProvider.js';22import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';2324export class PreferencesContribution extends Disposable implements IWorkbenchContribution {2526static readonly ID = 'workbench.contrib.preferences';2728private editorOpeningListener: IDisposable | undefined;2930constructor(31@IFileService fileService: IFileService,32@IInstantiationService private readonly instantiationService: IInstantiationService,33@IPreferencesService private readonly preferencesService: IPreferencesService,34@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,35@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,36@IConfigurationService private readonly configurationService: IConfigurationService,37@IEditorResolverService private readonly editorResolverService: IEditorResolverService,38@ITextEditorService private readonly textEditorService: ITextEditorService,39) {40super();41this._register(this.configurationService.onDidChangeConfiguration(e => {42if (e.affectsConfiguration(USE_SPLIT_JSON_SETTING) || e.affectsConfiguration(DEFAULT_SETTINGS_EDITOR_SETTING)) {43this.handleSettingsEditorRegistration();44}45}));46this.handleSettingsEditorRegistration();4748const fileSystemProvider = this._register(this.instantiationService.createInstance(SettingsFileSystemProvider));49this._register(fileService.registerProvider(SettingsFileSystemProvider.SCHEMA, fileSystemProvider));50}5152private handleSettingsEditorRegistration(): void {5354// dispose any old listener we had55dispose(this.editorOpeningListener);5657// install editor opening listener unless user has disabled this58if (!!this.configurationService.getValue(USE_SPLIT_JSON_SETTING) || !!this.configurationService.getValue(DEFAULT_SETTINGS_EDITOR_SETTING)) {59this.editorOpeningListener = this.editorResolverService.registerEditor(60'**/settings.json',61{62id: SideBySideEditorInput.ID,63label: nls.localize('splitSettingsEditorLabel', "Split Settings Editor"),64priority: RegisteredEditorPriority.builtin,65},66{},67{68createEditorInput: ({ resource, options }): EditorInputWithOptions => {69// Global User Settings File70if (isEqual(resource, this.userDataProfileService.currentProfile.settingsResource)) {71return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.USER_LOCAL, resource), options };72}7374// Single Folder Workspace Settings File75const state = this.workspaceService.getWorkbenchState();76if (state === WorkbenchState.FOLDER) {77const folders = this.workspaceService.getWorkspace().folders;78if (isEqual(resource, folders[0].toResource(FOLDER_SETTINGS_PATH))) {79return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.WORKSPACE, resource), options };80}81}8283// Multi Folder Workspace Settings File84else if (state === WorkbenchState.WORKSPACE) {85const folders = this.workspaceService.getWorkspace().folders;86for (const folder of folders) {87if (isEqual(resource, folder.toResource(FOLDER_SETTINGS_PATH))) {88return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.WORKSPACE_FOLDER, resource), options };89}90}91}9293return { editor: this.textEditorService.createTextEditor({ resource }), options };94}95}96);97}98}99override dispose(): void {100dispose(this.editorOpeningListener);101super.dispose();102}103}104105106const registry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);107registry.registerConfiguration({108...workbenchConfigurationNodeBase,109'properties': {110'workbench.settings.enableNaturalLanguageSearch': {111'type': 'boolean',112'description': nls.localize('enableNaturalLanguageSettingsSearch', "Controls whether to enable the natural language search mode for settings. The natural language search is provided by a Microsoft online service."),113'default': true,114'scope': ConfigurationScope.WINDOW,115'tags': ['usesOnlineServices']116},117'workbench.settings.settingsSearchTocBehavior': {118'type': 'string',119'enum': ['hide', 'filter'],120'enumDescriptions': [121nls.localize('settingsSearchTocBehavior.hide', "Hide the Table of Contents while searching."),122nls.localize('settingsSearchTocBehavior.filter', "Filter the Table of Contents to just categories that have matching settings. Clicking on a category will filter the results to that category."),123],124'description': nls.localize('settingsSearchTocBehavior', "Controls the behavior of the Settings editor Table of Contents while searching. If this setting is being changed in the Settings editor, the setting will take effect after the search query is modified."),125'default': 'filter',126'scope': ConfigurationScope.WINDOW127}128}129});130131132