Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/preferences/common/preferencesContribution.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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 { Disposable, dispose, IDisposable } from '../../../../base/common/lifecycle.js';
7
import { isEqual } from '../../../../base/common/resources.js';
8
import * as nls from '../../../../nls.js';
9
import { ConfigurationTarget, IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
10
import { ConfigurationScope, Extensions, IConfigurationRegistry } from '../../../../platform/configuration/common/configurationRegistry.js';
11
import { Registry } from '../../../../platform/registry/common/platform.js';
12
import { IWorkspaceContextService, WorkbenchState } from '../../../../platform/workspace/common/workspace.js';
13
import { workbenchConfigurationNodeBase } from '../../../common/configuration.js';
14
import { IWorkbenchContribution } from '../../../common/contributions.js';
15
import { EditorInputWithOptions } from '../../../common/editor.js';
16
import { SideBySideEditorInput } from '../../../common/editor/sideBySideEditorInput.js';
17
import { RegisteredEditorPriority, IEditorResolverService } from '../../../services/editor/common/editorResolverService.js';
18
import { ITextEditorService } from '../../../services/textfile/common/textEditorService.js';
19
import { DEFAULT_SETTINGS_EDITOR_SETTING, FOLDER_SETTINGS_PATH, IPreferencesService, USE_SPLIT_JSON_SETTING } from '../../../services/preferences/common/preferences.js';
20
import { IUserDataProfileService } from '../../../services/userDataProfile/common/userDataProfile.js';
21
import { IFileService } from '../../../../platform/files/common/files.js';
22
import { SettingsFileSystemProvider } from './settingsFilesystemProvider.js';
23
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
24
25
export class PreferencesContribution extends Disposable implements IWorkbenchContribution {
26
27
static readonly ID = 'workbench.contrib.preferences';
28
29
private editorOpeningListener: IDisposable | undefined;
30
31
constructor(
32
@IFileService fileService: IFileService,
33
@IInstantiationService private readonly instantiationService: IInstantiationService,
34
@IPreferencesService private readonly preferencesService: IPreferencesService,
35
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
36
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
37
@IConfigurationService private readonly configurationService: IConfigurationService,
38
@IEditorResolverService private readonly editorResolverService: IEditorResolverService,
39
@ITextEditorService private readonly textEditorService: ITextEditorService,
40
) {
41
super();
42
this._register(this.configurationService.onDidChangeConfiguration(e => {
43
if (e.affectsConfiguration(USE_SPLIT_JSON_SETTING) || e.affectsConfiguration(DEFAULT_SETTINGS_EDITOR_SETTING)) {
44
this.handleSettingsEditorRegistration();
45
}
46
}));
47
this.handleSettingsEditorRegistration();
48
49
const fileSystemProvider = this._register(this.instantiationService.createInstance(SettingsFileSystemProvider));
50
this._register(fileService.registerProvider(SettingsFileSystemProvider.SCHEMA, fileSystemProvider));
51
}
52
53
private handleSettingsEditorRegistration(): void {
54
55
// dispose any old listener we had
56
dispose(this.editorOpeningListener);
57
58
// install editor opening listener unless user has disabled this
59
if (!!this.configurationService.getValue(USE_SPLIT_JSON_SETTING) || !!this.configurationService.getValue(DEFAULT_SETTINGS_EDITOR_SETTING)) {
60
this.editorOpeningListener = this.editorResolverService.registerEditor(
61
'**/settings.json',
62
{
63
id: SideBySideEditorInput.ID,
64
label: nls.localize('splitSettingsEditorLabel', "Split Settings Editor"),
65
priority: RegisteredEditorPriority.builtin,
66
},
67
{},
68
{
69
createEditorInput: ({ resource, options }): EditorInputWithOptions => {
70
// Global User Settings File
71
if (isEqual(resource, this.userDataProfileService.currentProfile.settingsResource)) {
72
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.USER_LOCAL, resource), options };
73
}
74
75
// Single Folder Workspace Settings File
76
const state = this.workspaceService.getWorkbenchState();
77
if (state === WorkbenchState.FOLDER) {
78
const folders = this.workspaceService.getWorkspace().folders;
79
if (isEqual(resource, folders[0].toResource(FOLDER_SETTINGS_PATH))) {
80
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.WORKSPACE, resource), options };
81
}
82
}
83
84
// Multi Folder Workspace Settings File
85
else if (state === WorkbenchState.WORKSPACE) {
86
const folders = this.workspaceService.getWorkspace().folders;
87
for (const folder of folders) {
88
if (isEqual(resource, folder.toResource(FOLDER_SETTINGS_PATH))) {
89
return { editor: this.preferencesService.createSplitJsonEditorInput(ConfigurationTarget.WORKSPACE_FOLDER, resource), options };
90
}
91
}
92
}
93
94
return { editor: this.textEditorService.createTextEditor({ resource }), options };
95
}
96
}
97
);
98
}
99
}
100
override dispose(): void {
101
dispose(this.editorOpeningListener);
102
super.dispose();
103
}
104
}
105
106
107
const registry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
108
registry.registerConfiguration({
109
...workbenchConfigurationNodeBase,
110
'properties': {
111
'workbench.settings.enableNaturalLanguageSearch': {
112
'type': 'boolean',
113
'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."),
114
'default': true,
115
'scope': ConfigurationScope.WINDOW,
116
'tags': ['usesOnlineServices']
117
},
118
'workbench.settings.settingsSearchTocBehavior': {
119
'type': 'string',
120
'enum': ['hide', 'filter'],
121
'enumDescriptions': [
122
nls.localize('settingsSearchTocBehavior.hide', "Hide the Table of Contents while searching."),
123
nls.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."),
124
],
125
'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."),
126
'default': 'filter',
127
'scope': ConfigurationScope.WINDOW
128
}
129
}
130
});
131
132