From 3b68b954444661eafcb2d22d12c92ad245252d16 Mon Sep 17 00:00:00 2001 From: Anton Kosyakov Date: Wed, 20 Mar 2019 13:50:23 +0000 Subject: [PATCH] =?UTF-8?q?[plugin]=C2=A0fix=20#4621:=20apply=20only=20val?= =?UTF-8?q?id=20configurations=20as=20schemas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anton Kosyakov --- .../src/browser/preferences/preference-contribution.ts | 8 ++++++++ packages/plugin-ext/src/common/plugin-protocol.ts | 10 ++++------ .../src/hosted/node/scanners/scanner-theia.ts | 10 +++------- .../src/main/browser/plugin-contribution-handler.ts | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/core/src/browser/preferences/preference-contribution.ts b/packages/core/src/browser/preferences/preference-contribution.ts index 8bfa705519c00..3726111adbbe0 100644 --- a/packages/core/src/browser/preferences/preference-contribution.ts +++ b/packages/core/src/browser/preferences/preference-contribution.ts @@ -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((obj)['properties']); + } export function getDefaultScope(schema: PreferenceSchema): PreferenceScope { let defaultScope: PreferenceScope = PreferenceScope.Workspace; if (!PreferenceScope.is(schema.scope)) { @@ -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, diff --git a/packages/plugin-ext/src/common/plugin-protocol.ts b/packages/plugin-ext/src/common/plugin-protocol.ts index cbb7ba0780415..983a96a24cfd9 100644 --- a/packages/plugin-ext/src/common/plugin-protocol.ts +++ b/packages/plugin-ext/src/common/plugin-protocol.ts @@ -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'; @@ -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[] }; @@ -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[] }; diff --git a/packages/plugin-ext/src/hosted/node/scanners/scanner-theia.ts b/packages/plugin-ext/src/hosted/node/scanners/scanner-theia.ts index d8e668d6d2158..c38fa0ee11d99 100644 --- a/packages/plugin-ext/src/hosted/node/scanners/scanner-theia.ts +++ b/packages/plugin-ext/src/hosted/node/scanners/scanner-theia.ts @@ -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; @@ -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 { diff --git a/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts b/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts index 4543ea48bc047..4050d109bbf68 100644 --- a/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts +++ b/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts @@ -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); }