From f62945f5835a2838258acfe3e401d531d53e8148 Mon Sep 17 00:00:00 2001 From: Amiram Wingarten Date: Fri, 28 Jun 2019 14:40:31 +0300 Subject: [PATCH] plugin-dev - fix run/debug flow to work on windows - use fileSystem.getFsPath utility for HOSTED_PLUGIN as it also supports windows - fixed typos (one in HostedInstanceState enum is added to changelog) - removed member `processOptions` from `AbstractHostedInstanceManager` as it is not initialized or used (changelog updated) - add missing dependencies in package.json Signed-off-by: Amiram Wingarten --- CHANGELOG.md | 7 ++ packages/filesystem/src/common/filesystem.ts | 2 +- packages/plugin-dev/package.json | 107 +++++++++--------- .../src/browser/hosted-plugin-controller.ts | 8 +- .../browser/hosted-plugin-manager-client.ts | 6 +- .../src/node/hosted-instance-manager.ts | 29 +++-- 6 files changed, 87 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be0c0163df4fb..fdbd26c011c20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## v0.9.0 + +Breaking changes: + +- [plugin] fixed typo in 'HostedInstanceState' enum from RUNNNING to RUNNING in `plugin-dev` extension +- [plugin] removed member `processOptions` from `AbstractHostedInstanceManager` as it is not initialized or used + ## v0.8.0 - [core] added bépo keyboard layout diff --git a/packages/filesystem/src/common/filesystem.ts b/packages/filesystem/src/common/filesystem.ts index cfddd74da11af..b559372c9d6a9 100644 --- a/packages/filesystem/src/common/filesystem.ts +++ b/packages/filesystem/src/common/filesystem.ts @@ -134,7 +134,7 @@ export interface FileSystem extends JsonRpcServer { * If the URI is not a file URI, undefined is returned. * * USE WITH CAUTION: You should always prefer URIs to paths if possible, as they are - * portable and platform independent. Pathes should only be used in cases you directly + * portable and platform independent. Paths should only be used in cases you directly * interact with the OS, e.g. when running a command on the shell. */ getFsPath(uri: string): Promise diff --git a/packages/plugin-dev/package.json b/packages/plugin-dev/package.json index a9b8e42963ce8..de28273e2f3dc 100644 --- a/packages/plugin-dev/package.json +++ b/packages/plugin-dev/package.json @@ -1,52 +1,55 @@ -{ - "name": "@theia/plugin-dev", - "version": "0.8.0", - "description": "Theia - Plugin Development Extension", - "main": "lib/common/index.js", - "typings": "lib/common/index.d.ts", - "dependencies": { - "@theia/core": "^0.8.0", - "@theia/plugin-ext": "^0.8.0", - "@theia/preferences": "^0.8.0", - "ps-tree": "1.1.0" - }, - "publishConfig": { - "access": "public" - }, - "theiaExtensions": [ - { - "backend": "lib/node/plugin-dev-backend-module", - "backendElectron": "lib/node-electron/plugin-dev-electron-backend-module", - "frontend": "lib/browser/plugin-dev-frontend-module" - } - ], - "keywords": [ - "theia-extension" - ], - "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", - "repository": { - "type": "git", - "url": "https://github.com/theia-ide/theia.git" - }, - "bugs": { - "url": "https://github.com/theia-ide/theia/issues" - }, - "homepage": "https://github.com/theia-ide/theia", - "files": [ - "lib", - "src" - ], - "scripts": { - "prepare": "yarn run clean && yarn run build", - "clean": "theiaext clean", - "build": "theiaext build", - "watch": "theiaext watch", - "test": "theiaext test" - }, - "devDependencies": { - "@theia/ext-scripts": "^0.8.0" - }, - "nyc": { - "extends": "../../configs/nyc.json" - } -} +{ + "name": "@theia/plugin-dev", + "version": "0.8.0", + "description": "Theia - Plugin Development Extension", + "main": "lib/common/index.js", + "typings": "lib/common/index.d.ts", + "dependencies": { + "@theia/core": "^0.8.0", + "@theia/workspace": "^0.8.0", + "@theia/filesystem": "^0.8.0", + "@theia/plugin-ext": "^0.8.0", + "@theia/debug": "^0.8.0", + "@theia/preferences": "^0.8.0", + "ps-tree": "1.1.0" + }, + "publishConfig": { + "access": "public" + }, + "theiaExtensions": [ + { + "backend": "lib/node/plugin-dev-backend-module", + "backendElectron": "lib/node-electron/plugin-dev-electron-backend-module", + "frontend": "lib/browser/plugin-dev-frontend-module" + } + ], + "keywords": [ + "theia-extension" + ], + "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", + "repository": { + "type": "git", + "url": "https://github.com/theia-ide/theia.git" + }, + "bugs": { + "url": "https://github.com/theia-ide/theia/issues" + }, + "homepage": "https://github.com/theia-ide/theia", + "files": [ + "lib", + "src" + ], + "scripts": { + "prepare": "yarn run clean && yarn run build", + "clean": "theiaext clean", + "build": "theiaext build", + "watch": "theiaext watch", + "test": "theiaext test" + }, + "devDependencies": { + "@theia/ext-scripts": "^0.8.0" + }, + "nyc": { + "extends": "../../configs/nyc.json" + } +} diff --git a/packages/plugin-dev/src/browser/hosted-plugin-controller.ts b/packages/plugin-dev/src/browser/hosted-plugin-controller.ts index a234a2bd0877c..ebfda96927af5 100644 --- a/packages/plugin-dev/src/browser/hosted-plugin-controller.ts +++ b/packages/plugin-dev/src/browser/hosted-plugin-controller.ts @@ -79,7 +79,7 @@ export class HostedPluginController implements FrontendApplicationContribution { this.hostedPluginManagerClient.onStateChanged(e => { if (e.state === HostedInstanceState.STARTING) { this.onHostedPluginStarting(); - } else if (e.state === HostedInstanceState.RUNNNING) { + } else if (e.state === HostedInstanceState.RUNNING) { this.onHostedPluginRunning(); } else if (e.state === HostedInstanceState.STOPPED) { this.onHostedPluginStopped(); @@ -149,7 +149,7 @@ export class HostedPluginController implements FrontendApplicationContribution { * Display status bar element for running plugin. */ protected async onHostedPluginRunning(): Promise { - this.pluginState = HostedInstanceState.RUNNNING; + this.pluginState = HostedInstanceState.RUNNING; let entryText: string; if (this.hostedPluginPreferences['hosted-plugin.watchMode'] && this.watcherSuccess) { @@ -216,7 +216,7 @@ export class HostedPluginController implements FrontendApplicationContribution { * @param event hosted instance state change event */ protected async handleWatchers(event: HostedInstanceData): Promise { - if (event.state === HostedInstanceState.RUNNNING) { + if (event.state === HostedInstanceState.RUNNING) { if (this.hostedPluginPreferences['hosted-plugin.watchMode']) { await this.runWatchCompilation(event.pluginLocation.toString()); // update status bar @@ -289,7 +289,7 @@ export class HostedPluginController implements FrontendApplicationContribution { commands }); - if (this.pluginState === HostedInstanceState.RUNNNING) { + if (this.pluginState === HostedInstanceState.RUNNING) { this.addCommandsForRunningPlugin(commands, menu); } else if (this.pluginState === HostedInstanceState.STOPPED || this.pluginState === HostedInstanceState.FAILED) { this.addCommandsForStoppedPlugin(commands, menu); diff --git a/packages/plugin-dev/src/browser/hosted-plugin-manager-client.ts b/packages/plugin-dev/src/browser/hosted-plugin-manager-client.ts index d42e29ceb70f1..70fc362dd7b00 100644 --- a/packages/plugin-dev/src/browser/hosted-plugin-manager-client.ts +++ b/packages/plugin-dev/src/browser/hosted-plugin-manager-client.ts @@ -68,7 +68,7 @@ export namespace HostedPluginCommands { export enum HostedInstanceState { STOPPED = 'stopped', STARTING = 'starting', - RUNNNING = 'running', + RUNNING = 'running', STOPPING = 'stopping', FAILED = 'failed' } @@ -161,7 +161,7 @@ export class HostedPluginManagerClient { await this.openPluginWindow(); this.messageService.info('Hosted instance is running at: ' + this.pluginInstanceURL); - this.stateChanged.fire({ state: HostedInstanceState.RUNNNING, pluginLocation: this.pluginLocation }); + this.stateChanged.fire({ state: HostedInstanceState.RUNNING, pluginLocation: this.pluginLocation }); } catch (error) { this.messageService.error('Failed to run hosted plugin instance: ' + this.getErrorMessage(error)); this.stateChanged.fire({ state: HostedInstanceState.FAILED, pluginLocation: this.pluginLocation }); @@ -224,7 +224,7 @@ export class HostedPluginManagerClient { this.pluginInstanceURL = await this.hostedPluginServer.runHostedPluginInstance(this.pluginLocation!.toString()); await this.openPluginWindow(); this.messageService.info('Hosted instance is running at: ' + this.pluginInstanceURL); - this.stateChanged.fire({ state: HostedInstanceState.RUNNNING, pluginLocation: this.pluginLocation! }); + this.stateChanged.fire({ state: HostedInstanceState.RUNNING, pluginLocation: this.pluginLocation! }); return; } catch (error) { lastError = error; diff --git a/packages/plugin-dev/src/node/hosted-instance-manager.ts b/packages/plugin-dev/src/node/hosted-instance-manager.ts index 53c859c99f567..d50e270773182 100644 --- a/packages/plugin-dev/src/node/hosted-instance-manager.ts +++ b/packages/plugin-dev/src/node/hosted-instance-manager.ts @@ -30,6 +30,8 @@ import { FileUri } from '@theia/core/lib/node/file-uri'; import { LogType } from '@theia/plugin-ext/lib/common/types'; import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin'; import { MetadataScanner } from '@theia/plugin-ext/lib/hosted/node/metadata-scanner'; +import { FileSystem } from '@theia/filesystem/lib/common'; + const processTree = require('ps-tree'); export const HostedInstanceManager = Symbol('HostedInstanceManager'); @@ -97,8 +99,7 @@ delete PROCESS_OPTIONS.env.ELECTRON_RUN_AS_NODE; @injectable() export abstract class AbstractHostedInstanceManager implements HostedInstanceManager { protected hostedInstanceProcess: cp.ChildProcess; - protected processOptions: cp.SpawnOptions; - protected isPluginRunnig: boolean = false; + protected isPluginRunning: boolean = false; protected instanceUri: URI; protected pluginUri: URI; protected instanceOptions: object; @@ -109,8 +110,11 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan @inject(MetadataScanner) protected readonly metadata: MetadataScanner; + @inject(FileSystem) + protected readonly fileSystem: FileSystem; + isRunning(): boolean { - return this.isPluginRunnig; + return this.isPluginRunning; } async run(pluginUri: URI, port?: number): Promise { @@ -122,7 +126,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan } private async doRun(pluginUri: URI, port?: number, debugConfig?: DebugConfiguration): Promise { - if (this.isPluginRunnig) { + if (this.isPluginRunning) { this.hostedPluginSupport.sendLog({ data: 'Hosted plugin instance is already running.', type: LogType.Info }); throw new Error('Hosted instance is already running.'); } @@ -131,7 +135,8 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan let processOptions: cp.SpawnOptions; if (pluginUri.scheme === 'file') { processOptions = { ...PROCESS_OPTIONS }; - processOptions.env.HOSTED_PLUGIN = pluginUri.path.toString(); + // get filesystem path that work cross operating systems + processOptions.env.HOSTED_PLUGIN = await this.fileSystem.getFsPath(pluginUri.toString()); // Disable all the other plugins on this instance processOptions.env.THEIA_PLUGINS = ''; @@ -154,7 +159,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan } terminate(): void { - if (this.isPluginRunnig) { + if (this.isPluginRunning) { // tslint:disable-next-line:no-any processTree(this.hostedInstanceProcess.pid, (err: Error, children: Array) => { // tslint:disable-next-line:no-any @@ -168,14 +173,14 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan } getInstanceURI(): URI { - if (this.isPluginRunnig) { + if (this.isPluginRunning) { return this.instanceUri; } throw new Error('Hosted plugin instance is not running.'); } getPluginURI(): URI { - if (this.isPluginRunnig) { + if (this.isPluginRunning) { return this.pluginUri; } throw new Error('Hosted plugin instance is not running.'); @@ -290,7 +295,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan } protected runHostedPluginTheiaInstance(command: string[], options: cp.SpawnOptions): Promise { - this.isPluginRunnig = true; + this.isPluginRunning = true; return new Promise((resolve, reject) => { let started = false; const outputListener = (data: string | Buffer) => { @@ -304,8 +309,8 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan }; this.hostedInstanceProcess = cp.spawn(command.shift()!, command, options); - this.hostedInstanceProcess.on('error', () => { this.isPluginRunnig = false; }); - this.hostedInstanceProcess.on('exit', () => { this.isPluginRunnig = false; }); + this.hostedInstanceProcess.on('error', () => { this.isPluginRunning = false; }); + this.hostedInstanceProcess.on('exit', () => { this.isPluginRunning = false; }); this.hostedInstanceProcess.stdout.addListener('data', outputListener); this.hostedInstanceProcess.stdout.addListener('data', data => { @@ -318,7 +323,7 @@ export abstract class AbstractHostedInstanceManager implements HostedInstanceMan setTimeout(() => { if (!started) { this.terminate(); - this.isPluginRunnig = false; + this.isPluginRunning = false; reject(new Error('Timeout.')); } }, HOSTED_INSTANCE_START_TIMEOUT_MS);