Skip to content

Commit

Permalink
[plugin] fix #4621: apply only valid configurations as schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Mar 20, 2019
1 parent e35ba88 commit 3b68b95
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export interface PreferenceSchema {
properties: PreferenceSchemaProperties
}
export namespace PreferenceSchema {
export function is(obj: Object | undefined): obj is PreferenceSchema {
return !!obj && ('properties' in obj) && PreferenceSchemaProperties.is((<any>obj)['properties']);
}
export function getDefaultScope(schema: PreferenceSchema): PreferenceScope {
let defaultScope: PreferenceScope = PreferenceScope.Workspace;
if (!PreferenceScope.is(schema.scope)) {
Expand All @@ -49,6 +52,11 @@ export namespace PreferenceSchema {
export interface PreferenceSchemaProperties {
[name: string]: PreferenceSchemaProperty
}
export namespace PreferenceSchemaProperties {
export function is(obj: Object | undefined): obj is PreferenceSchemaProperties {
return !!obj && typeof obj === 'object';
}
}

export interface PreferenceDataSchema {
[name: string]: any,
Expand Down
10 changes: 4 additions & 6 deletions packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { RPCProtocol } from '../api/rpc-protocol';
import { Disposable } from '@theia/core/lib/common/disposable';
import { LogPart, KeysToAnyValues, KeysToKeysToAnyValue } from './types';
import { CharacterPair, CommentRule, PluginAPIFactory, Plugin } from '../api/plugin-api';
// FIXME get rid of browser code in backend
import { PreferenceSchema, PreferenceSchemaProperties } from '@theia/core/lib/browser/preferences';
import { ExtPluginApi } from './plugin-ext-api-contribution';
import { IJSONSchema, IJSONSchemaSnippet } from '@theia/core/lib/common/json-schema';

Expand Down Expand Up @@ -55,8 +53,8 @@ export interface PluginPackage {
* This interface describes a package.json contribution section object.
*/
export interface PluginPackageContribution {
configuration?: PreferenceSchema;
configurationDefaults?: PreferenceSchemaProperties;
configuration?: Object;
configurationDefaults?: Object;
languages?: PluginPackageLanguageContribution[];
grammars?: PluginPackageGrammarsContribution[];
viewsContainers?: { [location: string]: PluginPackageViewContainer[] };
Expand Down Expand Up @@ -348,8 +346,8 @@ export interface PluginModel {
* This interface describes some static plugin contributions.
*/
export interface PluginContribution {
configuration?: PreferenceSchema;
configurationDefaults?: PreferenceSchemaProperties;
configuration?: Object;
configurationDefaults?: Object;
languages?: LanguageContribution[];
grammars?: GrammarsContribution[];
viewsContainers?: { [location: string]: ViewContainer[] };
Expand Down
10 changes: 3 additions & 7 deletions packages/plugin-ext/src/hosted/node/scanners/scanner-theia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export class TheiaPluginScanner implements PluginScanner {
}

const contributions: PluginContribution = {};
if (rawPlugin.contributes!.configuration) {
const config = this.readConfiguration(rawPlugin.contributes.configuration!, rawPlugin.packagePath);
if (rawPlugin.contributes.configuration) {
const config = this.readConfiguration(rawPlugin.contributes.configuration, rawPlugin.packagePath);
contributions.configuration = config;
}
contributions.configurationDefaults = rawPlugin.contributes.configurationDefaults;
Expand Down Expand Up @@ -236,11 +236,7 @@ export class TheiaPluginScanner implements PluginScanner {

// tslint:disable-next-line:no-any
private readConfiguration(rawConfiguration: any, pluginPath: string): any {
return {
type: rawConfiguration.type,
title: rawConfiguration.title,
properties: rawConfiguration.properties
};
return rawConfiguration;
}

private readKeybinding(rawKeybinding: PluginPackageKeybinding): Keybinding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export class PluginContributionHandler {
protected readonly style: PluginSharedStyle;

handleContributions(contributions: PluginContribution): void {
if (contributions.configuration) {
if (PreferenceSchema.is(contributions.configuration)) {
this.updateConfigurationSchema(contributions.configuration);
}
if (contributions.configurationDefaults) {
if (PreferenceSchemaProperties.is(contributions.configurationDefaults)) {
this.updateDefaultOverridesSchema(contributions.configurationDefaults);
}

Expand Down

0 comments on commit 3b68b95

Please sign in to comment.