From e384ca7461d40f3bead9474b7cd077b8466447f5 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 28 Jan 2019 06:01:56 -0800 Subject: [PATCH] Clean up terminal cwd handling --- .../mainThreadTerminalService.ts | 10 ++-------- .../api/node/extHostTerminalService.ts | 13 ++----------- .../electron-browser/terminalActions.ts | 19 +++++++++---------- .../terminalProcessManager.ts | 17 ++++++++--------- 4 files changed, 21 insertions(+), 38 deletions(-) diff --git a/src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts b/src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts index 3edd37683f0..bb267c2dbb4 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadTerminalService.ts @@ -214,14 +214,8 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape request.proxy.onInput(data => this._proxy.$acceptProcessInput(request.proxy.terminalId, data)); request.proxy.onResize(dimensions => this._proxy.$acceptProcessResize(request.proxy.terminalId, dimensions.cols, dimensions.rows)); request.proxy.onShutdown(immediate => this._proxy.$acceptProcessShutdown(request.proxy.terminalId, immediate)); - request.proxy.onRequestCwd(() => { - console.log('onRequestCwd', request.proxy.terminalId); - this._proxy.$acceptProcessRequestCwd(request.proxy.terminalId); - }); - request.proxy.onRequestInitialCwd(() => { - console.log('onRequestInitialCwd', request.proxy.terminalId); - this._proxy.$acceptProcessRequestInitialCwd(request.proxy.terminalId); - }); + request.proxy.onRequestCwd(() => this._proxy.$acceptProcessRequestCwd(request.proxy.terminalId)); + request.proxy.onRequestInitialCwd(() => this._proxy.$acceptProcessRequestInitialCwd(request.proxy.terminalId)); } public $sendProcessTitle(terminalId: number, title: string): void { diff --git a/src/vs/workbench/api/node/extHostTerminalService.ts b/src/vs/workbench/api/node/extHostTerminalService.ts index c99a43a3561..fd343a8de75 100644 --- a/src/vs/workbench/api/node/extHostTerminalService.ts +++ b/src/vs/workbench/api/node/extHostTerminalService.ts @@ -458,21 +458,12 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape { this._terminalProcesses[id].shutdown(immediate); } - // TODO: Also support initial cwd as it's evaluated on the ext host public $acceptProcessRequestInitialCwd(id: number): void { - console.log('$acceptProcessRequestInitialCwd', id); - this._terminalProcesses[id].getInitialCwd().then(initialCwd => { - console.log('initialCwd', initialCwd); - this._proxy.$sendProcessInitialCwd(id, initialCwd); - }); + this._terminalProcesses[id].getInitialCwd().then(initialCwd => this._proxy.$sendProcessInitialCwd(id, initialCwd)); } public $acceptProcessRequestCwd(id: number): void { - console.log('$acceptProcessRequestCwd', id); - this._terminalProcesses[id].getCwd().then(cwd => { - console.log('cwd', cwd); - this._proxy.$sendProcessCwd(id, cwd); - }); + this._terminalProcesses[id].getCwd().then(cwd => this._proxy.$sendProcessCwd(id, cwd)); } private _onProcessExit(id: number, exitCode: number): void { diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index 31564bafef7..ac30cb45070 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -30,15 +30,19 @@ import { Command } from 'vs/editor/browser/editorExtensions'; import { timeout } from 'vs/base/common/async'; import { FindReplaceState } from 'vs/editor/contrib/find/findState'; import { ISelectOptionItem } from 'vs/base/browser/ui/selectBox/selectBox'; +import { URI } from 'vs/base/common/uri'; export const TERMINAL_PICKER_PREFIX = 'term '; -function getCwdForSplit(configHelper: ITerminalConfigHelper, instance: ITerminalInstance, folders?: IWorkspaceFolder[], commandService?: ICommandService): Promise { +function getCwdForSplit(configHelper: ITerminalConfigHelper, instance: ITerminalInstance, folders?: IWorkspaceFolder[], commandService?: ICommandService): Promise { switch (configHelper.config.splitCwd) { case 'workspaceRoot': - // allow original behavior - let pathPromise: Promise = Promise.resolve(''); - if (folders.length > 1) { + let pathPromise: Promise; + if (folders.length === 0) { + pathPromise = Promise.resolve(''); + } else if (folders.length === 1) { + pathPromise = Promise.resolve(folders[0].uri); + } else if (folders.length > 1) { // Only choose a path when there's more than 1 folder const options: IPickOptions = { placeHolder: nls.localize('workbench.action.terminal.newWorkspacePlaceholder', "Select current working directory for new terminal") @@ -48,16 +52,13 @@ function getCwdForSplit(configHelper: ITerminalConfigHelper, instance: ITerminal // Don't split the instance if the workspace picker was canceled return undefined; } - return Promise.resolve(workspace.uri.fsPath); + return Promise.resolve(workspace.uri); }); } - return pathPromise; case 'initial': - console.log('getCwdForSplit initial'); return instance.getInitialCwd(); case 'inherited': - console.log('getCwdForSplit inherited'); return instance.getCwd(); } } @@ -382,9 +383,7 @@ export class SplitTerminalAction extends Action { if (!instance) { return Promise.resolve(undefined); } - console.log('SplitTerminalAction'); return getCwdForSplit(this._terminalService.configHelper, instance, this.workspaceContextService.getWorkspace().folders, this.commandService).then(cwd => { - console.log('SplitTerminalAction cwd', cwd); if (cwd || (cwd === '')) { this._terminalService.splitInstance(instance, { cwd }); return this._terminalService.showPanel(true); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts index ed59e4a655a..93f6d2ac0f1 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts @@ -35,8 +35,6 @@ export class TerminalProcessManager implements ITerminalProcessManager { public processState: ProcessState = ProcessState.UNINITIALIZED; public ptyProcessReady: Promise; public shellProcessId: number; - // TODO: This should be removed in favor of async getInitialCwd - public initialCwd: string; private _process: ITerminalChildProcess | null = null; private _preLaunchInputQueue: string[] = []; @@ -92,24 +90,25 @@ export class TerminalProcessManager implements ITerminalProcessManager { rows: number ): void { let launchRemotely = false; + const forceExtHostProcess = (this._configHelper.config as any).extHostProcess; if (shellLaunchConfig.cwd && typeof shellLaunchConfig.cwd === 'object') { launchRemotely = !!getRemoteAuthority(shellLaunchConfig.cwd); shellLaunchConfig.cwd = shellLaunchConfig.cwd.fsPath; } else { - launchRemotely = !!this._windowService.getConfiguration().remoteAuthority || (this._configHelper.config as any).extHostProcess; + launchRemotely = !!this._windowService.getConfiguration().remoteAuthority; } - if (launchRemotely) { - const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(REMOTE_HOST_SCHEME); + if (launchRemotely || forceExtHostProcess) { + const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(forceExtHostProcess ? undefined : REMOTE_HOST_SCHEME); this._process = this._instantiationService.createInstance(TerminalProcessExtHostProxy, this._terminalId, shellLaunchConfig, activeWorkspaceRootUri, cols, rows); } else { if (!shellLaunchConfig.executable) { this._configHelper.mergeDefaultShellPathAndArgs(shellLaunchConfig); } - // TODO: @daniel + const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file); - this.initialCwd = terminalEnvironment.getCwd(shellLaunchConfig, activeWorkspaceRootUri, this._configHelper.config.cwd); + const initialCwd = terminalEnvironment.getCwd(shellLaunchConfig, activeWorkspaceRootUri, this._configHelper.config.cwd); // Compel type system as process.env should not have any undefined entries let env: platform.IProcessEnvironment = {}; @@ -140,8 +139,8 @@ export class TerminalProcessManager implements ITerminalProcessManager { terminalEnvironment.addTerminalEnvironmentKeys(env, platform.locale, this._configHelper.config.setLocaleVariables); } - this._logService.debug(`Terminal process launching`, shellLaunchConfig, this.initialCwd, cols, rows, env); - this._process = new TerminalProcess(shellLaunchConfig, this.initialCwd, cols, rows, env, this._configHelper.config.windowsEnableConpty); + this._logService.debug(`Terminal process launching`, shellLaunchConfig, initialCwd, cols, rows, env); + this._process = new TerminalProcess(shellLaunchConfig, initialCwd, cols, rows, env, this._configHelper.config.windowsEnableConpty); } this.processState = ProcessState.LAUNCHING; -- GitLab