mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
remove any type usage (#276948)
* remove any type usage * bring back configuration resolver * fix test
This commit is contained in:
committed by
GitHub
parent
94c8fb6ec3
commit
3c2d88de10
@@ -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',
|
||||
|
||||
@@ -13,7 +13,8 @@ import { IWorkspaceFolder } from '../../workspace/common/workspace.js';
|
||||
|
||||
export const IConfigurationService = createDecorator<IConfigurationService>('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<void>;
|
||||
updateValue(key: string, value: any, target: ConfigurationTarget): Promise<void>;
|
||||
updateValue(key: string, value: any, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise<void>;
|
||||
updateValue(key: string, value: any, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise<void>;
|
||||
updateValue(key: string, value: unknown): Promise<void>;
|
||||
updateValue(key: string, value: unknown, target: ConfigurationTarget): Promise<void>;
|
||||
updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise<void>;
|
||||
updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise<void>;
|
||||
|
||||
inspect<T>(key: string, overrides?: IConfigurationOverrides): IConfigurationValue<Readonly<T>>;
|
||||
|
||||
@@ -205,15 +207,15 @@ export interface IConfigurationService {
|
||||
}
|
||||
|
||||
export interface IConfigurationModel {
|
||||
contents: any;
|
||||
contents: IStringDictionary<unknown>;
|
||||
keys: string[];
|
||||
overrides: IOverrides[];
|
||||
raw?: IStringDictionary<any>;
|
||||
raw?: ReadonlyArray<IStringDictionary<unknown>> | IStringDictionary<unknown>;
|
||||
}
|
||||
|
||||
export interface IOverrides {
|
||||
keys: string[];
|
||||
contents: any;
|
||||
contents: IStringDictionary<unknown>;
|
||||
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<unknown>, conflictReporter: (message: string) => void): IStringDictionary<unknown> {
|
||||
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<unknown>, key: string, value: unknown, conflictReporter: (message: string) => void): void {
|
||||
const segments = key.split('.');
|
||||
const last = segments.pop()!;
|
||||
|
||||
let curr = settingsTreeRoot;
|
||||
let curr: IStringDictionary<unknown> = 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<unknown>;
|
||||
}
|
||||
|
||||
if (typeof curr === 'object' && curr !== null) {
|
||||
try {
|
||||
curr[last] = value; // workaround https://github.com/microsoft/vscode/issues/13606
|
||||
(curr as IStringDictionary<unknown>)[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<unknown>, key: string): void {
|
||||
const segments = key.split('.');
|
||||
doRemoveFromValueTree(valueTree, segments);
|
||||
}
|
||||
|
||||
function doRemoveFromValueTree(valueTree: any, segments: string[]): void {
|
||||
function doRemoveFromValueTree(valueTree: IStringDictionary<unknown> | unknown, segments: string[]): void {
|
||||
if (!valueTree) {
|
||||
return;
|
||||
}
|
||||
|
||||
const valueTreeRecord = valueTree as IStringDictionary<unknown>;
|
||||
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<T>(config: any, settingPath: string): T | undefined;
|
||||
export function getConfigurationValue<T>(config: any, settingPath: string, defaultValue: T): T;
|
||||
export function getConfigurationValue<T>(config: any, settingPath: string, defaultValue?: T): T | undefined {
|
||||
function accessSetting(config: any, path: string[]): any {
|
||||
let current = config;
|
||||
export function getConfigurationValue<T>(config: IStringDictionary<unknown>, settingPath: string): T | undefined;
|
||||
export function getConfigurationValue<T>(config: IStringDictionary<unknown>, settingPath: string, defaultValue: T): T;
|
||||
export function getConfigurationValue<T>(config: IStringDictionary<unknown>, settingPath: string, defaultValue?: T): T | undefined {
|
||||
function accessSetting(config: IStringDictionary<unknown>, 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<unknown>)[component];
|
||||
}
|
||||
return <T>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<unknown>, add: IStringDictionary<unknown>, 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<unknown>, add[key] as IStringDictionary<unknown>, overwrite);
|
||||
} else if (overwrite) {
|
||||
base[key] = add[key];
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ export class ConfigurationModel implements IConfigurationModel {
|
||||
private readonly overrideConfigurations = new Map<string, ConfigurationModel>();
|
||||
|
||||
constructor(
|
||||
private readonly _contents: any,
|
||||
private readonly _contents: IStringDictionary<unknown>,
|
||||
private readonly _keys: string[],
|
||||
private readonly _overrides: IOverrides[],
|
||||
readonly raw: IStringDictionary<any> | ReadonlyArray<IStringDictionary<any> | ConfigurationModel> | undefined,
|
||||
private readonly _raw: IStringDictionary<unknown> | ReadonlyArray<IStringDictionary<unknown> | 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<unknown> {
|
||||
return this._contents;
|
||||
}
|
||||
|
||||
@@ -76,12 +76,22 @@ export class ConfigurationModel implements IConfigurationModel {
|
||||
return this._keys;
|
||||
}
|
||||
|
||||
get raw(): IStringDictionary<unknown> | IStringDictionary<unknown>[] | 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<unknown> | IStringDictionary<unknown>[];
|
||||
}
|
||||
|
||||
isEmpty(): boolean {
|
||||
return this._keys.length === 0 && Object.keys(this._contents).length === 0 && this._overrides.length === 0;
|
||||
}
|
||||
|
||||
getValue<V>(section: string | undefined): V {
|
||||
return section ? getConfigurationValue<any>(this.contents, section) : this.contents;
|
||||
getValue<V>(section: string | undefined): V | undefined {
|
||||
return section ? getConfigurationValue<V>(this.contents, section) : this.contents as V;
|
||||
}
|
||||
|
||||
inspect<V>(section: string | undefined, overrideIdentifier?: string | null): InspectValue<V> {
|
||||
@@ -112,7 +122,7 @@ export class ConfigurationModel implements IConfigurationModel {
|
||||
getOverrideValue<V>(section: string | undefined, overrideIdentifier: string): V | undefined {
|
||||
const overrideContents = this.getContentsForOverrideIdentifer(overrideIdentifier);
|
||||
return overrideContents
|
||||
? section ? getConfigurationValue<any>(overrideContents, section) : overrideContents
|
||||
? section ? getConfigurationValue<V>(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<unknown> = {};
|
||||
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<unknown>, overrideContentsForKey as IStringDictionary<unknown>);
|
||||
} 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<unknown>, target: IStringDictionary<unknown>): 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<unknown>, target[key] as IStringDictionary<unknown>);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -218,10 +228,10 @@ export class ConfigurationModel implements IConfigurationModel {
|
||||
}
|
||||
}
|
||||
|
||||
private getContentsForOverrideIdentifer(identifier: string): any {
|
||||
let contentsForIdentifierOnly: IStringDictionary<any> | null = null;
|
||||
let contents: IStringDictionary<any> | null = null;
|
||||
const mergeContents = (contentsToMerge: any) => {
|
||||
private getContentsForOverrideIdentifer(identifier: string): IStringDictionary<unknown> | null {
|
||||
let contentsForIdentifierOnly: IStringDictionary<unknown> | null = null;
|
||||
let contents: IStringDictionary<unknown> | null = null;
|
||||
const mergeContents = (contentsToMerge: IStringDictionary<unknown> | 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<unknown>;
|
||||
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<unknown> | 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<unknown>, 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<unknown> {
|
||||
let raw: IStringDictionary<unknown> = {};
|
||||
let currentProperty: string | null = null;
|
||||
let currentParent: any = [];
|
||||
const previousParents: any[] = [];
|
||||
let currentParent: unknown[] | IStringDictionary<unknown> = [];
|
||||
const previousParents: (unknown[] | IStringDictionary<unknown>)[] = [];
|
||||
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<unknown>) || {};
|
||||
} 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<unknown>, options?: ConfigurationParseOptions): IConfigurationModel & { restricted?: string[]; hasExcludedProperties?: boolean } {
|
||||
const registry = Registry.as<IConfigurationRegistry>(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<IRegisteredConfigurationPropertySchema>, excludedConfigurationProperties: IStringDictionary<IRegisteredConfigurationPropertySchema>, filterOverriddenProperties: boolean, options?: ConfigurationParseOptions): { raw: {}; restricted: string[]; hasExcludedProperties: boolean } {
|
||||
private filter(properties: IStringDictionary<unknown>, configurationProperties: IStringDictionary<IRegisteredConfigurationPropertySchema>, excludedConfigurationProperties: IStringDictionary<IRegisteredConfigurationPropertySchema>, filterOverriddenProperties: boolean, options?: ConfigurationParseOptions): { raw: IStringDictionary<unknown>; 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<unknown> = {};
|
||||
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<unknown>, 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<unknown>, 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<unknown> = {};
|
||||
const rawKey = raw[key] as IStringDictionary<unknown>;
|
||||
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<unknown> } | undefined, from: { keys: string[]; contents: IStringDictionary<unknown> } | undefined) {
|
||||
const added = to
|
||||
? from ? to.keys.filter(key => from.keys.indexOf(key) === -1) : [...to.keys]
|
||||
: [];
|
||||
|
||||
@@ -258,7 +258,7 @@ export interface IConfigurationNode {
|
||||
export type ConfigurationDefaultValueSource = IExtensionInfo | Map<string, IExtensionInfo>;
|
||||
|
||||
export interface IConfigurationDefaults {
|
||||
overrides: IStringDictionary<any>;
|
||||
overrides: IStringDictionary<unknown>;
|
||||
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<unknown>, 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<unknown>, 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<any>, valueSource: IExtensionInfo | undefined, existingDefaultOverride: IConfigurationDefaultOverrideValue | undefined): IConfigurationDefaultOverrideValue | undefined {
|
||||
private mergeDefaultConfigurationsForOverrideIdentifier(overrideIdentifier: string, configurationValueObject: IStringDictionary<unknown>, valueSource: IExtensionInfo | undefined, existingDefaultOverride: IConfigurationDefaultOverrideValue | undefined): IConfigurationDefaultOverrideValue | undefined {
|
||||
const defaultValue = existingDefaultOverride?.value || {};
|
||||
const source = existingDefaultOverride?.source ?? new Map<string, IExtensionInfo>();
|
||||
|
||||
@@ -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<unknown>)[propertyKey]) || types.isObject((defaultValue as IStringDictionary<unknown>)[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<unknown>)[propertyKey] = { ...((defaultValue as IStringDictionary<unknown>)[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<unknown>)[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<unknown>)) {
|
||||
if (valuesSource) {
|
||||
source.set(`${propertyKey}.${objectKey}`, valuesSource);
|
||||
}
|
||||
}
|
||||
value = { ...(types.isObject(existingDefaultValue) ? existingDefaultValue : {}), ...value };
|
||||
value = { ...(types.isObject(existingDefaultValue) ? existingDefaultValue : {}), ...(value as IStringDictionary<unknown>) };
|
||||
}
|
||||
|
||||
return { value, source };
|
||||
|
||||
@@ -93,21 +93,21 @@ export class ConfigurationService extends Disposable implements IConfigurationSe
|
||||
getValue<T>(section: string): T;
|
||||
getValue<T>(overrides: IConfigurationOverrides): T;
|
||||
getValue<T>(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<void>;
|
||||
updateValue(key: string, value: any, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise<void>;
|
||||
updateValue(key: string, value: any, target: ConfigurationTarget): Promise<void>;
|
||||
updateValue(key: string, value: any, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise<void>;
|
||||
async updateValue(key: string, value: any, arg3?: any, arg4?: any, options?: any): Promise<void> {
|
||||
updateValue(key: string, value: unknown): Promise<void>;
|
||||
updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise<void>;
|
||||
updateValue(key: string, value: unknown, target: ConfigurationTarget): Promise<void>;
|
||||
updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise<void>;
|
||||
async updateValue(key: string, value: unknown, arg3?: unknown, arg4?: unknown, options?: IConfigurationUpdateOptions): Promise<void> {
|
||||
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<void>();
|
||||
}
|
||||
|
||||
write(path: JSONPath, value: any): Promise<void> {
|
||||
write(path: JSONPath, value: unknown): Promise<void> {
|
||||
return this.queue.queue(() => this.doWriteConfiguration(path, value)); // queue up writes to prevent race conditions
|
||||
}
|
||||
|
||||
private async doWriteConfiguration(path: JSONPath, value: any): Promise<void> {
|
||||
private async doWriteConfiguration(path: JSONPath, value: unknown): Promise<void> {
|
||||
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
|
||||
|
||||
@@ -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<any> {
|
||||
protected getConfigurationDefaultOverrides(): IStringDictionary<unknown> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ export class NullPolicyConfiguration implements IPolicyConfiguration {
|
||||
async initialize() { return this.configurationModel; }
|
||||
}
|
||||
|
||||
type ParsedType = IStringDictionary<unknown> | Array<unknown>;
|
||||
|
||||
export class PolicyConfiguration extends Disposable implements IPolicyConfiguration {
|
||||
|
||||
private readonly _onDidChangeConfiguration = this._register(new Emitter<ConfigurationModel>());
|
||||
@@ -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<ParsedType> = [];
|
||||
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) {
|
||||
|
||||
@@ -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 } });
|
||||
});
|
||||
|
||||
@@ -152,7 +152,7 @@ let _configDelta: IConfigurationDelta | undefined;
|
||||
|
||||
|
||||
// BEGIN VSCode extension point `configurationDefaults`
|
||||
const defaultConfigurationExtPoint = ExtensionsRegistry.registerExtensionPoint<IConfigurationNode>({
|
||||
const defaultConfigurationExtPoint = ExtensionsRegistry.registerExtensionPoint<IStringDictionary<IStringDictionary<unknown>>>({
|
||||
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<IConfigurationDefaults>(extension => {
|
||||
const overrides: IStringDictionary<any> = 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<string>();
|
||||
|
||||
function handleConfiguration(node: IConfigurationNode, extension: IExtensionPointUser<any>): IConfigurationNode {
|
||||
function handleConfiguration(node: IConfigurationNode, extension: IExtensionPointUser<unknown>): 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<any>): void {
|
||||
function validateProperties(configuration: IConfigurationNode, extension: IExtensionPointUser<unknown>): void {
|
||||
const properties = configuration.properties;
|
||||
const extensionConfigurationPolicy = product.extensionConfigurationPolicy;
|
||||
if (properties) {
|
||||
|
||||
@@ -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<string, unknown>)[parts[i]];
|
||||
}
|
||||
return node;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export type ConfigurationInspect<T> = {
|
||||
@@ -52,27 +53,29 @@ export type ConfigurationInspect<T> = {
|
||||
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<string, unknown>).uri instanceof URI
|
||||
&& !!(thing as Record<string, unknown>).languageId
|
||||
&& typeof (thing as Record<string, unknown>).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<string, unknown>).uri
|
||||
&& !!(thing as Record<string, unknown>).languageId
|
||||
&& typeof (thing as Record<string, unknown>).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<string, unknown>).uri instanceof URI
|
||||
&& (!(thing as Record<string, unknown>).name || typeof (thing as Record<string, unknown>).name === 'string')
|
||||
&& (!(thing as Record<string, unknown>).index || typeof (thing as Record<string, unknown>).index === 'number');
|
||||
}
|
||||
|
||||
function scopeToOverrides(scope: vscode.ConfigurationScope | undefined | null): IConfigurationOverrides | undefined {
|
||||
@@ -187,52 +190,52 @@ export class ExtHostConfigProvider {
|
||||
},
|
||||
get: <T>(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<string, unknown>, 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<PropertyKey, unknown>)[property];
|
||||
}
|
||||
const result = target[property];
|
||||
const result = (target as Record<PropertyKey, unknown>)[property];
|
||||
if (typeof property === 'string') {
|
||||
return cloneOnWriteProxy(result, `${accessor}.${property}`);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
set: (_target: any, property: PropertyKey, value: any) => {
|
||||
set: (_target: Record<string, unknown>, property: PropertyKey, value: unknown) => {
|
||||
cloneTarget();
|
||||
if (clonedTarget) {
|
||||
clonedTarget[property] = value;
|
||||
(clonedTarget as Record<PropertyKey, unknown>)[property] = value;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
deleteProperty: (_target: any, property: PropertyKey) => {
|
||||
deleteProperty: (_target: Record<string, unknown>, property: PropertyKey) => {
|
||||
cloneTarget();
|
||||
if (clonedTarget) {
|
||||
delete clonedTarget[property];
|
||||
delete (clonedTarget as Record<PropertyKey, unknown>)[property];
|
||||
}
|
||||
return true;
|
||||
},
|
||||
defineProperty: (_target: any, property: PropertyKey, descriptor: any) => {
|
||||
defineProperty: (_target: Record<string, unknown>, property: PropertyKey, descriptor: PropertyDescriptor) => {
|
||||
cloneTarget();
|
||||
if (clonedTarget) {
|
||||
Object.defineProperty(clonedTarget, property, descriptor);
|
||||
Object.defineProperty(clonedTarget as Record<string, unknown>, 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<string, unknown>, property: PropertyKey) => readonlyProxy((target as Record<PropertyKey, unknown>)[property]),
|
||||
set: (_target: Record<string, unknown>, property: PropertyKey, _value: unknown) => { throw new Error(`TypeError: Cannot assign to read only property '${String(property)}' of object`); },
|
||||
deleteProperty: (_target: Record<string, unknown>, property: PropertyKey) => { throw new Error(`TypeError: Cannot delete read only property '${String(property)}' of object`); },
|
||||
defineProperty: (_target: Record<string, unknown>, 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
|
||||
|
||||
@@ -34,7 +34,7 @@ export class DefaultConfiguration extends BaseDefaultConfiguration {
|
||||
static readonly DEFAULT_OVERRIDES_CACHE_EXISTS_KEY = 'DefaultOverridesCacheExists';
|
||||
|
||||
private readonly configurationRegistry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
|
||||
private cachedConfigurationDefaultsOverrides: IStringDictionary<any> = {};
|
||||
private cachedConfigurationDefaultsOverrides: IStringDictionary<unknown> = {};
|
||||
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<IStringDictionary<unknown>> }]);
|
||||
}
|
||||
}
|
||||
|
||||
protected override getConfigurationDefaultOverrides(): IStringDictionary<any> {
|
||||
protected override getConfigurationDefaultOverrides(): IStringDictionary<unknown> {
|
||||
return this.cachedConfigurationDefaultsOverrides;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ export class DefaultConfiguration extends BaseDefaultConfiguration {
|
||||
}
|
||||
|
||||
private async updateCachedConfigurationDefaultsOverrides(): Promise<void> {
|
||||
const cachedConfigurationDefaultsOverrides: IStringDictionary<any> = {};
|
||||
const cachedConfigurationDefaultsOverrides: IStringDictionary<unknown> = {};
|
||||
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<void> {
|
||||
const content: any = {};
|
||||
const content: IStringDictionary<unknown> = {};
|
||||
if (settingsContent) {
|
||||
content[FOLDER_SETTINGS_NAME] = settingsContent;
|
||||
}
|
||||
|
||||
@@ -325,20 +325,20 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
|
||||
getValue<T>(section: string): T;
|
||||
getValue<T>(overrides: IConfigurationOverrides): T;
|
||||
getValue<T>(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<void>;
|
||||
updateValue(key: string, value: unknown): Promise<void>;
|
||||
updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise<void>;
|
||||
updateValue(key: string, value: unknown, target: ConfigurationTarget): Promise<void>;
|
||||
updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise<void>;
|
||||
async updateValue(key: string, value: unknown, arg3?: any, arg4?: any, options?: any): Promise<void> {
|
||||
async updateValue(key: string, value: unknown, arg3?: unknown, arg4?: unknown, options?: IConfigurationUpdateOptions): Promise<void> {
|
||||
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<void> {
|
||||
private async writeConfigurationValue(key: string, value: unknown, target: ConfigurationTarget, overrides: IConfigurationUpdateOverrides | undefined, options?: IConfigurationUpdateOptions): Promise<void> {
|
||||
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<any>): ConfigurationTarget[] {
|
||||
private deriveConfigurationTargets(key: string, value: unknown, inspect: IConfigurationValue<unknown>): ConfigurationTarget[] {
|
||||
if (equals(value, inspect.value)) {
|
||||
return [];
|
||||
}
|
||||
@@ -1374,7 +1374,7 @@ class ConfigurationDefaultOverridesContribution extends Disposable implements IW
|
||||
}
|
||||
|
||||
private async processExperimentalSettings(properties: Iterable<string>, autoRefetch: boolean): Promise<void> {
|
||||
const overrides: IStringDictionary<any> = {};
|
||||
const overrides: IStringDictionary<unknown> = {};
|
||||
const allProperties = this.configurationRegistry.getConfigurationProperties();
|
||||
for (const property of properties) {
|
||||
const schema = allProperties[property];
|
||||
|
||||
@@ -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<unknown>, 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<unknown>, 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<unknown>, key: string): ConfigurationModel {
|
||||
const data = raw[key] as IStringDictionary<unknown> | 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<unknown>, 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user