提交 2f28156f 编写于 作者: D Daniel Imms

Improved names and doc

上级 35694107
......@@ -52,7 +52,7 @@ export interface ITerminalConfiguration {
setLocaleVariables: boolean,
scrollback: number,
commandsToSkipShell: string[],
customStartPath: string
cwd: string
}
};
}
......@@ -64,7 +64,7 @@ export interface ITerminalConfigHelper {
getCursorBlink(): boolean;
getCommandsToSkipShell(): string[];
getScrollback(): number;
getCustomStartPath(): string;
getCwd(): string;
}
export interface ITerminalFont {
......@@ -78,8 +78,8 @@ export interface ITerminalFont {
export interface IShell {
executable: string;
args: string[];
/** Whether to ignore a custom start path (if the shell is being launched by an extension) */
ignoreCustomStartPath?: boolean;
/** Whether to ignore a custom cwd (if the shell is being launched by an extension) */
ignoreCustomCwd?: boolean;
}
export interface ITerminalService {
......@@ -94,7 +94,7 @@ export interface ITerminalService {
onInstanceTitleChanged: Event<string>;
terminalInstances: ITerminalInstance[];
createInstance(name?: string, shellPath?: string, shellArgs?: string[], ignoreCustomStartPath?: boolean): ITerminalInstance;
createInstance(name?: string, shellPath?: string, shellArgs?: string[], ignoreCustomCwd?: boolean): ITerminalInstance;
getInstanceFromId(terminalId: number): ITerminalInstance;
getInstanceLabels(): string[];
getActiveInstance(): ITerminalInstance;
......
......@@ -106,8 +106,8 @@ configurationRegistry.registerConfiguration({
'type': 'boolean',
'default': platform.isMacintosh
},
'terminal.integrated.customStartPath': {
'description': nls.localize('terminal.integrated.customStartPath', "If set, all terminals will start at this path."),
'terminal.integrated.cwd': {
'description': nls.localize('terminal.integrated.cwd', "An explicit start path where the terminal will be launched, this is used as the current working directory (cwd) for the shell process. This may be particularly useful in workspace settings if the root directory is not a convenient cwd."),
'type': 'string',
'default': undefined
},
......
......@@ -170,9 +170,9 @@ export class TerminalConfigHelper implements ITerminalConfigHelper {
return config.terminal.integrated.setLocaleVariables;
}
public getCustomStartPath(): string {
public getCwd(): string {
const config = this._configurationService.getConfiguration<ITerminalConfiguration>();
return config.terminal.integrated.customStartPath;
return config.terminal.integrated.cwd;
}
private _toInteger(source: any, minimum?: number): number {
......
......@@ -297,13 +297,13 @@ export class TerminalInstance implements ITerminalInstance {
return typeof data === 'string' ? data.replace(TerminalInstance.EOL_REGEX, os.EOL) : data;
}
protected _getNewProcessCwd(workspace: IWorkspace, ignoreCustomStartPath: boolean): string {
protected _getCwd(workspace: IWorkspace, ignoreCustomCwd: boolean): string {
let cwd;
// TODO: Handle non-existent customCwd
if (!ignoreCustomStartPath) {
if (!ignoreCustomCwd) {
// Evaluate custom cwd first
const customCwd = this._configHelper.getCustomStartPath();
const customCwd = this._configHelper.getCwd();
if (customCwd) {
if (path.isAbsolute(customCwd)) {
cwd = customCwd;
......@@ -326,7 +326,7 @@ export class TerminalInstance implements ITerminalInstance {
if (!shell.executable) {
shell = this._configHelper.getShell();
}
let env = TerminalInstance.createTerminalEnv(process.env, shell, this._getNewProcessCwd(workspace, shell.ignoreCustomStartPath), locale);
let env = TerminalInstance.createTerminalEnv(process.env, shell, this._getCwd(workspace, shell.ignoreCustomCwd), locale);
this._title = name ? name : '';
this._process = cp.fork('./terminalProcess', [], {
env: env,
......
......@@ -62,11 +62,11 @@ export class TerminalService implements ITerminalService {
this.onInstanceDisposed((terminalInstance) => { this._removeInstance(terminalInstance); });
}
public createInstance(name?: string, shellPath?: string, shellArgs?: string[], ignoreCustomStartPath?: boolean): ITerminalInstance {
public createInstance(name?: string, shellPath?: string, shellArgs?: string[], ignoreCustomCwd?: boolean): ITerminalInstance {
let shell: IShell = {
executable: shellPath,
args: shellArgs,
ignoreCustomStartPath
ignoreCustomCwd
};
let terminalInstance = <TerminalInstance>this._instantiationService.createInstance(TerminalInstance,
this._terminalFocusContextKey,
......
......@@ -20,8 +20,8 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
class TestTerminalInstance extends TerminalInstance {
public _getNewProcessCwd(workspace: IWorkspace, ignoreCustomStartPath: boolean): string {
return super._getNewProcessCwd(workspace, ignoreCustomStartPath);
public _getCwd(workspace: IWorkspace, ignoreCustomCwd: boolean): string {
return super._getCwd(workspace, ignoreCustomCwd);
}
protected _createProcess(workspace: IWorkspace, name: string, shell: IShell): void { }
......@@ -74,10 +74,10 @@ suite('Workbench - TerminalInstance', () => {
assert.equal(env4['LANG'], 'en_US.UTF-8', 'LANG is equal to the parent environment\'s LANG');
});
suite('_getNewProcessCwd', () => {
suite('_getCwd', () => {
let instance: TestTerminalInstance;
let instantiationService: TestInstantiationService;
let configHelper: { getCustomStartPath: () => string };
let configHelper: { getCwd: () => string };
setup(() => {
let contextKeyService = new MockKeybindingService();
......@@ -88,45 +88,45 @@ suite('Workbench - TerminalInstance', () => {
instantiationService.stub(IKeybindingService, keybindingService);
instantiationService.stub(IContextKeyService, contextKeyService);
configHelper = {
getCustomStartPath: () => null
getCwd: () => null
};
instance = instantiationService.createInstance(TestTerminalInstance, terminalFocusContextKey, configHelper, null, null, null, null);
});
test('should default to os.homedir() for an empty workspace', () => {
assert.equal(instance._getNewProcessCwd(null, false), os.homedir());
assert.equal(instance._getCwd(null, false), os.homedir());
});
test('should use to the workspace if it exists', () => {
assert.equal(instance._getNewProcessCwd({ resource: Uri.file('/foo') }, false), '/foo');
assert.equal(instance._getCwd({ resource: Uri.file('/foo') }, false), '/foo');
});
test('should use an absolute custom start path as is', () => {
configHelper.getCustomStartPath = () => '/foo';
assert.equal(instance._getNewProcessCwd(null, false), '/foo');
test('should use an absolute custom cwd as is', () => {
configHelper.getCwd = () => '/foo';
assert.equal(instance._getCwd(null, false), '/foo');
});
test('should normalize a relative custom start path against the workspace path', () => {
configHelper.getCustomStartPath = () => 'foo';
assert.equal(instance._getNewProcessCwd({ resource: Uri.file('/bar') }, false), '/bar/foo');
configHelper.getCustomStartPath = () => './foo';
assert.equal(instance._getNewProcessCwd({ resource: Uri.file('/bar') }, false), '/bar/foo');
configHelper.getCustomStartPath = () => '../foo';
assert.equal(instance._getNewProcessCwd({ resource: Uri.file('/bar') }, false), '/foo');
test('should normalize a relative custom cwd against the workspace path', () => {
configHelper.getCwd = () => 'foo';
assert.equal(instance._getCwd({ resource: Uri.file('/bar') }, false), '/bar/foo');
configHelper.getCwd = () => './foo';
assert.equal(instance._getCwd({ resource: Uri.file('/bar') }, false), '/bar/foo');
configHelper.getCwd = () => '../foo';
assert.equal(instance._getCwd({ resource: Uri.file('/bar') }, false), '/foo');
});
test('should fall back for relative custom start paths that don\'t have a workspace', () => {
configHelper.getCustomStartPath = () => 'foo';
assert.equal(instance._getNewProcessCwd(null, false), os.homedir());
configHelper.getCustomStartPath = () => './foo';
assert.equal(instance._getNewProcessCwd(null, false), os.homedir());
configHelper.getCustomStartPath = () => '../foo';
assert.equal(instance._getNewProcessCwd(null, false), os.homedir());
test('should fall back for relative a custom cwd that doesn\'t have a workspace', () => {
configHelper.getCwd = () => 'foo';
assert.equal(instance._getCwd(null, false), os.homedir());
configHelper.getCwd = () => './foo';
assert.equal(instance._getCwd(null, false), os.homedir());
configHelper.getCwd = () => '../foo';
assert.equal(instance._getCwd(null, false), os.homedir());
});
test('should ignore custom start path when arg exists', () => {
configHelper.getCustomStartPath = () => '/foo';
assert.equal(instance._getNewProcessCwd({ resource: Uri.file('/bar') }, true), '/bar');
test('should ignore custom cwd when told to ignore', () => {
configHelper.getCwd = () => '/foo';
assert.equal(instance._getCwd({ resource: Uri.file('/bar') }, true), '/bar');
});
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册