diff --git a/eslint.config.js b/eslint.config.js index 2270c64a7a3..cc402245e25 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -428,11 +428,6 @@ export default tseslint.config( // Platform 'src/vs/platform/browserElements/electron-main/nativeBrowserElementsMainService.ts', 'src/vs/platform/commands/common/commands.ts', - 'src/vs/platform/configuration/common/configuration.ts', - 'src/vs/platform/configuration/common/configurationModels.ts', - 'src/vs/platform/configuration/common/configurationRegistry.ts', - 'src/vs/platform/configuration/common/configurationService.ts', - 'src/vs/platform/configuration/common/configurations.ts', 'src/vs/platform/contextkey/browser/contextKeyService.ts', 'src/vs/platform/contextkey/common/contextkey.ts', 'src/vs/platform/contextview/browser/contextView.ts', @@ -543,7 +538,6 @@ export default tseslint.config( 'src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/utils/utils.ts', // Workbench 'src/vs/workbench/api/browser/mainThreadChatSessions.ts', - 'src/vs/workbench/api/common/configurationExtensionPoint.ts', 'src/vs/workbench/api/common/extHost.api.impl.ts', 'src/vs/workbench/api/common/extHost.protocol.ts', 'src/vs/workbench/api/common/extHostChatSessions.ts', @@ -798,9 +792,6 @@ export default tseslint.config( 'src/vs/workbench/services/authentication/common/authentication.ts', 'src/vs/workbench/services/authentication/test/browser/authenticationQueryServiceMocks.ts', 'src/vs/workbench/services/commands/common/commandService.ts', - 'src/vs/workbench/services/configuration/browser/configuration.ts', - 'src/vs/workbench/services/configuration/browser/configurationService.ts', - 'src/vs/workbench/services/configuration/common/configurationModels.ts', 'src/vs/workbench/services/configurationResolver/common/configurationResolver.ts', 'src/vs/workbench/services/configurationResolver/common/configurationResolverExpression.ts', 'src/vs/workbench/services/extensionManagement/browser/builtinExtensionsScannerService.ts', diff --git a/src/vs/platform/configuration/common/configuration.ts b/src/vs/platform/configuration/common/configuration.ts index 8e6c465dfcc..e28c4a34a0a 100644 --- a/src/vs/platform/configuration/common/configuration.ts +++ b/src/vs/platform/configuration/common/configuration.ts @@ -13,7 +13,8 @@ import { IWorkspaceFolder } from '../../workspace/common/workspace.js'; export const IConfigurationService = createDecorator('configurationService'); -export function isConfigurationOverrides(thing: any): thing is IConfigurationOverrides { +export function isConfigurationOverrides(obj: unknown): obj is IConfigurationOverrides { + const thing = obj as IConfigurationOverrides; return thing && typeof thing === 'object' && (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string') @@ -25,11 +26,12 @@ export interface IConfigurationOverrides { resource?: URI | null; } -export function isConfigurationUpdateOverrides(thing: any): thing is IConfigurationUpdateOverrides { +export function isConfigurationUpdateOverrides(obj: unknown): obj is IConfigurationUpdateOverrides { + const thing = obj as IConfigurationUpdateOverrides | IConfigurationOverrides; return thing && typeof thing === 'object' - && (!thing.overrideIdentifiers || Array.isArray(thing.overrideIdentifiers)) - && !thing.overrideIdentifier + && (!(thing as IConfigurationUpdateOverrides).overrideIdentifiers || Array.isArray((thing as IConfigurationUpdateOverrides).overrideIdentifiers)) + && !(thing as IConfigurationOverrides).overrideIdentifier && (!thing.resource || thing.resource instanceof URI); } @@ -185,10 +187,10 @@ export interface IConfigurationService { * @param key setting to be updated * @param value The new value */ - updateValue(key: string, value: any): Promise; - updateValue(key: string, value: any, target: ConfigurationTarget): Promise; - updateValue(key: string, value: any, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise; - updateValue(key: string, value: any, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise; + updateValue(key: string, value: unknown): Promise; + updateValue(key: string, value: unknown, target: ConfigurationTarget): Promise; + updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise; + updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise; inspect(key: string, overrides?: IConfigurationOverrides): IConfigurationValue>; @@ -205,15 +207,15 @@ export interface IConfigurationService { } export interface IConfigurationModel { - contents: any; + contents: IStringDictionary; keys: string[]; overrides: IOverrides[]; - raw?: IStringDictionary; + raw?: ReadonlyArray> | IStringDictionary; } export interface IOverrides { keys: string[]; - contents: any; + contents: IStringDictionary; identifiers: string[]; } @@ -234,7 +236,7 @@ export interface IConfigurationCompareResult { overrides: [string, string[]][]; } -export function toValuesTree(properties: { [qualifiedKey: string]: any }, conflictReporter: (message: string) => void): any { +export function toValuesTree(properties: IStringDictionary, conflictReporter: (message: string) => void): IStringDictionary { const root = Object.create(null); for (const key in properties) { @@ -244,11 +246,11 @@ export function toValuesTree(properties: { [qualifiedKey: string]: any }, confli return root; } -export function addToValueTree(settingsTreeRoot: any, key: string, value: any, conflictReporter: (message: string) => void): void { +export function addToValueTree(settingsTreeRoot: IStringDictionary, key: string, value: unknown, conflictReporter: (message: string) => void): void { const segments = key.split('.'); const last = segments.pop()!; - let curr = settingsTreeRoot; + let curr: IStringDictionary = settingsTreeRoot; for (let i = 0; i < segments.length; i++) { const s = segments[i]; let obj = curr[s]; @@ -266,12 +268,12 @@ export function addToValueTree(settingsTreeRoot: any, key: string, value: any, c conflictReporter(`Ignoring ${key} as ${segments.slice(0, i + 1).join('.')} is ${JSON.stringify(obj)}`); return; } - curr = obj; + curr = obj as IStringDictionary; } if (typeof curr === 'object' && curr !== null) { try { - curr[last] = value; // workaround https://github.com/microsoft/vscode/issues/13606 + (curr as IStringDictionary)[last] = value; // workaround https://github.com/microsoft/vscode/issues/13606 } catch (e) { conflictReporter(`Ignoring ${key} as ${segments.join('.')} is ${JSON.stringify(curr)}`); } @@ -280,29 +282,30 @@ export function addToValueTree(settingsTreeRoot: any, key: string, value: any, c } } -export function removeFromValueTree(valueTree: any, key: string): void { +export function removeFromValueTree(valueTree: IStringDictionary, key: string): void { const segments = key.split('.'); doRemoveFromValueTree(valueTree, segments); } -function doRemoveFromValueTree(valueTree: any, segments: string[]): void { +function doRemoveFromValueTree(valueTree: IStringDictionary | unknown, segments: string[]): void { if (!valueTree) { return; } + const valueTreeRecord = valueTree as IStringDictionary; const first = segments.shift()!; if (segments.length === 0) { // Reached last segment - delete valueTree[first]; + delete valueTreeRecord[first]; return; } - if (Object.keys(valueTree).indexOf(first) !== -1) { - const value = valueTree[first]; + if (Object.keys(valueTreeRecord).indexOf(first) !== -1) { + const value = valueTreeRecord[first]; if (typeof value === 'object' && !Array.isArray(value)) { doRemoveFromValueTree(value, segments); - if (Object.keys(value).length === 0) { - delete valueTree[first]; + if (Object.keys(value as object).length === 0) { + delete valueTreeRecord[first]; } } } @@ -311,32 +314,32 @@ function doRemoveFromValueTree(valueTree: any, segments: string[]): void { /** * A helper function to get the configuration value with a specific settings path (e.g. config.some.setting) */ -export function getConfigurationValue(config: any, settingPath: string): T | undefined; -export function getConfigurationValue(config: any, settingPath: string, defaultValue: T): T; -export function getConfigurationValue(config: any, settingPath: string, defaultValue?: T): T | undefined { - function accessSetting(config: any, path: string[]): any { - let current = config; +export function getConfigurationValue(config: IStringDictionary, settingPath: string): T | undefined; +export function getConfigurationValue(config: IStringDictionary, settingPath: string, defaultValue: T): T; +export function getConfigurationValue(config: IStringDictionary, settingPath: string, defaultValue?: T): T | undefined { + function accessSetting(config: IStringDictionary, path: string[]): unknown { + let current: unknown = config; for (const component of path) { if (typeof current !== 'object' || current === null) { return undefined; } - current = current[component]; + current = (current as IStringDictionary)[component]; } - return current; + return current as T; } const path = settingPath.split('.'); const result = accessSetting(config, path); - return typeof result === 'undefined' ? defaultValue : result; + return typeof result === 'undefined' ? defaultValue : result as T; } -export function merge(base: any, add: any, overwrite: boolean): void { +export function merge(base: IStringDictionary, add: IStringDictionary, overwrite: boolean): void { Object.keys(add).forEach(key => { if (key !== '__proto__') { if (key in base) { if (types.isObject(base[key]) && types.isObject(add[key])) { - merge(base[key], add[key], overwrite); + merge(base[key] as IStringDictionary, add[key] as IStringDictionary, overwrite); } else if (overwrite) { base[key] = add[key]; } diff --git a/src/vs/platform/configuration/common/configurationModels.ts b/src/vs/platform/configuration/common/configurationModels.ts index e90048d5949..b5cf8e4a264 100644 --- a/src/vs/platform/configuration/common/configurationModels.ts +++ b/src/vs/platform/configuration/common/configurationModels.ts @@ -35,10 +35,10 @@ export class ConfigurationModel implements IConfigurationModel { private readonly overrideConfigurations = new Map(); constructor( - private readonly _contents: any, + private readonly _contents: IStringDictionary, private readonly _keys: string[], private readonly _overrides: IOverrides[], - readonly raw: IStringDictionary | ReadonlyArray | ConfigurationModel> | undefined, + private readonly _raw: IStringDictionary | ReadonlyArray | ConfigurationModel> | undefined, private readonly logService: ILogService ) { } @@ -46,8 +46,8 @@ export class ConfigurationModel implements IConfigurationModel { private _rawConfiguration: ConfigurationModel | undefined; get rawConfiguration(): ConfigurationModel { if (!this._rawConfiguration) { - if (this.raw) { - const rawConfigurationModels = (Array.isArray(this.raw) ? this.raw : [this.raw]).map(raw => { + if (this._raw) { + const rawConfigurationModels = (Array.isArray(this._raw) ? this._raw : [this._raw]).map(raw => { if (raw instanceof ConfigurationModel) { return raw; } @@ -64,7 +64,7 @@ export class ConfigurationModel implements IConfigurationModel { return this._rawConfiguration; } - get contents(): any { + get contents(): IStringDictionary { return this._contents; } @@ -76,12 +76,22 @@ export class ConfigurationModel implements IConfigurationModel { return this._keys; } + get raw(): IStringDictionary | IStringDictionary[] | undefined { + if (!this._raw) { + return undefined; + } + if (Array.isArray(this._raw) && this._raw.every(raw => raw instanceof ConfigurationModel)) { + return undefined; + } + return this._raw as IStringDictionary | IStringDictionary[]; + } + isEmpty(): boolean { return this._keys.length === 0 && Object.keys(this._contents).length === 0 && this._overrides.length === 0; } - getValue(section: string | undefined): V { - return section ? getConfigurationValue(this.contents, section) : this.contents; + getValue(section: string | undefined): V | undefined { + return section ? getConfigurationValue(this.contents, section) : this.contents as V; } inspect(section: string | undefined, overrideIdentifier?: string | null): InspectValue { @@ -112,7 +122,7 @@ export class ConfigurationModel implements IConfigurationModel { getOverrideValue(section: string | undefined, overrideIdentifier: string): V | undefined { const overrideContents = this.getContentsForOverrideIdentifer(overrideIdentifier); return overrideContents - ? section ? getConfigurationValue(overrideContents, section) : overrideContents + ? section ? getConfigurationValue(overrideContents, section) : overrideContents as V : undefined; } @@ -147,10 +157,10 @@ export class ConfigurationModel implements IConfigurationModel { const contents = objects.deepClone(this.contents); const overrides = objects.deepClone(this.overrides); const keys = [...this.keys]; - const raws = this.raw ? Array.isArray(this.raw) ? [...this.raw] : [this.raw] : [this]; + const raws = this._raw ? Array.isArray(this._raw) ? [...this._raw] : [this._raw] : [this]; for (const other of others) { - raws.push(...(other.raw ? Array.isArray(other.raw) ? other.raw : [other.raw] : [other])); + raws.push(...(other._raw ? Array.isArray(other._raw) ? other._raw : [other._raw] : [other])); if (other.isEmpty()) { continue; } @@ -183,7 +193,7 @@ export class ConfigurationModel implements IConfigurationModel { return this; } - const contents: any = {}; + const contents: IStringDictionary = {}; for (const key of arrays.distinct([...Object.keys(this.contents), ...Object.keys(overrideContents)])) { let contentsForKey = this.contents[key]; @@ -194,7 +204,7 @@ export class ConfigurationModel implements IConfigurationModel { // Clone and merge only if base contents and override contents are of type object otherwise just override if (typeof contentsForKey === 'object' && typeof overrideContentsForKey === 'object') { contentsForKey = objects.deepClone(contentsForKey); - this.mergeContents(contentsForKey, overrideContentsForKey); + this.mergeContents(contentsForKey as IStringDictionary, overrideContentsForKey as IStringDictionary); } else { contentsForKey = overrideContentsForKey; } @@ -206,11 +216,11 @@ export class ConfigurationModel implements IConfigurationModel { return new ConfigurationModel(contents, this.keys, this.overrides, undefined, this.logService); } - private mergeContents(source: any, target: any): void { + private mergeContents(source: IStringDictionary, target: IStringDictionary): void { for (const key of Object.keys(target)) { if (key in source) { if (types.isObject(source[key]) && types.isObject(target[key])) { - this.mergeContents(source[key], target[key]); + this.mergeContents(source[key] as IStringDictionary, target[key] as IStringDictionary); continue; } } @@ -218,10 +228,10 @@ export class ConfigurationModel implements IConfigurationModel { } } - private getContentsForOverrideIdentifer(identifier: string): any { - let contentsForIdentifierOnly: IStringDictionary | null = null; - let contents: IStringDictionary | null = null; - const mergeContents = (contentsToMerge: any) => { + private getContentsForOverrideIdentifer(identifier: string): IStringDictionary | null { + let contentsForIdentifierOnly: IStringDictionary | null = null; + let contents: IStringDictionary | null = null; + const mergeContents = (contentsToMerge: IStringDictionary | null) => { if (contentsToMerge) { if (contents) { this.mergeContents(contents, contentsToMerge); @@ -252,11 +262,11 @@ export class ConfigurationModel implements IConfigurationModel { // Update methods - public addValue(key: string, value: any): void { + public addValue(key: string, value: unknown): void { this.updateValue(key, value, true); } - public setValue(key: string, value: any): void { + public setValue(key: string, value: unknown): void { this.updateValue(key, value, false); } @@ -272,18 +282,19 @@ export class ConfigurationModel implements IConfigurationModel { } } - private updateValue(key: string, value: any, add: boolean): void { + private updateValue(key: string, value: unknown, add: boolean): void { addToValueTree(this.contents, key, value, e => this.logService.error(e)); add = add || this.keys.indexOf(key) === -1; if (add) { this.keys.push(key); } if (OVERRIDE_PROPERTY_REGEX.test(key)) { + const overrideContents = this.contents[key] as IStringDictionary; const identifiers = overrideIdentifiersFromKey(key); const override = { identifiers, - keys: Object.keys(this.contents[key]), - contents: toValuesTree(this.contents[key], message => this.logService.error(message)), + keys: Object.keys(overrideContents), + contents: toValuesTree(overrideContents, message => this.logService.error(message)), }; const index = this.overrides.findIndex(o => arrays.equals(o.identifiers, identifiers)); if (index !== -1) { @@ -305,10 +316,10 @@ export interface ConfigurationParseOptions { export class ConfigurationModelParser { - private _raw: any = null; + private _raw: IStringDictionary | null = null; private _configurationModel: ConfigurationModel | null = null; private _restrictedConfigurations: string[] = []; - private _parseErrors: any[] = []; + private _parseErrors: json.ParseError[] = []; constructor( protected readonly _name: string, @@ -323,7 +334,7 @@ export class ConfigurationModelParser { return this._restrictedConfigurations; } - get errors(): any[] { + get errors(): json.ParseError[] { return this._parseErrors; } @@ -340,21 +351,21 @@ export class ConfigurationModelParser { } } - public parseRaw(raw: any, options?: ConfigurationParseOptions): void { + public parseRaw(raw: IStringDictionary, options?: ConfigurationParseOptions): void { this._raw = raw; const { contents, keys, overrides, restricted, hasExcludedProperties } = this.doParseRaw(raw, options); this._configurationModel = new ConfigurationModel(contents, keys, overrides, hasExcludedProperties ? [raw] : undefined /* raw has not changed */, this.logService); this._restrictedConfigurations = restricted || []; } - private doParseContent(content: string): any { - let raw: any = {}; + private doParseContent(content: string): IStringDictionary { + let raw: IStringDictionary = {}; let currentProperty: string | null = null; - let currentParent: any = []; - const previousParents: any[] = []; + let currentParent: unknown[] | IStringDictionary = []; + const previousParents: (unknown[] | IStringDictionary)[] = []; const parseErrors: json.ParseError[] = []; - function onValue(value: any) { + function onValue(value: unknown) { if (Array.isArray(currentParent)) { currentParent.push(value); } else if (currentProperty !== null) { @@ -374,17 +385,17 @@ export class ConfigurationModelParser { currentProperty = name; }, onObjectEnd: () => { - currentParent = previousParents.pop(); + currentParent = previousParents.pop()!; }, onArrayBegin: () => { - const array: any[] = []; + const array: unknown[] = []; onValue(array); previousParents.push(currentParent); currentParent = array; currentProperty = null; }, onArrayEnd: () => { - currentParent = previousParents.pop(); + currentParent = previousParents.pop()!; }, onLiteralValue: onValue, onError: (error: json.ParseErrorCode, offset: number, length: number) => { @@ -394,17 +405,17 @@ export class ConfigurationModelParser { if (content) { try { json.visit(content, visitor); - raw = currentParent[0] || {}; + raw = (currentParent[0] as IStringDictionary) || {}; } catch (e) { this.logService.error(`Error while parsing settings file ${this._name}: ${e}`); - this._parseErrors = [e]; + this._parseErrors = [e as json.ParseError]; } } return raw; } - protected doParseRaw(raw: any, options?: ConfigurationParseOptions): IConfigurationModel & { restricted?: string[]; hasExcludedProperties?: boolean } { + protected doParseRaw(raw: IStringDictionary, options?: ConfigurationParseOptions): IConfigurationModel & { restricted?: string[]; hasExcludedProperties?: boolean } { const registry = Registry.as(Extensions.Configuration); const configurationProperties = registry.getConfigurationProperties(); const excludedConfigurationProperties = registry.getExcludedConfigurationProperties(); @@ -416,16 +427,16 @@ export class ConfigurationModelParser { return { contents, keys, overrides, restricted: filtered.restricted, hasExcludedProperties: filtered.hasExcludedProperties }; } - private filter(properties: any, configurationProperties: IStringDictionary, excludedConfigurationProperties: IStringDictionary, filterOverriddenProperties: boolean, options?: ConfigurationParseOptions): { raw: {}; restricted: string[]; hasExcludedProperties: boolean } { + private filter(properties: IStringDictionary, configurationProperties: IStringDictionary, excludedConfigurationProperties: IStringDictionary, filterOverriddenProperties: boolean, options?: ConfigurationParseOptions): { raw: IStringDictionary; restricted: string[]; hasExcludedProperties: boolean } { let hasExcludedProperties = false; if (!options?.scopes && !options?.skipRestricted && !options?.skipUnregistered && !options?.exclude?.length) { return { raw: properties, restricted: [], hasExcludedProperties }; } - const raw: any = {}; + const raw: IStringDictionary = {}; const restricted: string[] = []; for (const key in properties) { if (OVERRIDE_PROPERTY_REGEX.test(key) && filterOverriddenProperties) { - const result = this.filter(properties[key], configurationProperties, excludedConfigurationProperties, false, options); + const result = this.filter(properties[key] as IStringDictionary, configurationProperties, excludedConfigurationProperties, false, options); raw[key] = result.raw; hasExcludedProperties = hasExcludedProperties || result.hasExcludedProperties; restricted.push(...result.restricted); @@ -470,13 +481,14 @@ export class ConfigurationModelParser { return options.scopes.includes(scope); } - private toOverrides(raw: any, conflictReporter: (message: string) => void): IOverrides[] { + private toOverrides(raw: IStringDictionary, conflictReporter: (message: string) => void): IOverrides[] { const overrides: IOverrides[] = []; for (const key of Object.keys(raw)) { if (OVERRIDE_PROPERTY_REGEX.test(key)) { - const overrideRaw: any = {}; - for (const keyInOverrideRaw in raw[key]) { - overrideRaw[keyInOverrideRaw] = raw[key][keyInOverrideRaw]; + const overrideRaw: IStringDictionary = {}; + const rawKey = raw[key] as IStringDictionary; + for (const keyInOverrideRaw in rawKey) { + overrideRaw[keyInOverrideRaw] = rawKey[keyInOverrideRaw]; } overrides.push({ identifiers: overrideIdentifiersFromKey(key), @@ -729,12 +741,12 @@ export class Configuration { ) { } - getValue(section: string | undefined, overrides: IConfigurationOverrides, workspace: Workspace | undefined): any { + getValue(section: string | undefined, overrides: IConfigurationOverrides, workspace: Workspace | undefined): unknown { const consolidateConfigurationModel = this.getConsolidatedConfigurationModel(section, overrides, workspace); return consolidateConfigurationModel.getValue(section); } - updateValue(key: string, value: any, overrides: IConfigurationUpdateOverrides = {}): void { + updateValue(key: string, value: unknown, overrides: IConfigurationUpdateOverrides = {}): void { let memoryConfiguration: ConfigurationModel | undefined; if (overrides.resource) { memoryConfiguration = this._memoryConfigurationByResource.get(overrides.resource); @@ -1262,7 +1274,7 @@ function compare(from: ConfigurationModel | undefined, to: ConfigurationModel | return { added, removed, updated, overrides }; } -function compareConfigurationContents(to: { keys: string[]; contents: any } | undefined, from: { keys: string[]; contents: any } | undefined) { +function compareConfigurationContents(to: { keys: string[]; contents: IStringDictionary } | undefined, from: { keys: string[]; contents: IStringDictionary } | undefined) { const added = to ? from ? to.keys.filter(key => from.keys.indexOf(key) === -1) : [...to.keys] : []; diff --git a/src/vs/platform/configuration/common/configurationRegistry.ts b/src/vs/platform/configuration/common/configurationRegistry.ts index cdcbf0ae3f6..c7ba82fc678 100644 --- a/src/vs/platform/configuration/common/configurationRegistry.ts +++ b/src/vs/platform/configuration/common/configurationRegistry.ts @@ -258,7 +258,7 @@ export interface IConfigurationNode { export type ConfigurationDefaultValueSource = IExtensionInfo | Map; export interface IConfigurationDefaults { - overrides: IStringDictionary; + overrides: IStringDictionary; source?: IExtensionInfo; } @@ -269,18 +269,18 @@ export type IRegisteredConfigurationPropertySchema = IConfigurationPropertySchem order?: number; extensionInfo?: IExtensionInfo; }; - defaultDefaultValue?: any; + defaultDefaultValue?: unknown; source?: IExtensionInfo; // Source of the Property defaultValueSource?: ConfigurationDefaultValueSource; // Source of the Default Value }; export interface IConfigurationDefaultOverride { - readonly value: any; + readonly value: unknown; readonly source?: IExtensionInfo; // Source of the default override } export interface IConfigurationDefaultOverrideValue { - readonly value: any; + readonly value: unknown; readonly source?: ConfigurationDefaultValueSource; } @@ -397,7 +397,7 @@ class ConfigurationRegistry extends Disposable implements IConfigurationRegistry // Configuration defaults for Override Identifiers if (OVERRIDE_PROPERTY_REGEX.test(key)) { - const newDefaultOverride = this.mergeDefaultConfigurationsForOverrideIdentifier(key, value, source, configurationDefaultOverridesForKey.configurationDefaultOverrideValue); + const newDefaultOverride = this.mergeDefaultConfigurationsForOverrideIdentifier(key, value as IStringDictionary, source, configurationDefaultOverridesForKey.configurationDefaultOverrideValue); if (!newDefaultOverride) { continue; } @@ -464,7 +464,7 @@ class ConfigurationRegistry extends Disposable implements IConfigurationRegistry if (OVERRIDE_PROPERTY_REGEX.test(key)) { let configurationDefaultOverrideValue: IConfigurationDefaultOverrideValue | undefined; for (const configurationDefaultOverride of configurationDefaultOverridesForKey.configurationDefaultOverrides) { - configurationDefaultOverrideValue = this.mergeDefaultConfigurationsForOverrideIdentifier(key, configurationDefaultOverride.value, configurationDefaultOverride.source, configurationDefaultOverrideValue); + configurationDefaultOverrideValue = this.mergeDefaultConfigurationsForOverrideIdentifier(key, configurationDefaultOverride.value as IStringDictionary, configurationDefaultOverride.source, configurationDefaultOverrideValue); } if (configurationDefaultOverrideValue && !types.isEmptyObject(configurationDefaultOverrideValue.value)) { configurationDefaultOverridesForKey.configurationDefaultOverrideValue = configurationDefaultOverrideValue; @@ -512,7 +512,7 @@ class ConfigurationRegistry extends Disposable implements IConfigurationRegistry this.defaultLanguageConfigurationOverridesNode.properties![key] = property; } - private mergeDefaultConfigurationsForOverrideIdentifier(overrideIdentifier: string, configurationValueObject: IStringDictionary, valueSource: IExtensionInfo | undefined, existingDefaultOverride: IConfigurationDefaultOverrideValue | undefined): IConfigurationDefaultOverrideValue | undefined { + private mergeDefaultConfigurationsForOverrideIdentifier(overrideIdentifier: string, configurationValueObject: IStringDictionary, valueSource: IExtensionInfo | undefined, existingDefaultOverride: IConfigurationDefaultOverrideValue | undefined): IConfigurationDefaultOverrideValue | undefined { const defaultValue = existingDefaultOverride?.value || {}; const source = existingDefaultOverride?.source ?? new Map(); @@ -526,11 +526,11 @@ class ConfigurationRegistry extends Disposable implements IConfigurationRegistry const propertyDefaultValue = configurationValueObject[propertyKey]; const isObjectSetting = types.isObject(propertyDefaultValue) && - (types.isUndefined(defaultValue[propertyKey]) || types.isObject(defaultValue[propertyKey])); + (types.isUndefined((defaultValue as IStringDictionary)[propertyKey]) || types.isObject((defaultValue as IStringDictionary)[propertyKey])); // If the default value is an object, merge the objects and store the source of each keys if (isObjectSetting) { - defaultValue[propertyKey] = { ...(defaultValue[propertyKey] ?? {}), ...propertyDefaultValue }; + (defaultValue as IStringDictionary)[propertyKey] = { ...((defaultValue as IStringDictionary)[propertyKey] ?? {}), ...propertyDefaultValue }; // Track the source of each value in the object if (valueSource) { for (const objectKey in propertyDefaultValue) { @@ -541,7 +541,7 @@ class ConfigurationRegistry extends Disposable implements IConfigurationRegistry // Primitive values are overridden else { - defaultValue[propertyKey] = propertyDefaultValue; + (defaultValue as IStringDictionary)[propertyKey] = propertyDefaultValue; if (valueSource) { source.set(propertyKey, valueSource); } else { @@ -553,7 +553,7 @@ class ConfigurationRegistry extends Disposable implements IConfigurationRegistry return { value: defaultValue, source }; } - private mergeDefaultConfigurationsForConfigurationProperty(propertyKey: string, value: any, valuesSource: IExtensionInfo | undefined, existingDefaultOverride: IConfigurationDefaultOverrideValue | undefined): IConfigurationDefaultOverrideValue | undefined { + private mergeDefaultConfigurationsForConfigurationProperty(propertyKey: string, value: unknown, valuesSource: IExtensionInfo | undefined, existingDefaultOverride: IConfigurationDefaultOverrideValue | undefined): IConfigurationDefaultOverrideValue | undefined { const property = this.configurationProperties[propertyKey]; const existingDefaultValue = existingDefaultOverride?.value ?? property?.defaultDefaultValue; let source: ConfigurationDefaultValueSource | undefined = valuesSource; @@ -574,12 +574,12 @@ class ConfigurationRegistry extends Disposable implements IConfigurationRegistry return undefined; } - for (const objectKey in value) { + for (const objectKey in (value as IStringDictionary)) { if (valuesSource) { source.set(`${propertyKey}.${objectKey}`, valuesSource); } } - value = { ...(types.isObject(existingDefaultValue) ? existingDefaultValue : {}), ...value }; + value = { ...(types.isObject(existingDefaultValue) ? existingDefaultValue : {}), ...(value as IStringDictionary) }; } return { value, source }; diff --git a/src/vs/platform/configuration/common/configurationService.ts b/src/vs/platform/configuration/common/configurationService.ts index dc47c790348..f832d9fd359 100644 --- a/src/vs/platform/configuration/common/configurationService.ts +++ b/src/vs/platform/configuration/common/configurationService.ts @@ -93,21 +93,21 @@ export class ConfigurationService extends Disposable implements IConfigurationSe getValue(section: string): T; getValue(overrides: IConfigurationOverrides): T; getValue(section: string, overrides: IConfigurationOverrides): T; - getValue(arg1?: any, arg2?: any): any { + getValue(arg1?: unknown, arg2?: unknown): unknown { const section = typeof arg1 === 'string' ? arg1 : undefined; const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {}; return this.configuration.getValue(section, overrides, undefined); } - updateValue(key: string, value: any): Promise; - updateValue(key: string, value: any, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise; - updateValue(key: string, value: any, target: ConfigurationTarget): Promise; - updateValue(key: string, value: any, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise; - async updateValue(key: string, value: any, arg3?: any, arg4?: any, options?: any): Promise { + updateValue(key: string, value: unknown): Promise; + updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise; + updateValue(key: string, value: unknown, target: ConfigurationTarget): Promise; + updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise; + async updateValue(key: string, value: unknown, arg3?: unknown, arg4?: unknown, options?: IConfigurationUpdateOptions): Promise { const overrides: IConfigurationUpdateOverrides | undefined = isConfigurationUpdateOverrides(arg3) ? arg3 : isConfigurationOverrides(arg3) ? { resource: arg3.resource, overrideIdentifiers: arg3.overrideIdentifier ? [arg3.overrideIdentifier] : undefined } : undefined; - const target: ConfigurationTarget | undefined = overrides ? arg4 : arg3; + const target: ConfigurationTarget | undefined = (overrides ? arg4 : arg3) as ConfigurationTarget | undefined; if (target !== undefined) { if (target !== ConfigurationTarget.USER_LOCAL && target !== ConfigurationTarget.USER) { throw new Error(`Unable to write ${key} to target ${target}.`); @@ -199,11 +199,11 @@ class ConfigurationEditing { this.queue = new Queue(); } - write(path: JSONPath, value: any): Promise { + write(path: JSONPath, value: unknown): Promise { return this.queue.queue(() => this.doWriteConfiguration(path, value)); // queue up writes to prevent race conditions } - private async doWriteConfiguration(path: JSONPath, value: any): Promise { + private async doWriteConfiguration(path: JSONPath, value: unknown): Promise { let content: string; try { const fileContent = await this.fileService.readFile(this.settingsResource); @@ -228,7 +228,7 @@ class ConfigurationEditing { await this.fileService.writeFile(this.settingsResource, VSBuffer.fromString(content)); } - private getEdits(content: string, path: JSONPath, value: any): Edit[] { + private getEdits(content: string, path: JSONPath, value: unknown): Edit[] { const { tabSize, insertSpaces, eol } = this.formattingOptions; // With empty path the entire file is being replaced, so we just use JSON.stringify diff --git a/src/vs/platform/configuration/common/configurations.ts b/src/vs/platform/configuration/common/configurations.ts index 618f417c765..e769804c41d 100644 --- a/src/vs/platform/configuration/common/configurations.ts +++ b/src/vs/platform/configuration/common/configurations.ts @@ -12,7 +12,7 @@ import { isEmptyObject, isString } from '../../../base/common/types.js'; import { ConfigurationModel } from './configurationModels.js'; import { Extensions, IConfigurationRegistry, IRegisteredConfigurationPropertySchema } from './configurationRegistry.js'; import { ILogService, NullLogService } from '../../log/common/log.js'; -import { IPolicyService, PolicyDefinition } from '../../policy/common/policy.js'; +import { IPolicyService, PolicyDefinition, PolicyValue } from '../../policy/common/policy.js'; import { Registry } from '../../registry/common/platform.js'; import { getErrorMessage } from '../../../base/common/errors.js'; import * as json from '../../../base/common/json.js'; @@ -49,7 +49,7 @@ export class DefaultConfiguration extends Disposable { this._onDidChangeConfiguration.fire({ defaults: this.configurationModel, properties }); } - protected getConfigurationDefaultOverrides(): IStringDictionary { + protected getConfigurationDefaultOverrides(): IStringDictionary { return {}; } @@ -88,6 +88,8 @@ export class NullPolicyConfiguration implements IPolicyConfiguration { async initialize() { return this.configurationModel; } } +type ParsedType = IStringDictionary | Array; + export class PolicyConfiguration extends Disposable implements IPolicyConfiguration { private readonly _onDidChangeConfiguration = this._register(new Emitter()); @@ -164,14 +166,14 @@ export class PolicyConfiguration extends Disposable implements IPolicyConfigurat this.logService.trace('PolicyConfiguration#update', keys); const configurationProperties = this.configurationRegistry.getConfigurationProperties(); const excludedConfigurationProperties = this.configurationRegistry.getExcludedConfigurationProperties(); - const changed: [string, any][] = []; + const changed: [string, unknown][] = []; const wasEmpty = this._configurationModel.isEmpty(); for (const key of keys) { const proprety = configurationProperties[key] ?? excludedConfigurationProperties[key]; const policyName = proprety?.policy?.name; if (policyName) { - let policyValue = this.policyService.getPolicyValue(policyName); + let policyValue: PolicyValue | ParsedType | undefined = this.policyService.getPolicyValue(policyName); if (isString(policyValue) && proprety.type !== 'string') { try { policyValue = this.parse(policyValue); @@ -210,14 +212,14 @@ export class PolicyConfiguration extends Disposable implements IPolicyConfigurat } } - private parse(content: string): any { - let raw: any = {}; + private parse(content: string): ParsedType { + let raw: ParsedType = {}; let currentProperty: string | null = null; - let currentParent: any = []; - const previousParents: any[] = []; + let currentParent: ParsedType = []; + const previousParents: Array = []; const parseErrors: json.ParseError[] = []; - function onValue(value: any) { + function onValue(value: unknown) { if (Array.isArray(currentParent)) { currentParent.push(value); } else if (currentProperty !== null) { @@ -240,17 +242,17 @@ export class PolicyConfiguration extends Disposable implements IPolicyConfigurat currentProperty = name; }, onObjectEnd: () => { - currentParent = previousParents.pop(); + currentParent = previousParents.pop()!; }, onArrayBegin: () => { - const array: any[] = []; + const array: unknown[] = []; onValue(array); previousParents.push(currentParent); currentParent = array; currentProperty = null; }, onArrayEnd: () => { - currentParent = previousParents.pop(); + currentParent = previousParents.pop()!; }, onLiteralValue: onValue, onError: (error: json.ParseErrorCode, offset: number, length: number) => { @@ -260,7 +262,7 @@ export class PolicyConfiguration extends Disposable implements IPolicyConfigurat if (content) { json.visit(content, visitor); - raw = currentParent[0] || {}; + raw = (currentParent[0] as ParsedType | undefined) || raw; } if (parseErrors.length > 0) { diff --git a/src/vs/platform/configuration/test/common/configurationModels.test.ts b/src/vs/platform/configuration/test/common/configurationModels.test.ts index a50178e7e81..c6993dfaa07 100644 --- a/src/vs/platform/configuration/test/common/configurationModels.test.ts +++ b/src/vs/platform/configuration/test/common/configurationModels.test.ts @@ -508,7 +508,8 @@ suite('ConfigurationModel', () => { test('get overriding configuration if the value of overriding identifier is not object', () => { const testObject = new ConfigurationModel( { 'a': { 'b': 1 }, 'f': { 'g': 1 } }, [], - [{ identifiers: ['c'], contents: 'abc', keys: [] }], [], new NullLogService()); + // eslint-disable-next-line local/code-no-any-casts + [{ identifiers: ['c'], contents: 'abc' as any, keys: [] }], [], new NullLogService()); assert.deepStrictEqual(testObject.override('c').contents, { 'a': { 'b': 1 }, 'f': { 'g': 1 } }); }); diff --git a/src/vs/workbench/api/common/configurationExtensionPoint.ts b/src/vs/workbench/api/common/configurationExtensionPoint.ts index 53177fb9eba..68efbd805de 100644 --- a/src/vs/workbench/api/common/configurationExtensionPoint.ts +++ b/src/vs/workbench/api/common/configurationExtensionPoint.ts @@ -152,7 +152,7 @@ let _configDelta: IConfigurationDelta | undefined; // BEGIN VSCode extension point `configurationDefaults` -const defaultConfigurationExtPoint = ExtensionsRegistry.registerExtensionPoint({ +const defaultConfigurationExtPoint = ExtensionsRegistry.registerExtensionPoint>>({ extensionPoint: 'configurationDefaults', jsonSchema: { $ref: configurationDefaultsSchemaId, @@ -183,7 +183,7 @@ defaultConfigurationExtPoint.setHandler((extensions, { added, removed }) => { const registeredProperties = configurationRegistry.getConfigurationProperties(); const allowedScopes = [ConfigurationScope.MACHINE_OVERRIDABLE, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE, ConfigurationScope.LANGUAGE_OVERRIDABLE]; const addedDefaultConfigurations = added.map(extension => { - const overrides: IStringDictionary = objects.deepClone(extension.value); + const overrides = objects.deepClone(extension.value); for (const key of Object.keys(overrides)) { const registeredPropertyScheme = registeredProperties[key]; if (registeredPropertyScheme?.disallowConfigurationDefault) { @@ -242,7 +242,7 @@ configurationExtPoint.setHandler((extensions, { added, removed }) => { const seenProperties = new Set(); - function handleConfiguration(node: IConfigurationNode, extension: IExtensionPointUser): IConfigurationNode { + function handleConfiguration(node: IConfigurationNode, extension: IExtensionPointUser): IConfigurationNode { const configuration = objects.deepClone(node); if (configuration.title && (typeof configuration.title !== 'string')) { @@ -258,7 +258,7 @@ configurationExtPoint.setHandler((extensions, { added, removed }) => { return configuration; } - function validateProperties(configuration: IConfigurationNode, extension: IExtensionPointUser): void { + function validateProperties(configuration: IConfigurationNode, extension: IExtensionPointUser): void { const properties = configuration.properties; const extensionConfigurationPolicy = product.extensionConfigurationPolicy; if (properties) { diff --git a/src/vs/workbench/api/common/extHostConfiguration.ts b/src/vs/workbench/api/common/extHostConfiguration.ts index 425d303ff88..d166a1974b3 100644 --- a/src/vs/workbench/api/common/extHostConfiguration.ts +++ b/src/vs/workbench/api/common/extHostConfiguration.ts @@ -21,15 +21,16 @@ import { ILogService } from '../../../platform/log/common/log.js'; import { Workspace } from '../../../platform/workspace/common/workspace.js'; import { URI } from '../../../base/common/uri.js'; -function lookUp(tree: any, key: string) { +function lookUp(tree: unknown, key: string) { if (key) { const parts = key.split('.'); let node = tree; for (let i = 0; node && i < parts.length; i++) { - node = node[parts[i]]; + node = (node as Record)[parts[i]]; } return node; } + return undefined; } export type ConfigurationInspect = { @@ -52,27 +53,29 @@ export type ConfigurationInspect = { languageIds?: string[]; }; -function isUri(thing: any): thing is vscode.Uri { +function isUri(thing: unknown): thing is vscode.Uri { return thing instanceof URI; } -function isResourceLanguage(thing: any): thing is { uri: URI; languageId: string } { - return thing - && thing.uri instanceof URI - && (thing.languageId && typeof thing.languageId === 'string'); +function isResourceLanguage(thing: unknown): thing is { uri: URI; languageId: string } { + return isObject(thing) + && (thing as Record).uri instanceof URI + && !!(thing as Record).languageId + && typeof (thing as Record).languageId === 'string'; } -function isLanguage(thing: any): thing is { languageId: string } { - return thing - && !thing.uri - && (thing.languageId && typeof thing.languageId === 'string'); +function isLanguage(thing: unknown): thing is { languageId: string } { + return isObject(thing) + && !(thing as Record).uri + && !!(thing as Record).languageId + && typeof (thing as Record).languageId === 'string'; } -function isWorkspaceFolder(thing: any): thing is vscode.WorkspaceFolder { - return thing - && thing.uri instanceof URI - && (!thing.name || typeof thing.name === 'string') - && (!thing.index || typeof thing.index === 'number'); +function isWorkspaceFolder(thing: unknown): thing is vscode.WorkspaceFolder { + return isObject(thing) + && (thing as Record).uri instanceof URI + && (!(thing as Record).name || typeof (thing as Record).name === 'string') + && (!(thing as Record).index || typeof (thing as Record).index === 'number'); } function scopeToOverrides(scope: vscode.ConfigurationScope | undefined | null): IConfigurationOverrides | undefined { @@ -187,52 +190,52 @@ export class ExtHostConfigProvider { }, get: (key: string, defaultValue?: T) => { this._validateConfigurationAccess(section ? `${section}.${key}` : key, overrides, extensionDescription?.identifier); - let result = lookUp(config, key); + let result: unknown = lookUp(config, key); if (typeof result === 'undefined') { result = defaultValue; } else { - let clonedConfig: any | undefined = undefined; - const cloneOnWriteProxy = (target: any, accessor: string): any => { + let clonedConfig: unknown | undefined = undefined; + const cloneOnWriteProxy = (target: unknown, accessor: string): unknown => { if (isObject(target)) { - let clonedTarget: any | undefined = undefined; + let clonedTarget: unknown | undefined = undefined; const cloneTarget = () => { clonedConfig = clonedConfig ? clonedConfig : deepClone(config); clonedTarget = clonedTarget ? clonedTarget : lookUp(clonedConfig, accessor); }; return new Proxy(target, { - get: (target: any, property: PropertyKey) => { + get: (target: Record, property: PropertyKey) => { if (typeof property === 'string' && property.toLowerCase() === 'tojson') { cloneTarget(); return () => clonedTarget; } if (clonedConfig) { clonedTarget = clonedTarget ? clonedTarget : lookUp(clonedConfig, accessor); - return clonedTarget[property]; + return (clonedTarget as Record)[property]; } - const result = target[property]; + const result = (target as Record)[property]; if (typeof property === 'string') { return cloneOnWriteProxy(result, `${accessor}.${property}`); } return result; }, - set: (_target: any, property: PropertyKey, value: any) => { + set: (_target: Record, property: PropertyKey, value: unknown) => { cloneTarget(); if (clonedTarget) { - clonedTarget[property] = value; + (clonedTarget as Record)[property] = value; } return true; }, - deleteProperty: (_target: any, property: PropertyKey) => { + deleteProperty: (_target: Record, property: PropertyKey) => { cloneTarget(); if (clonedTarget) { - delete clonedTarget[property]; + delete (clonedTarget as Record)[property]; } return true; }, - defineProperty: (_target: any, property: PropertyKey, descriptor: any) => { + defineProperty: (_target: Record, property: PropertyKey, descriptor: PropertyDescriptor) => { cloneTarget(); if (clonedTarget) { - Object.defineProperty(clonedTarget, property, descriptor); + Object.defineProperty(clonedTarget as Record, property, descriptor); } return true; } @@ -291,14 +294,14 @@ export class ExtHostConfigProvider { return Object.freeze(result); } - private _toReadonlyValue(result: any): any { - const readonlyProxy = (target: any): any => { + private _toReadonlyValue(result: unknown): unknown { + const readonlyProxy = (target: unknown): unknown => { return isObject(target) ? new Proxy(target, { - get: (target: any, property: PropertyKey) => readonlyProxy(target[property]), - set: (_target: any, property: PropertyKey, _value: any) => { throw new Error(`TypeError: Cannot assign to read only property '${String(property)}' of object`); }, - deleteProperty: (_target: any, property: PropertyKey) => { throw new Error(`TypeError: Cannot delete read only property '${String(property)}' of object`); }, - defineProperty: (_target: any, property: PropertyKey) => { throw new Error(`TypeError: Cannot define property '${String(property)}' for a readonly object`); }, + get: (target: Record, property: PropertyKey) => readonlyProxy((target as Record)[property]), + set: (_target: Record, property: PropertyKey, _value: unknown) => { throw new Error(`TypeError: Cannot assign to read only property '${String(property)}' of object`); }, + deleteProperty: (_target: Record, property: PropertyKey) => { throw new Error(`TypeError: Cannot delete read only property '${String(property)}' of object`); }, + defineProperty: (_target: Record, property: PropertyKey) => { throw new Error(`TypeError: Cannot define property '${String(property)}' for a readonly object`); }, setPrototypeOf: (_target: unknown) => { throw new Error(`TypeError: Cannot set prototype for a readonly object`); }, isExtensible: () => false, preventExtensions: () => true diff --git a/src/vs/workbench/services/configuration/browser/configuration.ts b/src/vs/workbench/services/configuration/browser/configuration.ts index 011aa62a24a..c4027279f98 100644 --- a/src/vs/workbench/services/configuration/browser/configuration.ts +++ b/src/vs/workbench/services/configuration/browser/configuration.ts @@ -34,7 +34,7 @@ export class DefaultConfiguration extends BaseDefaultConfiguration { static readonly DEFAULT_OVERRIDES_CACHE_EXISTS_KEY = 'DefaultOverridesCacheExists'; private readonly configurationRegistry = Registry.as(Extensions.Configuration); - private cachedConfigurationDefaultsOverrides: IStringDictionary = {}; + private cachedConfigurationDefaultsOverrides: IStringDictionary = {}; private readonly cacheKey: ConfigurationKey = { type: 'defaults', key: 'configurationDefaultsOverrides' }; constructor( @@ -44,11 +44,11 @@ export class DefaultConfiguration extends BaseDefaultConfiguration { ) { super(logService); if (environmentService.options?.configurationDefaults) { - this.configurationRegistry.registerDefaultConfigurations([{ overrides: environmentService.options.configurationDefaults }]); + this.configurationRegistry.registerDefaultConfigurations([{ overrides: environmentService.options.configurationDefaults as IStringDictionary> }]); } } - protected override getConfigurationDefaultOverrides(): IStringDictionary { + protected override getConfigurationDefaultOverrides(): IStringDictionary { return this.cachedConfigurationDefaultsOverrides; } @@ -94,7 +94,7 @@ export class DefaultConfiguration extends BaseDefaultConfiguration { } private async updateCachedConfigurationDefaultsOverrides(): Promise { - const cachedConfigurationDefaultsOverrides: IStringDictionary = {}; + const cachedConfigurationDefaultsOverrides: IStringDictionary = {}; const configurationDefaultsOverrides = this.configurationRegistry.getConfigurationDefaultsOverrides(); for (const [key, value] of configurationDefaultsOverrides) { if (!OVERRIDE_PROPERTY_REGEX.test(key) && value.value !== undefined) { @@ -964,7 +964,7 @@ class CachedFolderConfiguration { } async updateConfiguration(settingsContent: string | undefined, standAloneConfigurationContents: [string, string | undefined][]): Promise { - const content: any = {}; + const content: IStringDictionary = {}; if (settingsContent) { content[FOLDER_SETTINGS_NAME] = settingsContent; } diff --git a/src/vs/workbench/services/configuration/browser/configurationService.ts b/src/vs/workbench/services/configuration/browser/configurationService.ts index f7b58d5891f..ecbfc79a45a 100644 --- a/src/vs/workbench/services/configuration/browser/configurationService.ts +++ b/src/vs/workbench/services/configuration/browser/configurationService.ts @@ -325,20 +325,20 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat getValue(section: string): T; getValue(overrides: IConfigurationOverrides): T; getValue(section: string, overrides: IConfigurationOverrides): T; - getValue(arg1?: any, arg2?: any): any { + getValue(arg1?: unknown, arg2?: unknown): unknown { const section = typeof arg1 === 'string' ? arg1 : undefined; const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : undefined; return this._configuration.getValue(section, overrides); } - updateValue(key: string, value: any): Promise; + updateValue(key: string, value: unknown): Promise; updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise; updateValue(key: string, value: unknown, target: ConfigurationTarget): Promise; updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise; - async updateValue(key: string, value: unknown, arg3?: any, arg4?: any, options?: any): Promise { + async updateValue(key: string, value: unknown, arg3?: unknown, arg4?: unknown, options?: IConfigurationUpdateOptions): Promise { const overrides: IConfigurationUpdateOverrides | undefined = isConfigurationUpdateOverrides(arg3) ? arg3 : isConfigurationOverrides(arg3) ? { resource: arg3.resource, overrideIdentifiers: arg3.overrideIdentifier ? [arg3.overrideIdentifier] : undefined } : undefined; - const target: ConfigurationTarget | undefined = overrides ? arg4 : arg3; + const target: ConfigurationTarget | undefined = (overrides ? arg4 : arg3) as ConfigurationTarget | undefined; const targets: ConfigurationTarget[] = target ? [target] : []; if (overrides?.overrideIdentifiers) { @@ -997,7 +997,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat return validWorkspaceFolders; } - private async writeConfigurationValue(key: string, value: unknown, target: ConfigurationTarget, overrides: IConfigurationUpdateOverrides | undefined, options?: IConfigurationUpdateOverrides): Promise { + private async writeConfigurationValue(key: string, value: unknown, target: ConfigurationTarget, overrides: IConfigurationUpdateOverrides | undefined, options?: IConfigurationUpdateOptions): Promise { if (!this.instantiationService) { throw new Error('Cannot write configuration because the configuration service is not yet ready to accept writes.'); } @@ -1081,7 +1081,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat } } - private deriveConfigurationTargets(key: string, value: unknown, inspect: IConfigurationValue): ConfigurationTarget[] { + private deriveConfigurationTargets(key: string, value: unknown, inspect: IConfigurationValue): ConfigurationTarget[] { if (equals(value, inspect.value)) { return []; } @@ -1374,7 +1374,7 @@ class ConfigurationDefaultOverridesContribution extends Disposable implements IW } private async processExperimentalSettings(properties: Iterable, autoRefetch: boolean): Promise { - const overrides: IStringDictionary = {}; + const overrides: IStringDictionary = {}; const allProperties = this.configurationRegistry.getConfigurationProperties(); for (const property of properties) { const schema = allProperties[property]; diff --git a/src/vs/workbench/services/configuration/common/configurationModels.ts b/src/vs/workbench/services/configuration/common/configurationModels.ts index c73a1e38999..453ccbb7034 100644 --- a/src/vs/workbench/services/configuration/common/configurationModels.ts +++ b/src/vs/workbench/services/configuration/common/configurationModels.ts @@ -13,6 +13,7 @@ import { URI } from '../../../../base/common/uri.js'; import { isBoolean } from '../../../../base/common/types.js'; import { distinct } from '../../../../base/common/arrays.js'; import { ILogService } from '../../../../platform/log/common/log.js'; +import { IStringDictionary } from '../../../../base/common/collections.js'; export class WorkspaceConfigurationModelParser extends ConfigurationModelParser { @@ -57,17 +58,17 @@ export class WorkspaceConfigurationModelParser extends ConfigurationModelParser return this._settingsModelParser.restrictedConfigurations; } - protected override doParseRaw(raw: any, configurationParseOptions?: ConfigurationParseOptions): IConfigurationModel { + protected override doParseRaw(raw: IStringDictionary, configurationParseOptions?: ConfigurationParseOptions): IConfigurationModel { this._folders = (raw['folders'] || []) as IStoredWorkspaceFolder[]; this._transient = isBoolean(raw['transient']) && raw['transient']; - this._settingsModelParser.parseRaw(raw['settings'], configurationParseOptions); + this._settingsModelParser.parseRaw(raw['settings'] as IStringDictionary, configurationParseOptions); this._launchModel = this.createConfigurationModelFrom(raw, 'launch'); this._tasksModel = this.createConfigurationModelFrom(raw, 'tasks'); return super.doParseRaw(raw, configurationParseOptions); } - private createConfigurationModelFrom(raw: any, key: string): ConfigurationModel { - const data = raw[key]; + private createConfigurationModelFrom(raw: IStringDictionary, key: string): ConfigurationModel { + const data = raw[key] as IStringDictionary | undefined; if (data) { const contents = toValuesTree(data, message => console.error(`Conflict in settings file ${this._name}: ${message}`)); const scopedContents = Object.create(null); @@ -85,7 +86,7 @@ export class StandaloneConfigurationModelParser extends ConfigurationModelParser super(name, logService); } - protected override doParseRaw(raw: any, configurationParseOptions?: ConfigurationParseOptions): IConfigurationModel { + protected override doParseRaw(raw: IStringDictionary, configurationParseOptions?: ConfigurationParseOptions): IConfigurationModel { const contents = toValuesTree(raw, message => console.error(`Conflict in settings file ${this._name}: ${message}`)); const scopedContents = Object.create(null); scopedContents[this.scope] = contents; @@ -113,7 +114,7 @@ export class Configuration extends BaseConfiguration { super(defaults, policy, application, localUser, remoteUser, workspaceConfiguration, folders, memoryConfiguration, memoryConfigurationByResource, logService); } - override getValue(key: string | undefined, overrides: IConfigurationOverrides = {}): any { + override getValue(key: string | undefined, overrides: IConfigurationOverrides = {}): unknown { return super.getValue(key, overrides, this._workspace); }