Skip to content

Commit 299449f

Browse files
committed
microsoft#26707 Introduce resource-language scope to define a setting as a language setting
1 parent 236faf2 commit 299449f

6 files changed

Lines changed: 37 additions & 8 deletions

File tree

src/vs/platform/configuration/common/configurationRegistry.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ export const enum ConfigurationScope {
9999
* Resource specific configuration, which can be configured in the user, workspace or folder settings.
100100
*/
101101
RESOURCE,
102+
/**
103+
* Resource specific configuration that can also be configured in language specific settings
104+
*/
105+
RESOURCE_LANGUAGE,
102106
/**
103107
* Machine specific configuration that can also be configured in workspace or folder settings.
104108
*/
@@ -143,6 +147,7 @@ export const machineSettings: { properties: SettingProperties, patternProperties
143147
export const machineOverridableSettings: { properties: SettingProperties, patternProperties: SettingProperties } = { properties: {}, patternProperties: {} };
144148
export const windowSettings: { properties: SettingProperties, patternProperties: SettingProperties } = { properties: {}, patternProperties: {} };
145149
export const resourceSettings: { properties: SettingProperties, patternProperties: SettingProperties } = { properties: {}, patternProperties: {} };
150+
export const resourceLanguageSettings: { properties: SettingProperties, patternProperties: SettingProperties } = { properties: {}, patternProperties: {} };
146151

147152
export const editorConfigurationSchemaId = 'vscode://schemas/settings/editor';
148153
const contributionRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
@@ -223,6 +228,10 @@ class ConfigurationRegistry implements IConfigurationRegistry {
223228
case ConfigurationScope.RESOURCE:
224229
delete resourceSettings.properties[key];
225230
break;
231+
case ConfigurationScope.RESOURCE_LANGUAGE:
232+
delete resourceSettings.properties[key];
233+
delete resourceLanguageSettings.properties[key];
234+
break;
226235
}
227236
}
228237
}
@@ -377,6 +386,10 @@ class ConfigurationRegistry implements IConfigurationRegistry {
377386
case ConfigurationScope.RESOURCE:
378387
resourceSettings.properties[key] = properties[key];
379388
break;
389+
case ConfigurationScope.RESOURCE_LANGUAGE:
390+
resourceSettings.properties[key] = properties[key];
391+
resourceLanguageSettings.properties[key] = properties[key];
392+
break;
380393
}
381394
}
382395
}

src/vs/workbench/api/browser/mainThreadConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class MainThreadConfiguration implements MainThreadConfigurationShape {
6363
private deriveConfigurationTarget(key: string, resource: URI | null): ConfigurationTarget {
6464
if (resource && this._workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE) {
6565
const configurationProperties = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).getConfigurationProperties();
66-
if (configurationProperties[key] && configurationProperties[key].scope === ConfigurationScope.RESOURCE) {
66+
if (configurationProperties[key] && (configurationProperties[key].scope === ConfigurationScope.RESOURCE || configurationProperties[key].scope === ConfigurationScope.RESOURCE_LANGUAGE)) {
6767
return ConfigurationTarget.WORKSPACE_FOLDER;
6868
}
6969
}

src/vs/workbench/api/common/configurationExtensionPoint.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ const configurationEntrySchema: IJSONSchema = {
3939
},
4040
scope: {
4141
type: 'string',
42-
enum: ['application', 'machine', 'window', 'resource', 'machine-overridable'],
42+
enum: ['application', 'machine', 'window', 'resource', 'resource-language', 'machine-overridable'],
4343
default: 'window',
4444
enumDescriptions: [
4545
nls.localize('scope.application.description', "Configuration that can be configured only in the user settings."),
4646
nls.localize('scope.machine.description', "Configuration that can be configured only in the user settings when the extension is running locally, or only in the remote settings when the extension is running remotely."),
4747
nls.localize('scope.window.description', "Configuration that can be configured in the user, remote or workspace settings."),
4848
nls.localize('scope.resource.description', "Configuration that can be configured in the user, remote, workspace or folder settings."),
49+
nls.localize('scope.resource-language.description', "Resource configuration that can be configured also in language specific settings."),
4950
nls.localize('scope.machine-overridable.description', "Machine configuration that can be configured also in workspace or folder settings.")
5051
],
51-
description: nls.localize('scope.description', "Scope in which the configuration is applicable. Available scopes are `application`, `machine`, `window`, `resource` and `machine-overridable`.")
52+
description: nls.localize('scope.description', "Scope in which the configuration is applicable. Available scopes are `application`, `machine`, `window`, `resource`, `resource-language` and `machine-overridable`.")
5253
},
5354
enumDescriptions: {
5455
type: 'array',
@@ -218,6 +219,8 @@ function validateProperties(configuration: IConfigurationNode, extension: IExten
218219
propertyConfiguration.scope = ConfigurationScope.RESOURCE;
219220
} else if (propertyConfiguration.scope.toString() === 'machine-overridable') {
220221
propertyConfiguration.scope = ConfigurationScope.MACHINE_OVERRIDABLE;
222+
} else if (propertyConfiguration.scope.toString() === 'resource-language') {
223+
propertyConfiguration.scope = ConfigurationScope.RESOURCE_LANGUAGE;
221224
} else {
222225
propertyConfiguration.scope = ConfigurationScope.WINDOW;
223226
}

src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ class EditSettingRenderer extends Disposable {
772772
if ((<SettingsEditorModel>this.masterSettingsModel).configurationTarget !== ConfigurationTarget.WORKSPACE_FOLDER) {
773773
return true;
774774
}
775-
if (configurationNode.scope === ConfigurationScope.RESOURCE) {
775+
if (configurationNode.scope === ConfigurationScope.RESOURCE || configurationNode.scope === ConfigurationScope.RESOURCE_LANGUAGE) {
776776
return true;
777777
}
778778
}

src/vs/workbench/services/configuration/common/configuration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export const folderSettingsSchemaId = 'vscode://schemas/settings/folder';
1717
export const launchSchemaId = 'vscode://schemas/launch';
1818
export const tasksSchemaId = 'vscode://schemas/tasks';
1919

20-
export const LOCAL_MACHINE_SCOPES = [ConfigurationScope.APPLICATION, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE];
21-
export const REMOTE_MACHINE_SCOPES = [ConfigurationScope.MACHINE, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.MACHINE_OVERRIDABLE];
22-
export const WORKSPACE_SCOPES = [ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.MACHINE_OVERRIDABLE];
23-
export const FOLDER_SCOPES = [ConfigurationScope.RESOURCE, ConfigurationScope.MACHINE_OVERRIDABLE];
20+
export const LOCAL_MACHINE_SCOPES = [ConfigurationScope.APPLICATION, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.RESOURCE_LANGUAGE];
21+
export const REMOTE_MACHINE_SCOPES = [ConfigurationScope.MACHINE, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.RESOURCE_LANGUAGE, ConfigurationScope.MACHINE_OVERRIDABLE];
22+
export const WORKSPACE_SCOPES = [ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.RESOURCE_LANGUAGE, ConfigurationScope.MACHINE_OVERRIDABLE];
23+
export const FOLDER_SCOPES = [ConfigurationScope.RESOURCE, ConfigurationScope.RESOURCE_LANGUAGE, ConfigurationScope.MACHINE_OVERRIDABLE];
2424

2525
export const TASKS_CONFIGURATION_KEY = 'tasks';
2626
export const LAUNCH_CONFIGURATION_KEY = 'launch';

src/vs/workbench/services/configuration/common/configurationEditingService.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export const enum ConfigurationEditingErrorCode {
6767
*/
6868
ERROR_INVALID_FOLDER_TARGET,
6969

70+
/**
71+
* Error when trying to write to language specific setting but not supported for preovided key
72+
*/
73+
ERROR_INVALID_RESOURCE_LANGUAGE_CONFIGURATION,
74+
7075
/**
7176
* Error when trying to write to the workspace configuration without having a workspace opened.
7277
*/
@@ -304,6 +309,7 @@ export class ConfigurationEditingService {
304309
case ConfigurationEditingErrorCode.ERROR_INVALID_USER_TARGET: return nls.localize('errorInvalidUserTarget', "Unable to write to User Settings because {0} does not support for global scope.", operation.key);
305310
case ConfigurationEditingErrorCode.ERROR_INVALID_WORKSPACE_TARGET: return nls.localize('errorInvalidWorkspaceTarget', "Unable to write to Workspace Settings because {0} does not support for workspace scope in a multi folder workspace.", operation.key);
306311
case ConfigurationEditingErrorCode.ERROR_INVALID_FOLDER_TARGET: return nls.localize('errorInvalidFolderTarget', "Unable to write to Folder Settings because no resource is provided.");
312+
case ConfigurationEditingErrorCode.ERROR_INVALID_RESOURCE_LANGUAGE_CONFIGURATION: return nls.localize('errorInvalidResourceLanguageConfiguraiton', "Unable to write to Language Settings because {0} is not a resource language setting.", operation.key);
307313
case ConfigurationEditingErrorCode.ERROR_NO_WORKSPACE_OPENED: return nls.localize('errorNoWorkspaceOpened', "Unable to write to {0} because no workspace is opened. Please open a workspace first and try again.", this.stringifyTarget(target));
308314

309315
// User issues
@@ -460,6 +466,13 @@ export class ConfigurationEditingService {
460466
}
461467
}
462468

469+
if (overrides.overrideIdentifier) {
470+
const configurationProperties = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).getConfigurationProperties();
471+
if (configurationProperties[operation.key].scope !== ConfigurationScope.RESOURCE_LANGUAGE) {
472+
return this.reject(ConfigurationEditingErrorCode.ERROR_INVALID_RESOURCE_LANGUAGE_CONFIGURATION, target, operation);
473+
}
474+
}
475+
463476
if (!operation.resource) {
464477
return this.reject(ConfigurationEditingErrorCode.ERROR_INVALID_FOLDER_TARGET, target, operation);
465478
}

0 commit comments

Comments
 (0)