Skip to content

Commit

Permalink
#46851 passing extension description breaks intellisense as it is not…
Browse files Browse the repository at this point in the history
… serializable.

Pass only id and display name as extension info
  • Loading branch information
sandy081 committed Nov 26, 2021
1 parent 13ff6ba commit 212deea
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
32 changes: 16 additions & 16 deletions src/vs/platform/configuration/common/configurationRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Emitter, Event } from 'vs/base/common/event';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import * as types from 'vs/base/common/types';
import * as nls from 'vs/nls';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { Registry } from 'vs/platform/registry/common/platform';

Expand Down Expand Up @@ -177,9 +176,9 @@ export interface IConfigurationPropertySchema extends IJSONSchema {
order?: number;
}

export interface IConfigurationExtensionInfo {
extensionDescription: IExtensionDescription;
restrictedConfigurations?: string[];
export interface IExtensionInfo {
id: string;
displayName?: string;
}

export interface IConfigurationNode {
Expand All @@ -191,21 +190,22 @@ export interface IConfigurationNode {
properties?: IStringDictionary<IConfigurationPropertySchema>;
allOf?: IConfigurationNode[];
scope?: ConfigurationScope;
extensionInfo?: IConfigurationExtensionInfo;
extensionInfo?: IExtensionInfo;
restrictedProperties?: string[];
}

export interface IConfigurationDefaults {
overrides: IStringDictionary<any>;
source?: IExtensionDescription | string;
source?: IExtensionInfo | string;
}

export type IRegisteredConfigurationPropertySchema = IConfigurationPropertySchema & {
defaultDefaultValue?: any,
source?: IExtensionDescription,
defaultSource?: IExtensionDescription | string;
source?: IExtensionInfo,
defaultSource?: IExtensionInfo | string;
};

export type IConfigurationDefaultOverride = { value: any, source?: IExtensionDescription | string };
export type IConfigurationDefaultOverride = { value: any, source?: IExtensionInfo | string };

export const allSettings: { properties: IStringDictionary<IConfigurationPropertySchema>, patternProperties: IStringDictionary<IConfigurationPropertySchema> } = { properties: {}, patternProperties: {} };
export const applicationSettings: { properties: IStringDictionary<IConfigurationPropertySchema>, patternProperties: IStringDictionary<IConfigurationPropertySchema> } = { properties: {}, patternProperties: {} };
Expand Down Expand Up @@ -323,8 +323,8 @@ class ConfigurationRegistry implements IConfigurationRegistry {
for (const { overrides, source } of defaultConfigurations) {
for (const key in overrides) {
const configurationDefaultsOverride = this.configurationDefaultsOverrides.get(key);
const id = types.isString(source) ? source : source?.identifier.value;
const configurationDefaultsOverrideSourceId = types.isString(configurationDefaultsOverride?.source) ? configurationDefaultsOverride?.source : configurationDefaultsOverride?.source?.identifier.value;
const id = types.isString(source) ? source : source?.id;
const configurationDefaultsOverrideSourceId = types.isString(configurationDefaultsOverride?.source) ? configurationDefaultsOverride?.source : configurationDefaultsOverride?.source?.id;
if (id !== configurationDefaultsOverrideSourceId) {
continue;
}
Expand Down Expand Up @@ -362,7 +362,7 @@ class ConfigurationRegistry implements IConfigurationRegistry {
private doRegisterConfigurations(configurations: IConfigurationNode[], validate: boolean): string[] {
const properties: string[] = [];
configurations.forEach(configuration => {
properties.push(...this.validateAndRegisterProperties(configuration, validate, configuration.extensionInfo)); // fills in defaults
properties.push(...this.validateAndRegisterProperties(configuration, validate, configuration.extensionInfo, configuration.restrictedProperties)); // fills in defaults
this.configurationContributors.push(configuration);
this.registerJSONConfiguration(configuration);
});
Expand Down Expand Up @@ -393,7 +393,7 @@ class ConfigurationRegistry implements IConfigurationRegistry {
return properties;
}

private validateAndRegisterProperties(configuration: IConfigurationNode, validate: boolean = true, extensionInfo?: IConfigurationExtensionInfo, scope: ConfigurationScope = ConfigurationScope.WINDOW): string[] {
private validateAndRegisterProperties(configuration: IConfigurationNode, validate: boolean = true, extensionInfo: IExtensionInfo | undefined, restrictedProperties: string[] | undefined, scope: ConfigurationScope = ConfigurationScope.WINDOW): string[] {
scope = types.isUndefinedOrNull(configuration.scope) ? scope : configuration.scope;
let propertyKeys: string[] = [];
let properties = configuration.properties;
Expand All @@ -405,7 +405,7 @@ class ConfigurationRegistry implements IConfigurationRegistry {
}

const property: IRegisteredConfigurationPropertySchema = properties[key];
property.source = extensionInfo?.extensionDescription;
property.source = extensionInfo;

// update default value
property.defaultDefaultValue = properties[key].default;
Expand All @@ -416,7 +416,7 @@ class ConfigurationRegistry implements IConfigurationRegistry {
property.scope = undefined; // No scope for overridable properties `[${identifier}]`
} else {
property.scope = types.isUndefinedOrNull(property.scope) ? scope : property.scope;
property.restricted = types.isUndefinedOrNull(property.restricted) ? !!extensionInfo?.restrictedConfigurations?.includes(key) : property.restricted;
property.restricted = types.isUndefinedOrNull(property.restricted) ? !!restrictedProperties?.includes(key) : property.restricted;
}

// Add to properties maps
Expand All @@ -440,7 +440,7 @@ class ConfigurationRegistry implements IConfigurationRegistry {
let subNodes = configuration.allOf;
if (subNodes) {
for (let node of subNodes) {
propertyKeys.push(...this.validateAndRegisterProperties(node, validate, extensionInfo, scope));
propertyKeys.push(...this.validateAndRegisterProperties(node, validate, extensionInfo, restrictedProperties, scope));
}
}
return propertyKeys;
Expand Down
7 changes: 4 additions & 3 deletions src/vs/workbench/api/common/configurationExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const defaultConfigurationExtPoint = ExtensionsRegistry.registerExtensionPoint<I
});
defaultConfigurationExtPoint.setHandler((extensions, { added, removed }) => {
if (removed.length) {
const removedDefaultConfigurations = removed.map<IConfigurationDefaults>(extension => ({ overrides: objects.deepClone(extension.value), source: extension.description }));
const removedDefaultConfigurations = removed.map<IConfigurationDefaults>(extension => ({ overrides: objects.deepClone(extension.value), source: { id: extension.description.identifier.value, displayName: extension.description.displayName } }));
configurationRegistry.deregisterDefaultConfigurations(removedDefaultConfigurations);
}
if (added.length) {
Expand All @@ -161,7 +161,7 @@ defaultConfigurationExtPoint.setHandler((extensions, { added, removed }) => {
}
}
}
return { overrides, source: extension.description };
return { overrides, source: { id: extension.description.identifier.value, displayName: extension.description.displayName } };
});
configurationRegistry.registerDefaultConfigurations(addedDefaultConfigurations);
}
Expand Down Expand Up @@ -212,7 +212,8 @@ configurationExtPoint.setHandler((extensions, { added, removed }) => {
validateProperties(configuration, extension);

configuration.id = node.id || extension.description.identifier.value;
configuration.extensionInfo = { extensionDescription: extension.description, restrictedConfigurations: extension.description.capabilities?.untrustedWorkspaces?.supported === 'limited' ? extension.description.capabilities?.untrustedWorkspaces.restrictedConfigurations : undefined };
configuration.extensionInfo = { id: extension.description.identifier.value, displayName: extension.description.displayName };
configuration.restrictedProperties = extension.description.capabilities?.untrustedWorkspaces?.supported === 'limited' ? extension.description.capabilities?.untrustedWorkspaces.restrictedConfigurations : undefined;
configuration.title = configuration.title || extension.description.displayName || extension.description.identifier.value;
configurations.push(configuration);
return configurations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export async function resolveExtensionsSettings(extensionService: IExtensionServ
const flatSettings = arrays.flatten(
group.sections.map(section => section.settings));

const extensionId = group.extensionInfo!.extensionDescription.identifier.value;
const extensionId = group.extensionInfo!.id;
const extension = await extensionService.getExtension(extensionId);
const extensionName = extension!.displayName ?? extension!.name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {
return false;
}

return Array.from(extensionFilters).some(extensionId => extensionId.toLowerCase() === this.setting.extensionInfo!.extensionDescription.identifier.value.toLowerCase());
return Array.from(extensionFilters).some(extensionId => extensionId.toLowerCase() === this.setting.extensionInfo!.id.toLowerCase());
}

matchesAnyFeature(featureFilters?: Set<string>): boolean {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/services/preferences/common/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { URI } from 'vs/base/common/uri';
import { IRange } from 'vs/editor/common/core/range';
import { ITextModel } from 'vs/editor/common/model';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { ConfigurationScope, EditPresentationTypes, IConfigurationExtensionInfo } from 'vs/platform/configuration/common/configurationRegistry';
import { ConfigurationScope, EditPresentationTypes, IExtensionInfo } from 'vs/platform/configuration/common/configurationRegistry';
import { EditorResolution, IEditorOptions } from 'vs/platform/editor/common/editor';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface ISettingsGroup {
titleRange: IRange;
sections: ISettingsSection[];
order?: number;
extensionInfo?: IConfigurationExtensionInfo;
extensionInfo?: IExtensionInfo;
}

export interface ISettingsSection {
Expand Down Expand Up @@ -81,7 +81,7 @@ export interface ISetting {
tags?: string[];
disallowSyncIgnore?: boolean;
restricted?: boolean;
extensionInfo?: IConfigurationExtensionInfo;
extensionInfo?: IExtensionInfo;
validator?: (value: any) => string | null;
enumItemLabels?: string[];
allKeysAreBoolean?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/mod
import { ITextEditorModel } from 'vs/editor/common/services/resolverService';
import * as nls from 'vs/nls';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ConfigurationScope, Extensions, IConfigurationNode, IConfigurationPropertySchema, IConfigurationRegistry, IConfigurationExtensionInfo, OVERRIDE_PROPERTY_REGEX } from 'vs/platform/configuration/common/configurationRegistry';
import { ConfigurationScope, Extensions, IConfigurationNode, IConfigurationPropertySchema, IConfigurationRegistry, IExtensionInfo, OVERRIDE_PROPERTY_REGEX } from 'vs/platform/configuration/common/configurationRegistry';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { Registry } from 'vs/platform/registry/common/platform';
import { EditorModel } from 'vs/workbench/common/editor/editorModel';
Expand Down Expand Up @@ -565,7 +565,7 @@ export class DefaultSettings extends Disposable {
}
if (title) {
if (!settingsGroup) {
settingsGroup = result.find(g => g.title === title && g.extensionInfo?.extensionDescription.identifier.value === config.extensionInfo?.extensionDescription.identifier.value);
settingsGroup = result.find(g => g.title === title && g.extensionInfo?.id === config.extensionInfo?.id);
if (!settingsGroup) {
settingsGroup = { sections: [{ settings: [] }], id: config.id || '', title: title || '', titleRange: nullRange, order: config.order, range: nullRange, extensionInfo: config.extensionInfo };
result.push(settingsGroup);
Expand Down Expand Up @@ -607,7 +607,7 @@ export class DefaultSettings extends Disposable {
return result;
}

private parseSettings(settingsObject: { [path: string]: IConfigurationPropertySchema; }, extensionInfo?: IConfigurationExtensionInfo): ISetting[] {
private parseSettings(settingsObject: { [path: string]: IConfigurationPropertySchema; }, extensionInfo?: IExtensionInfo): ISetting[] {
const result: ISetting[] = [];
for (const key in settingsObject) {
const prop = settingsObject[key];
Expand Down

0 comments on commit 212deea

Please sign in to comment.