Skip to content

Commit

Permalink
[plug-in] implement inspect configuration method
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
  • Loading branch information
akurinnoy committed Jan 30, 2019
1 parent d76196d commit 6b1a35c
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 70 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { LabelParser } from './label-parser';
import { LabelProvider, LabelProviderContribution, DefaultUriLabelProviderContribution } from './label-provider';
import {
PreferenceProviderProvider, PreferenceProvider, PreferenceScope, PreferenceService,
PreferenceServiceImpl, bindPreferenceSchemaProvider
PreferenceServiceImpl, bindPreferenceSchemaProvider, PreferenceSchemaProvider
} from './preferences';
import { ContextMenuRenderer } from './context-menu-renderer';
import { ThemingCommandContribution, ThemeService, BuiltinThemeProvider } from './theming';
Expand Down Expand Up @@ -193,7 +193,12 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo

bind(PreferenceProvider).toSelf().inSingletonScope().whenTargetNamed(PreferenceScope.User);
bind(PreferenceProvider).toSelf().inSingletonScope().whenTargetNamed(PreferenceScope.Workspace);
bind(PreferenceProviderProvider).toFactory(ctx => (scope: PreferenceScope) => ctx.container.getNamed(PreferenceProvider, scope));
bind(PreferenceProviderProvider).toFactory(ctx => (scope: PreferenceScope) => {
if (scope === PreferenceScope.Default) {
return ctx.container.get(PreferenceSchemaProvider);
}
return ctx.container.getNamed(PreferenceProvider, scope);
});
bind(PreferenceServiceImpl).toSelf().inSingletonScope();
bind(PreferenceService).toService(PreferenceServiceImpl);
bind(FrontendApplicationContribution).toService(PreferenceServiceImpl);
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/browser/preferences/preference-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ import { PreferenceProvider } from './preference-provider';
import { PreferenceSchemaProvider } from './preference-contribution';

export enum PreferenceScope {
Default,
User,
Workspace
}

export namespace PreferenceScope {
export function getScopes(): PreferenceScope[] {
return Object.keys(PreferenceScope)
.filter(k => typeof PreferenceScope[k as any] === 'string')
.map(v => <PreferenceScope>Number(v));
}
}

export interface PreferenceChangedEvent {
changes: PreferenceChange[]
}
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ import { SymbolInformation } from 'vscode-languageserver-types';

export interface PluginInitData {
plugins: PluginMetadata[];
preferences: { [key: string]: any };
preferences: PreferenceData;
globalState: KeysToKeysToAnyValue;
workspaceState: KeysToKeysToAnyValue;
env: EnvInit;
extApi?: ExtPluginApi[];
}

export interface PreferenceData {
[scope: number]: any;
}

export interface Plugin {
pluginPath: string;
pluginFolder: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface PluginPackage {
* This interface describes a package.json contribution section object.
*/
export interface PluginPackageContribution {
configuration: PreferenceSchema;
configuration?: PreferenceSchema;
languages?: PluginPackageLanguageContribution[];
grammars?: PluginPackageGrammarsContribution[];
viewsContainers?: { [location: string]: PluginPackageViewContainer[] };
Expand Down
10 changes: 7 additions & 3 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import { MAIN_RPC_CONTEXT, ConfigStorage, PluginManagerExt } from '../../api/plu
import { setUpPluginApi } from '../../main/browser/main-context';
import { RPCProtocol, RPCProtocolImpl } from '../../api/rpc-protocol';
import { ILogger, ContributionProvider } from '@theia/core';
import { PreferenceServiceImpl } from '@theia/core/lib/browser';
import { PreferenceServiceImpl, PreferenceProviderProvider } from '@theia/core/lib/browser';
import { WorkspaceService } from '@theia/workspace/lib/browser';
import { PluginContributionHandler } from '../../main/browser/plugin-contribution-handler';
import { getQueryParameters } from '../../main/browser/env-main';
import { ExtPluginApi, MainPluginApiProvider } from '../../common/plugin-ext-api-contribution';
import { PluginPathsService } from '../../main/common/plugin-paths-protocol';
import { StoragePathService } from '../../main/browser/storage-path-service';
import { getPreferences } from '../../main/browser/preference-registry-main';
import { PluginServer } from '../../common/plugin-protocol';
import { KeysToKeysToAnyValue } from '../../common/types';

Expand Down Expand Up @@ -60,6 +61,9 @@ export class HostedPluginSupport {
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

@inject(PreferenceProviderProvider)
protected readonly preferenceProviderProvider: PreferenceProviderProvider;

private theiaReadyPromise: Promise<any>;
private frontendExtManagerProxy: PluginManagerExt;
private backendExtManagerProxy: PluginManagerExt;
Expand Down Expand Up @@ -119,7 +123,7 @@ export class HostedPluginSupport {
const hostedExtManager = worker.rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
hostedExtManager.$init({
plugins: initData.plugins,
preferences: this.preferenceServiceImpl.getPreferences(),
preferences: getPreferences(this.preferenceProviderProvider),
globalState: initData.globalStates,
workspaceState: initData.workspaceStates,
env: { queryParams: getQueryParameters() },
Expand Down Expand Up @@ -153,7 +157,7 @@ export class HostedPluginSupport {
const hostedExtManager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
hostedExtManager.$init({
plugins: plugins,
preferences: this.preferenceServiceImpl.getPreferences(),
preferences: getPreferences(this.preferenceProviderProvider),
globalState: initData.globalStates,
workspaceState: initData.workspaceStates,
env: { queryParams: getQueryParameters() },
Expand Down
13 changes: 11 additions & 2 deletions packages/plugin-ext/src/hosted/browser/worker/worker-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { EnvExtImpl } from '../../../plugin/env';
import { PreferenceRegistryExtImpl } from '../../../plugin/preference-registry';
import { ExtPluginApi } from '../../../common/plugin-ext-api-contribution';
import { createDebugExtStub } from './debug-stub';
import { EditorsAndDocumentsExtImpl } from '../../../plugin/editors-and-documents';
import { WorkspaceExtImpl } from '../../../plugin/workspace';

// tslint:disable-next-line:no-any
const ctx = self as any;
Expand All @@ -47,7 +49,9 @@ function initialize(contextPath: string, pluginMetadata: PluginMetadata): void {
ctx.importScripts('/context/' + contextPath);
}
const envExt = new EnvExtImpl(rpc);
const preferenceRegistryExt = new PreferenceRegistryExtImpl(rpc);
const editorsAndDocuments = new EditorsAndDocumentsExtImpl(rpc);
const workspaceExt = new WorkspaceExtImpl(rpc, editorsAndDocuments);
const preferenceRegistryExt = new PreferenceRegistryExtImpl(rpc, workspaceExt);
const debugExt = createDebugExtStub(rpc);

const pluginManager = new PluginManagerExtImpl({
Expand Down Expand Up @@ -124,7 +128,10 @@ const apiFactory = createAPIFactory(
pluginManager,
envExt,
debugExt,
preferenceRegistryExt);
preferenceRegistryExt,
editorsAndDocuments,
workspaceExt
);
let defaultApi: typeof theia;

const handler = {
Expand All @@ -147,6 +154,8 @@ const handler = {
ctx['theia'] = new Proxy(Object.create(null), handler);

rpc.set(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT, pluginManager);
rpc.set(MAIN_RPC_CONTEXT.EDITORS_AND_DOCUMENTS_EXT, editorsAndDocuments);
rpc.set(MAIN_RPC_CONTEXT.WORKSPACE_EXT, workspaceExt);
rpc.set(MAIN_RPC_CONTEXT.PREFERENCE_REGISTRY_EXT, preferenceRegistryExt);

function isElectron() {
Expand Down
13 changes: 11 additions & 2 deletions packages/plugin-ext/src/hosted/node/plugin-host-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { EnvExtImpl } from '../../plugin/env';
import { PreferenceRegistryExtImpl } from '../../plugin/preference-registry';
import { ExtPluginApi } from '../../common/plugin-ext-api-contribution';
import { DebugExtImpl } from '../../plugin/node/debug/debug';
import { EditorsAndDocumentsExtImpl } from '../../plugin/editors-and-documents';
import { WorkspaceExtImpl } from '../../plugin/workspace';

/**
* Handle the RPC calls.
Expand All @@ -39,17 +41,24 @@ export class PluginHostRPC {
initialize() {
const envExt = new EnvExtImpl(this.rpc);
const debugExt = new DebugExtImpl(this.rpc);
const preferenceRegistryExt = new PreferenceRegistryExtImpl(this.rpc);
const editorsAndDocumentsExt = new EditorsAndDocumentsExtImpl(this.rpc);
const workspaceExt = new WorkspaceExtImpl(this.rpc, editorsAndDocumentsExt);
const preferenceRegistryExt = new PreferenceRegistryExtImpl(this.rpc, workspaceExt);
this.pluginManager = this.createPluginManager(envExt, preferenceRegistryExt, this.rpc);
this.rpc.set(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT, this.pluginManager);
this.rpc.set(MAIN_RPC_CONTEXT.EDITORS_AND_DOCUMENTS_EXT, editorsAndDocumentsExt);
this.rpc.set(MAIN_RPC_CONTEXT.WORKSPACE_EXT, workspaceExt);
this.rpc.set(MAIN_RPC_CONTEXT.PREFERENCE_REGISTRY_EXT, preferenceRegistryExt);

PluginHostRPC.apiFactory = createAPIFactory(
this.rpc,
this.pluginManager,
envExt,
debugExt,
preferenceRegistryExt);
preferenceRegistryExt,
editorsAndDocumentsExt,
workspaceExt
);
}

// tslint:disable-next-line:no-any
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-ext/src/main/browser/plugin-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export class PluginWorker {
private worker: Worker;
public readonly rpc: RPCProtocol;
constructor() {
const emmitter = new Emitter();
const emitter = new Emitter();
this.worker = new (require('../../hosted/browser/worker/worker-main'));
this.worker.onmessage = message => {
emmitter.fire(message.data);
emitter.fire(message.data);
};
this.worker.onerror = e => console.error(e);

this.rpc = new RPCProtocolImpl({
onMessage: emmitter.event,
onMessage: emitter.event,
send: (m: {}) => {
this.worker.postMessage(m);
}
Expand Down
34 changes: 28 additions & 6 deletions packages/plugin-ext/src/main/browser/preference-registry-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,47 @@
import {
PreferenceService,
PreferenceServiceImpl,
PreferenceScope
PreferenceScope,
PreferenceChange,
PreferenceProviderProvider
} from '@theia/core/lib/browser/preferences';
import { interfaces } from 'inversify';
import {
MAIN_RPC_CONTEXT,
PreferenceRegistryExt,
PreferenceRegistryMain,
PreferenceData,
} from '../../api/plugin-api';
import { RPCProtocol } from '../../api/rpc-protocol';
import { ConfigurationTarget } from '../../plugin/types-impl';

export function getPreferences(preferenceProviderProvider: PreferenceProviderProvider): PreferenceData {
return PreferenceScope.getScopes().reduce((result, scope) => {
const provider = preferenceProviderProvider(scope);
result[scope] = provider.getPreferences();
return result;
}, {} as PreferenceData);
}

export class PreferenceRegistryMainImpl implements PreferenceRegistryMain {
private proxy: PreferenceRegistryExt;
private preferenceService: PreferenceService;
private readonly preferenceProviderProvider: PreferenceProviderProvider;

constructor(prc: RPCProtocol, container: interfaces.Container) {
this.proxy = prc.getProxy(MAIN_RPC_CONTEXT.PREFERENCE_REGISTRY_EXT);
this.preferenceService = container.get(PreferenceService);
this.preferenceProviderProvider = container.get(PreferenceProviderProvider);
const preferenceServiceImpl = container.get(PreferenceServiceImpl);

preferenceServiceImpl.onPreferenceChanged(e => {
this.proxy.$acceptConfigurationChanged(preferenceServiceImpl.getPreferences(), e);
const data = getPreferences(this.preferenceProviderProvider);
const eventData: PreferenceChange = {
preferenceName: e.preferenceName,
newValue: e.newValue,
oldValue: e.oldValue
};
this.proxy.$acceptConfigurationChanged(data, eventData);
});
}

Expand All @@ -61,10 +80,13 @@ export class PreferenceRegistryMainImpl implements PreferenceRegistryMain {
return arg ? PreferenceScope.User : PreferenceScope.Workspace;
}

if (arg === ConfigurationTarget.User) {
return PreferenceScope.User;
} else {
return PreferenceScope.Workspace;
switch (arg) {
case ConfigurationTarget.Global:
return PreferenceScope.User;
case ConfigurationTarget.Workspace:
return PreferenceScope.Workspace;
default:
return PreferenceScope.Workspace;
}
}

Expand Down
11 changes: 6 additions & 5 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ export function createAPIFactory(
pluginManager: PluginManager,
envExt: EnvExtImpl,
debugExt: DebugExtImpl,
preferenceRegistryExt: PreferenceRegistryExtImpl): PluginAPIFactory {
preferenceRegistryExt: PreferenceRegistryExtImpl,
editorsAndDocumentsExt: EditorsAndDocumentsExtImpl,
workspaceExt: WorkspaceExtImpl
): PluginAPIFactory {

const commandRegistry = rpc.set(MAIN_RPC_CONTEXT.COMMAND_REGISTRY_EXT, new CommandRegistryImpl(rpc));
const quickOpenExt = rpc.set(MAIN_RPC_CONTEXT.QUICK_OPEN_EXT, new QuickOpenExtImpl(rpc));
Expand All @@ -132,10 +135,8 @@ export function createAPIFactory(
const windowStateExt = rpc.set(MAIN_RPC_CONTEXT.WINDOW_STATE_EXT, new WindowStateExtImpl());
const notificationExt = rpc.set(MAIN_RPC_CONTEXT.NOTIFICATION_EXT, new NotificationExtImpl(rpc));
const statusBarExt = new StatusBarExtImpl(rpc);
const editorsAndDocuments = rpc.set(MAIN_RPC_CONTEXT.EDITORS_AND_DOCUMENTS_EXT, new EditorsAndDocumentsExtImpl(rpc));
const editors = rpc.set(MAIN_RPC_CONTEXT.TEXT_EDITORS_EXT, new TextEditorsExtImpl(rpc, editorsAndDocuments));
const documents = rpc.set(MAIN_RPC_CONTEXT.DOCUMENTS_EXT, new DocumentsExtImpl(rpc, editorsAndDocuments));
const workspaceExt = rpc.set(MAIN_RPC_CONTEXT.WORKSPACE_EXT, new WorkspaceExtImpl(rpc, editorsAndDocuments));
const editors = rpc.set(MAIN_RPC_CONTEXT.TEXT_EDITORS_EXT, new TextEditorsExtImpl(rpc, editorsAndDocumentsExt));
const documents = rpc.set(MAIN_RPC_CONTEXT.DOCUMENTS_EXT, new DocumentsExtImpl(rpc, editorsAndDocumentsExt));
const statusBarMessageRegistryExt = new StatusBarMessageRegistryExt(rpc);
const terminalExt = rpc.set(MAIN_RPC_CONTEXT.TERMINAL_EXT, new TerminalServiceExtImpl(rpc));
const outputChannelRegistryExt = new OutputChannelRegistryExt(rpc);
Expand Down
Loading

0 comments on commit 6b1a35c

Please sign in to comment.