Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #6046: workspace configuration contributed by VSCode extension an… #6090

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions packages/core/src/browser/preferences/preference-proxy.ts
Original file line number Diff line number Diff line change
@@ -68,15 +68,29 @@ export function createPreferenceProxy<T>(preferences: PreferenceService, schema:
throw new Error('Unsupported operation');
};
const getValue: PreferenceRetrieval<any>['get'] = (arg, defaultValue, resourceUri) => {
const preferenceName = typeof arg === 'object' && arg.overrideIdentifier ?
const isArgOverridePreferenceName = typeof arg === 'object' && arg.overrideIdentifier;
const preferenceName = isArgOverridePreferenceName ?
preferences.overridePreferenceName(<OverridePreferenceName>arg) :
<string>arg;
return preferences.get(preferenceName, defaultValue, resourceUri);
const value = preferences.get(preferenceName, defaultValue, resourceUri);
if (preferences.validate(isArgOverridePreferenceName ? (<OverridePreferenceName>arg).preferenceName : preferenceName, value)) {
return value;
}
if (defaultValue !== undefined) {
return defaultValue;
}
const values = preferences.inspect(preferenceName, resourceUri);
return values && values.defaultValue;
};
return new Proxy({}, {
get: (_, property: string) => {
if (schema.properties[property]) {
return preferences.get(property);
const value = preferences.get(property);
if (preferences.validate(property, value)) {
return value;
}
const values = preferences.inspect(property);
return values && values.defaultValue;
}
if (property === 'onPreferenceChanged') {
return onPreferenceChangedEmitter.event;
4 changes: 4 additions & 0 deletions packages/core/src/browser/preferences/preference-service.ts
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@ export interface PreferenceService extends Disposable {
overriddenPreferenceName(preferenceName: string): OverridePreferenceName | undefined;

resolve<T>(preferenceName: string, defaultValue?: T, resourceUri?: string): PreferenceResolveResult<T>;
validate(name: string, value: any): boolean;
}

/**
@@ -412,4 +413,7 @@ export class PreferenceServiceImpl implements PreferenceService, FrontendApplica
};
}

validate(name: string, value: any): boolean {
return this.schema.validate(name, value);
}
}
Original file line number Diff line number Diff line change
@@ -55,4 +55,7 @@ export class MockPreferenceService implements PreferenceService {
overriddenPreferenceName(preferenceName: string): OverridePreferenceName | undefined {
return undefined;
}

// tslint:disable-next-line:no-any
validate(name: string, value: any): boolean { return true; }
}
Original file line number Diff line number Diff line change
@@ -85,10 +85,12 @@ describe('editor-preview-manager', () => {

it('should handle preview requests if editor.enablePreview enabled', async () => {
(mockPreference.get as sinon.SinonStub).returns(true);
(mockPreference.validate as sinon.SinonStub).returns(true);
expect(await previewManager.canHandle(new URI(), {preview: true})).to.be.greaterThan(0);
});
it('should not handle preview requests if editor.enablePreview disabled', async () => {
(mockPreference.get as sinon.SinonStub).returns(false);
(mockPreference.validate as sinon.SinonStub).returns(true);
expect(await previewManager.canHandle(new URI(), {preview: true})).to.equal(0);
});
it('should not handle requests that are not preview or currently being previewed', async () => {
Original file line number Diff line number Diff line change
@@ -147,14 +147,9 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi
if (typeof jsonData !== 'object') {
return preferences;
}
const uri = this.getUri();
// tslint:disable-next-line:forin
for (const preferenceName in jsonData) {
const preferenceValue = jsonData[preferenceName];
if (!this.validate(preferenceName, preferenceValue)) {
console.warn(`Preference ${preferenceName} in ${uri} is invalid.`);
continue;
}
if (this.schemaProvider.testOverrideValue(preferenceName, preferenceValue)) {
// tslint:disable-next-line:forin
for (const overriddenPreferenceName in preferenceValue) {
@@ -168,14 +163,6 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi
return preferences;
}

protected validate(preferenceName: string, preferenceValue: any): boolean {
// in case if preferences are loaded from .vscode folder we should load even invalid
if (this.configurations.getPath(this.getUri()) !== this.configurations.getPaths()[0]) {
return true;
}
return preferenceValue === undefined || this.schemaProvider.validate(preferenceName, preferenceValue);
}

protected parse(content: string): any {
content = content.trim();
if (!content) {