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

[plug-in] [vscode] Add some missing entries in env object #4971

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@theia/task": "^0.5.0",
"@theia/workspace": "^0.5.0",
"decompress": "^4.2.0",
"getmac": "^1.4.6",
Copy link
Member

@akosyakov akosyakov Apr 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcdumais-work Could you please use your tool to verify this dep?

nvm https://dev.eclipse.org/ipzilla/show_bug.cgi?id=19584 is already resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Florent and I did the analysis anyway for the new dependency and its own recursive dependency tree. All licenses found are Foundation-approved:

Screenshot from 2019-04-24 10-29-59

"jsonc-parser": "^2.0.2",
"lodash.clonedeep": "^4.5.0",
"ps-tree": "1.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface ConfigStorage {

export interface EnvInit {
queryParams: QueryParameters;
language: string;
}

export interface PluginAPI {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class HostedPluginSupport {
preferences: getPreferences(this.preferenceProviderProvider),
globalState: initData.globalStates,
workspaceState: initData.workspaceStates,
env: { queryParams: getQueryParameters() },
env: { queryParams: getQueryParameters(), language: navigator.language },
extApi: initData.pluginAPIs
}, confStorage);
setUpPluginApi(worker.rpc, container);
Expand Down Expand Up @@ -174,7 +174,7 @@ export class HostedPluginSupport {
preferences: getPreferences(this.preferenceProviderProvider),
globalState: initData.globalStates,
workspaceState: initData.workspaceStates,
env: { queryParams: getQueryParameters() },
env: { queryParams: getQueryParameters(), language: navigator.language },
extApi: initData.pluginAPIs
}, confStorage);
this.mainPluginApiProviders.getContributions().forEach(p => p.initialize(rpc!, container));
Expand Down
37 changes: 37 additions & 0 deletions packages/plugin-ext/src/hosted/browser/worker/worker-env-ext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/********************************************************************************
* Copyright (C) 2019 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { EnvExtImpl } from '../../../plugin/env';
import { RPCProtocol } from '../../../api/rpc-protocol';

/**
* Worker specific implementation not returning any FileSystem details
* Extending the common class
*/
export class WorkerEnvExtImpl extends EnvExtImpl {

constructor(rpc: RPCProtocol) {
super(rpc);
}

/**
* Throw error for app-root as there is no filesystem in worker context
*/
get appRoot(): string {
throw new Error('There is no app root in worker context');
}

}
4 changes: 2 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 @@ -21,13 +21,13 @@ import { MAIN_RPC_CONTEXT, Plugin, emptyPlugin } from '../../../api/plugin-api';
import { createAPIFactory } from '../../../plugin/plugin-context';
import { getPluginId, PluginMetadata } from '../../../common/plugin-protocol';
import * as theia from '@theia/plugin';
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';
import { MessageRegistryExt } from '../../../plugin/message-registry';
import { WorkerEnvExtImpl } from './worker-env-ext';

// tslint:disable-next-line:no-any
const ctx = self as any;
Expand All @@ -49,7 +49,7 @@ addEventListener('message', (message: any) => {
function initialize(contextPath: string, pluginMetadata: PluginMetadata): void {
ctx.importScripts('/context/' + contextPath);
}
const envExt = new EnvExtImpl(rpc);
const envExt = new WorkerEnvExtImpl(rpc);
const editorsAndDocuments = new EditorsAndDocumentsExtImpl(rpc);
const messageRegistryExt = new MessageRegistryExt(rpc);
const workspaceExt = new WorkspaceExtImpl(rpc, editorsAndDocuments, messageRegistryExt);
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/hosted/node/plugin-host-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { DebugExtImpl } from '../../plugin/node/debug/debug';
import { EditorsAndDocumentsExtImpl } from '../../plugin/editors-and-documents';
import { WorkspaceExtImpl } from '../../plugin/workspace';
import { MessageRegistryExt } from '../../plugin/message-registry';
import { EnvNodeExtImpl } from '../../plugin/node/env-node-ext';

/**
* Handle the RPC calls.
Expand All @@ -40,7 +41,7 @@ export class PluginHostRPC {
}

initialize() {
const envExt = new EnvExtImpl(this.rpc);
const envExt = new EnvNodeExtImpl(this.rpc);
const debugExt = new DebugExtImpl(this.rpc);
const editorsAndDocumentsExt = new EditorsAndDocumentsExtImpl(this.rpc);
const messageRegistryExt = new MessageRegistryExt(this.rpc);
Expand Down
33 changes: 32 additions & 1 deletion packages/plugin-ext/src/plugin/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ import * as theia from '@theia/plugin';
import { RPCProtocol } from '../api/rpc-protocol';
import { EnvMain, PLUGIN_RPC_CONTEXT } from '../api/plugin-api';
import { QueryParameters } from '../common/env';
import { v4 } from 'uuid';

export class EnvExtImpl {
export abstract class EnvExtImpl {
private proxy: EnvMain;
private queryParameters: QueryParameters;
private lang: string;
private envMachineId: string;
private envSessionId: string;

public static readonly APP_NAME = 'Eclipse Theia';

constructor(rpc: RPCProtocol) {
this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.ENV_MAIN);
this.envSessionId = v4();
this.envMachineId = v4();
}

getEnvVariable(envVarName: string): Promise<string | undefined> {
Expand All @@ -48,7 +56,30 @@ export class EnvExtImpl {
this.queryParameters = queryParams;
}

setLanguage(lang: string): void {
this.lang = lang;
}

getClientOperatingSystem(): Promise<theia.OperatingSystem> {
return this.proxy.$getClientOperatingSystem();
}

get appName(): string {
return EnvExtImpl.APP_NAME;
}

abstract get appRoot(): string;

get language(): string {
return this.lang;
}
get machineId(): string {
return this.envMachineId;
}
get sessionId(): string {
return this.envSessionId;
}
get uriScheme(): string {
return 'theia';
}
}
57 changes: 57 additions & 0 deletions packages/plugin-ext/src/plugin/node/env-node-ext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/********************************************************************************
* Copyright (C) 2019 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { EnvExtImpl } from '../env';
import { RPCProtocol } from '../../api/rpc-protocol';
import { createHash } from 'crypto';
import { getMac } from 'getmac';
import { v4 } from 'uuid';

/**
* Provides machineId using mac address. It's only possible on node side
* Extending the common class
*/
export class EnvNodeExtImpl extends EnvExtImpl {

private macMachineId: string;

constructor(rpc: RPCProtocol) {
super(rpc);
getMac((err, macAddress) => {
if (err) {
this.macMachineId = v4();
} else {
this.macMachineId = createHash('sha256').update(macAddress, 'utf8').digest('hex');
}
});

}

/**
* override machineID
*/
get machineId(): string {
return this.macMachineId;
}

/**
* Provides application root.
*/
get appRoot(): string {
return __dirname;
}

}
11 changes: 9 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,14 @@ export function createAPIFactory(
}
};

const env: typeof theia.env = {
const env: typeof theia.env = Object.freeze({
get appName() { return envExt.appName; },
get appRoot() { return envExt.appRoot; },
get language() { return envExt.language; },
get machineId() { return envExt.machineId; },
get sessionId() { return envExt.sessionId; },
get uriScheme() { return envExt.uriScheme; },

getEnvVariable(envVarName: string): PromiseLike<string | undefined> {
return envExt.getEnvVariable(envVarName);
},
Expand All @@ -458,7 +465,7 @@ export function createAPIFactory(
return envExt.getClientOperatingSystem();
}

};
});

const languageServer: typeof theia.languageServer = {
registerLanguageServerProvider(languageServerInfo: theia.LanguageServerInfo): Disposable {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {

// init query parameters
this.envExt.setQueryParameters(pluginInit.env.queryParams);
this.envExt.setLanguage(pluginInit.env.language);

this.preferencesManager.init(pluginInit.preferences);

Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-ext/src/typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/********************************************************************************
* Copyright (C) 2019 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

declare module 'getmac' {
function getMac(cb: (error: Error, macAddress: string) => void): void;
}
32 changes: 32 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4232,6 +4232,38 @@ declare module '@theia/plugin' {
* Returns all query parameters of current IDE.
*/
export function getQueryParameters(): { [key: string]: string | string[] } | undefined;

/**
* The application name of the editor, like 'Eclipse Theia'.
*/
export const appName: string;

/**
* The application root folder from which the editor is running.
*/
export const appRoot: string;

/**
* The custom uri scheme the editor registers to in the operating system.
*/
export const uriScheme: string;

/**
* Represents the preferred user-language, like `de-CH`, `fr`, or `en-US`.
*/
export const language: string;

/**
* A unique identifier for the computer.
*/
export const machineId: string;

/**
* A unique identifier for the current session.
* Changes each time the editor is started.
*/
export const sessionId: string;

}

/**
Expand Down
Loading