提交 e384ca74 编写于 作者: D Daniel Imms

Clean up terminal cwd handling

上级 88467576
......@@ -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 {
......
......@@ -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 {
......
......@@ -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<string | undefined> {
function getCwdForSplit(configHelper: ITerminalConfigHelper, instance: ITerminalInstance, folders?: IWorkspaceFolder[], commandService?: ICommandService): Promise<string | URI> {
switch (configHelper.config.splitCwd) {
case 'workspaceRoot':
// allow original behavior
let pathPromise: Promise<string> = Promise.resolve('');
if (folders.length > 1) {
let pathPromise: Promise<string | URI>;
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<IQuickPickItem> = {
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);
......
......@@ -35,8 +35,6 @@ export class TerminalProcessManager implements ITerminalProcessManager {
public processState: ProcessState = ProcessState.UNINITIALIZED;
public ptyProcessReady: Promise<void>;
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册