From 299449f0f4bbdec07727311a91177797ef41b561 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Mon, 16 Dec 2019 09:57:38 +0100 Subject: [PATCH] #26707 Introduce `resource-language` scope to define a setting as a language setting --- .../configuration/common/configurationRegistry.ts | 13 +++++++++++++ .../api/browser/mainThreadConfiguration.ts | 2 +- .../api/common/configurationExtensionPoint.ts | 7 +++++-- .../preferences/browser/preferencesRenderers.ts | 2 +- .../services/configuration/common/configuration.ts | 8 ++++---- .../common/configurationEditingService.ts | 13 +++++++++++++ 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/vs/platform/configuration/common/configurationRegistry.ts b/src/vs/platform/configuration/common/configurationRegistry.ts index 8a346c09ca4..64fac4d9c64 100644 --- a/src/vs/platform/configuration/common/configurationRegistry.ts +++ b/src/vs/platform/configuration/common/configurationRegistry.ts @@ -99,6 +99,10 @@ export const enum ConfigurationScope { * Resource specific configuration, which can be configured in the user, workspace or folder settings. */ RESOURCE, + /** + * Resource specific configuration that can also be configured in language specific settings + */ + RESOURCE_LANGUAGE, /** * Machine specific configuration that can also be configured in workspace or folder settings. */ @@ -143,6 +147,7 @@ export const machineSettings: { properties: SettingProperties, patternProperties export const machineOverridableSettings: { properties: SettingProperties, patternProperties: SettingProperties } = { properties: {}, patternProperties: {} }; export const windowSettings: { properties: SettingProperties, patternProperties: SettingProperties } = { properties: {}, patternProperties: {} }; export const resourceSettings: { properties: SettingProperties, patternProperties: SettingProperties } = { properties: {}, patternProperties: {} }; +export const resourceLanguageSettings: { properties: SettingProperties, patternProperties: SettingProperties } = { properties: {}, patternProperties: {} }; export const editorConfigurationSchemaId = 'vscode://schemas/settings/editor'; const contributionRegistry = Registry.as(JSONExtensions.JSONContribution); @@ -223,6 +228,10 @@ class ConfigurationRegistry implements IConfigurationRegistry { case ConfigurationScope.RESOURCE: delete resourceSettings.properties[key]; break; + case ConfigurationScope.RESOURCE_LANGUAGE: + delete resourceSettings.properties[key]; + delete resourceLanguageSettings.properties[key]; + break; } } } @@ -377,6 +386,10 @@ class ConfigurationRegistry implements IConfigurationRegistry { case ConfigurationScope.RESOURCE: resourceSettings.properties[key] = properties[key]; break; + case ConfigurationScope.RESOURCE_LANGUAGE: + resourceSettings.properties[key] = properties[key]; + resourceLanguageSettings.properties[key] = properties[key]; + break; } } } diff --git a/src/vs/workbench/api/browser/mainThreadConfiguration.ts b/src/vs/workbench/api/browser/mainThreadConfiguration.ts index 29e768e8347..2871b8d4ca7 100644 --- a/src/vs/workbench/api/browser/mainThreadConfiguration.ts +++ b/src/vs/workbench/api/browser/mainThreadConfiguration.ts @@ -63,7 +63,7 @@ export class MainThreadConfiguration implements MainThreadConfigurationShape { private deriveConfigurationTarget(key: string, resource: URI | null): ConfigurationTarget { if (resource && this._workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE) { const configurationProperties = Registry.as(ConfigurationExtensions.Configuration).getConfigurationProperties(); - if (configurationProperties[key] && configurationProperties[key].scope === ConfigurationScope.RESOURCE) { + if (configurationProperties[key] && (configurationProperties[key].scope === ConfigurationScope.RESOURCE || configurationProperties[key].scope === ConfigurationScope.RESOURCE_LANGUAGE)) { return ConfigurationTarget.WORKSPACE_FOLDER; } } diff --git a/src/vs/workbench/api/common/configurationExtensionPoint.ts b/src/vs/workbench/api/common/configurationExtensionPoint.ts index 797cd6d8f9a..29cc4ba3231 100644 --- a/src/vs/workbench/api/common/configurationExtensionPoint.ts +++ b/src/vs/workbench/api/common/configurationExtensionPoint.ts @@ -39,16 +39,17 @@ const configurationEntrySchema: IJSONSchema = { }, scope: { type: 'string', - enum: ['application', 'machine', 'window', 'resource', 'machine-overridable'], + enum: ['application', 'machine', 'window', 'resource', 'resource-language', 'machine-overridable'], default: 'window', enumDescriptions: [ nls.localize('scope.application.description', "Configuration that can be configured only in the user settings."), 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."), nls.localize('scope.window.description', "Configuration that can be configured in the user, remote or workspace settings."), nls.localize('scope.resource.description', "Configuration that can be configured in the user, remote, workspace or folder settings."), + nls.localize('scope.resource-language.description', "Resource configuration that can be configured also in language specific settings."), nls.localize('scope.machine-overridable.description', "Machine configuration that can be configured also in workspace or folder settings.") ], - description: nls.localize('scope.description', "Scope in which the configuration is applicable. Available scopes are `application`, `machine`, `window`, `resource` and `machine-overridable`.") + description: nls.localize('scope.description', "Scope in which the configuration is applicable. Available scopes are `application`, `machine`, `window`, `resource`, `resource-language` and `machine-overridable`.") }, enumDescriptions: { type: 'array', @@ -218,6 +219,8 @@ function validateProperties(configuration: IConfigurationNode, extension: IExten propertyConfiguration.scope = ConfigurationScope.RESOURCE; } else if (propertyConfiguration.scope.toString() === 'machine-overridable') { propertyConfiguration.scope = ConfigurationScope.MACHINE_OVERRIDABLE; + } else if (propertyConfiguration.scope.toString() === 'resource-language') { + propertyConfiguration.scope = ConfigurationScope.RESOURCE_LANGUAGE; } else { propertyConfiguration.scope = ConfigurationScope.WINDOW; } diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts index 103536ddc96..bfdb2f18caa 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts @@ -772,7 +772,7 @@ class EditSettingRenderer extends Disposable { if ((this.masterSettingsModel).configurationTarget !== ConfigurationTarget.WORKSPACE_FOLDER) { return true; } - if (configurationNode.scope === ConfigurationScope.RESOURCE) { + if (configurationNode.scope === ConfigurationScope.RESOURCE || configurationNode.scope === ConfigurationScope.RESOURCE_LANGUAGE) { return true; } } diff --git a/src/vs/workbench/services/configuration/common/configuration.ts b/src/vs/workbench/services/configuration/common/configuration.ts index a470043aa73..069871e52db 100644 --- a/src/vs/workbench/services/configuration/common/configuration.ts +++ b/src/vs/workbench/services/configuration/common/configuration.ts @@ -17,10 +17,10 @@ export const folderSettingsSchemaId = 'vscode://schemas/settings/folder'; export const launchSchemaId = 'vscode://schemas/launch'; export const tasksSchemaId = 'vscode://schemas/tasks'; -export const LOCAL_MACHINE_SCOPES = [ConfigurationScope.APPLICATION, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE]; -export const REMOTE_MACHINE_SCOPES = [ConfigurationScope.MACHINE, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.MACHINE_OVERRIDABLE]; -export const WORKSPACE_SCOPES = [ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.MACHINE_OVERRIDABLE]; -export const FOLDER_SCOPES = [ConfigurationScope.RESOURCE, ConfigurationScope.MACHINE_OVERRIDABLE]; +export const LOCAL_MACHINE_SCOPES = [ConfigurationScope.APPLICATION, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.RESOURCE_LANGUAGE]; +export const REMOTE_MACHINE_SCOPES = [ConfigurationScope.MACHINE, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.RESOURCE_LANGUAGE, ConfigurationScope.MACHINE_OVERRIDABLE]; +export const WORKSPACE_SCOPES = [ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.RESOURCE_LANGUAGE, ConfigurationScope.MACHINE_OVERRIDABLE]; +export const FOLDER_SCOPES = [ConfigurationScope.RESOURCE, ConfigurationScope.RESOURCE_LANGUAGE, ConfigurationScope.MACHINE_OVERRIDABLE]; export const TASKS_CONFIGURATION_KEY = 'tasks'; export const LAUNCH_CONFIGURATION_KEY = 'launch'; diff --git a/src/vs/workbench/services/configuration/common/configurationEditingService.ts b/src/vs/workbench/services/configuration/common/configurationEditingService.ts index 55662338cdb..68bb46913a1 100644 --- a/src/vs/workbench/services/configuration/common/configurationEditingService.ts +++ b/src/vs/workbench/services/configuration/common/configurationEditingService.ts @@ -67,6 +67,11 @@ export const enum ConfigurationEditingErrorCode { */ ERROR_INVALID_FOLDER_TARGET, + /** + * Error when trying to write to language specific setting but not supported for preovided key + */ + ERROR_INVALID_RESOURCE_LANGUAGE_CONFIGURATION, + /** * Error when trying to write to the workspace configuration without having a workspace opened. */ @@ -304,6 +309,7 @@ export class ConfigurationEditingService { 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); 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); case ConfigurationEditingErrorCode.ERROR_INVALID_FOLDER_TARGET: return nls.localize('errorInvalidFolderTarget', "Unable to write to Folder Settings because no resource is provided."); + 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); 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)); // User issues @@ -460,6 +466,13 @@ export class ConfigurationEditingService { } } + if (overrides.overrideIdentifier) { + const configurationProperties = Registry.as(ConfigurationExtensions.Configuration).getConfigurationProperties(); + if (configurationProperties[operation.key].scope !== ConfigurationScope.RESOURCE_LANGUAGE) { + return this.reject(ConfigurationEditingErrorCode.ERROR_INVALID_RESOURCE_LANGUAGE_CONFIGURATION, target, operation); + } + } + if (!operation.resource) { return this.reject(ConfigurationEditingErrorCode.ERROR_INVALID_FOLDER_TARGET, target, operation); } -- GitLab