mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-31 17:20:28 -04:00
Vscode merge (#4582)
* Merge from vscode 37cb23d3dd4f9433d56d4ba5ea3203580719a0bd * fix issues with merges * bump node version in azpipe * replace license headers * remove duplicate launch task * fix build errors * fix build errors * fix tslint issues * working through package and linux build issues * more work * wip * fix packaged builds * working through linux build errors * wip * wip * wip * fix mac and linux file limits * iterate linux pipeline * disable editor typing * revert series to parallel * remove optimize vscode from linux * fix linting issues * revert testing change * add work round for new node * readd packaging for extensions * fix issue with angular not resolving decorator dependencies
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IProcessEnvironment } from 'vs/base/common/platform';
|
||||
|
||||
export const IExternalTerminalService = createDecorator<IExternalTerminalService>('nativeTerminalService');
|
||||
|
||||
export interface IExternalTerminalService {
|
||||
_serviceBrand: any;
|
||||
openTerminal(path: string): void;
|
||||
runInTerminal(title: string, cwd: string, args: string[], env: IProcessEnvironment): Promise<number | undefined>;
|
||||
}
|
||||
|
||||
export interface IExternalTerminalConfiguration {
|
||||
terminal: {
|
||||
explorerKind: 'integrated' | 'external',
|
||||
external: {
|
||||
linuxExec: string,
|
||||
osxExec: string,
|
||||
windowsExec: string
|
||||
}
|
||||
};
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,155 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import * as env from 'vs/base/common/platform';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import * as paths from 'vs/base/common/path';
|
||||
import { URI as uri } from 'vs/base/common/uri';
|
||||
import { IExternalTerminalConfiguration, IExternalTerminalService } from 'vs/workbench/contrib/externalTerminal/common/externalTerminal';
|
||||
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { Extensions, IConfigurationRegistry, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { ITerminalService as IIntegratedTerminalService, KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED } from 'vs/workbench/contrib/terminal/common/terminal';
|
||||
import { getDefaultTerminalWindows, getDefaultTerminalLinuxReady, DEFAULT_TERMINAL_OSX } from 'vs/workbench/contrib/externalTerminal/electron-browser/externalTerminal';
|
||||
import { WindowsExternalTerminalService, MacExternalTerminalService, LinuxExternalTerminalService } from 'vs/workbench/contrib/externalTerminal/electron-browser/externalTerminalService';
|
||||
import { IHistoryService } from 'vs/workbench/services/history/common/history';
|
||||
import { ResourceContextKey } from 'vs/workbench/common/resources';
|
||||
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { IListService } from 'vs/platform/list/browser/listService';
|
||||
import { getMultiSelectedResources } from 'vs/workbench/contrib/files/browser/files';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { distinct } from 'vs/base/common/arrays';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
|
||||
if (env.isWindows) {
|
||||
registerSingleton(IExternalTerminalService, WindowsExternalTerminalService, true);
|
||||
} else if (env.isMacintosh) {
|
||||
registerSingleton(IExternalTerminalService, MacExternalTerminalService, true);
|
||||
} else if (env.isLinux) {
|
||||
registerSingleton(IExternalTerminalService, LinuxExternalTerminalService, true);
|
||||
}
|
||||
|
||||
getDefaultTerminalLinuxReady().then(defaultTerminalLinux => {
|
||||
let configurationRegistry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
id: 'externalTerminal',
|
||||
order: 100,
|
||||
title: nls.localize('terminalConfigurationTitle', "External Terminal"),
|
||||
type: 'object',
|
||||
properties: {
|
||||
'terminal.explorerKind': {
|
||||
type: 'string',
|
||||
enum: [
|
||||
'integrated',
|
||||
'external'
|
||||
],
|
||||
enumDescriptions: [
|
||||
nls.localize('terminal.explorerKind.integrated', "Use VS Code's integrated terminal."),
|
||||
nls.localize('terminal.explorerKind.external', "Use the configured external terminal.")
|
||||
],
|
||||
description: nls.localize('explorer.openInTerminalKind', "Customizes what kind of terminal to launch."),
|
||||
default: 'integrated'
|
||||
},
|
||||
'terminal.external.windowsExec': {
|
||||
type: 'string',
|
||||
description: nls.localize('terminal.external.windowsExec', "Customizes which terminal to run on Windows."),
|
||||
default: getDefaultTerminalWindows(),
|
||||
scope: ConfigurationScope.APPLICATION
|
||||
},
|
||||
'terminal.external.osxExec': {
|
||||
type: 'string',
|
||||
description: nls.localize('terminal.external.osxExec', "Customizes which terminal application to run on macOS."),
|
||||
default: DEFAULT_TERMINAL_OSX,
|
||||
scope: ConfigurationScope.APPLICATION
|
||||
},
|
||||
'terminal.external.linuxExec': {
|
||||
type: 'string',
|
||||
description: nls.localize('terminal.external.linuxExec', "Customizes which terminal to run on Linux."),
|
||||
default: defaultTerminalLinux,
|
||||
scope: ConfigurationScope.APPLICATION
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const OPEN_IN_TERMINAL_COMMAND_ID = 'openInTerminal';
|
||||
CommandsRegistry.registerCommand({
|
||||
id: OPEN_IN_TERMINAL_COMMAND_ID,
|
||||
handler: (accessor, resource: uri) => {
|
||||
const configurationService = accessor.get(IConfigurationService);
|
||||
const editorService = accessor.get(IEditorService);
|
||||
const fileService = accessor.get(IFileService);
|
||||
const integratedTerminalService = accessor.get(IIntegratedTerminalService);
|
||||
const terminalService = accessor.get(IExternalTerminalService);
|
||||
const resources = getMultiSelectedResources(resource, accessor.get(IListService), editorService);
|
||||
|
||||
return fileService.resolveFiles(resources.map(r => ({ resource: r }))).then(stats => {
|
||||
const directoriesToOpen = distinct(stats.filter(data => data.success).map(({ stat }) => stat!.isDirectory ? stat!.resource.fsPath : paths.dirname(stat!.resource.fsPath)));
|
||||
return directoriesToOpen.map(dir => {
|
||||
if (configurationService.getValue<IExternalTerminalConfiguration>().terminal.explorerKind === 'integrated') {
|
||||
const instance = integratedTerminalService.createTerminal({ cwd: dir }, true);
|
||||
if (instance && (resources.length === 1 || !resource || dir === resource.fsPath || dir === paths.dirname(resource.fsPath))) {
|
||||
integratedTerminalService.setActiveInstance(instance);
|
||||
integratedTerminalService.showPanel(true);
|
||||
}
|
||||
} else {
|
||||
terminalService.openTerminal(dir);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const OPEN_NATIVE_CONSOLE_COMMAND_ID = 'workbench.action.terminal.openNativeConsole';
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: OPEN_NATIVE_CONSOLE_COMMAND_ID,
|
||||
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_C,
|
||||
when: KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED,
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
handler: (accessor) => {
|
||||
const historyService = accessor.get(IHistoryService);
|
||||
const terminalService = accessor.get(IExternalTerminalService);
|
||||
const root = historyService.getLastActiveWorkspaceRoot(Schemas.file);
|
||||
if (root) {
|
||||
terminalService.openTerminal(root.fsPath);
|
||||
} else {
|
||||
// Opens current file's folder, if no folder is open in editor
|
||||
const activeFile = historyService.getLastActiveFile(Schemas.file);
|
||||
if (activeFile) {
|
||||
terminalService.openTerminal(paths.dirname(activeFile.fsPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
|
||||
command: {
|
||||
id: OPEN_NATIVE_CONSOLE_COMMAND_ID,
|
||||
title: { value: nls.localize('globalConsoleAction', "Open New Terminal"), original: 'Open New Terminal' }
|
||||
}
|
||||
});
|
||||
|
||||
const openConsoleCommand = {
|
||||
id: OPEN_IN_TERMINAL_COMMAND_ID,
|
||||
title: nls.localize('scopedConsoleAction', "Open in Terminal")
|
||||
};
|
||||
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
|
||||
group: 'navigation',
|
||||
order: 30,
|
||||
command: openConsoleCommand,
|
||||
when: ResourceContextKey.Scheme.isEqualTo(Schemas.file)
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
|
||||
group: 'navigation',
|
||||
order: 30,
|
||||
command: openConsoleCommand,
|
||||
when: ResourceContextKey.Scheme.isEqualTo(Schemas.file)
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as env from 'vs/base/common/platform';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
|
||||
let _DEFAULT_TERMINAL_LINUX_READY: Promise<string> | null = null;
|
||||
export function getDefaultTerminalLinuxReady(): Promise<string> {
|
||||
if (!_DEFAULT_TERMINAL_LINUX_READY) {
|
||||
_DEFAULT_TERMINAL_LINUX_READY = new Promise<string>(c => {
|
||||
if (env.isLinux) {
|
||||
Promise.all([pfs.exists('/etc/debian_version'), process.lazyEnv || Promise.resolve(undefined)]).then(([isDebian]) => {
|
||||
if (isDebian) {
|
||||
c('x-terminal-emulator');
|
||||
} else if (process.env.DESKTOP_SESSION === 'gnome' || process.env.DESKTOP_SESSION === 'gnome-classic') {
|
||||
c('gnome-terminal');
|
||||
} else if (process.env.DESKTOP_SESSION === 'kde-plasma') {
|
||||
c('konsole');
|
||||
} else if (process.env.COLORTERM) {
|
||||
c(process.env.COLORTERM);
|
||||
} else if (process.env.TERM) {
|
||||
c(process.env.TERM);
|
||||
} else {
|
||||
c('xterm');
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
c('xterm');
|
||||
});
|
||||
}
|
||||
return _DEFAULT_TERMINAL_LINUX_READY;
|
||||
}
|
||||
|
||||
export const DEFAULT_TERMINAL_OSX = 'Terminal.app';
|
||||
|
||||
let _DEFAULT_TERMINAL_WINDOWS: string | null = null;
|
||||
export function getDefaultTerminalWindows(): string {
|
||||
if (!_DEFAULT_TERMINAL_WINDOWS) {
|
||||
const isWoW64 = !!process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
|
||||
_DEFAULT_TERMINAL_WINDOWS = `${process.env.windir ? process.env.windir : 'C:\\Windows'}\\${isWoW64 ? 'Sysnative' : 'System32'}\\cmd.exe`;
|
||||
}
|
||||
return _DEFAULT_TERMINAL_WINDOWS;
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as cp from 'child_process';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as processes from 'vs/base/node/processes';
|
||||
import * as nls from 'vs/nls';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { IExternalTerminalService, IExternalTerminalConfiguration } from 'vs/workbench/contrib/externalTerminal/common/externalTerminal';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { getDefaultTerminalWindows, getDefaultTerminalLinuxReady, DEFAULT_TERMINAL_OSX } from 'vs/workbench/contrib/externalTerminal/electron-browser/externalTerminal';
|
||||
import { IProcessEnvironment } from 'vs/base/common/platform';
|
||||
import { getPathFromAmdModule } from 'vs/base/common/amd';
|
||||
|
||||
const TERMINAL_TITLE = nls.localize('console.title', "VS Code Console");
|
||||
|
||||
enum WinSpawnType {
|
||||
CMD,
|
||||
CMDER
|
||||
}
|
||||
|
||||
export class WindowsExternalTerminalService implements IExternalTerminalService {
|
||||
public _serviceBrand: any;
|
||||
|
||||
private static readonly CMD = 'cmd.exe';
|
||||
|
||||
constructor(
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService
|
||||
) {
|
||||
}
|
||||
|
||||
public openTerminal(cwd?: string): void {
|
||||
const configuration = this._configurationService.getValue<IExternalTerminalConfiguration>();
|
||||
|
||||
this.spawnTerminal(cp, configuration, processes.getWindowsShell(), cwd);
|
||||
}
|
||||
|
||||
public runInTerminal(title: string, dir: string, args: string[], envVars: IProcessEnvironment): Promise<number | undefined> {
|
||||
|
||||
const configuration = this._configurationService.getValue<IExternalTerminalConfiguration>();
|
||||
const terminalConfig = configuration.terminal.external;
|
||||
const exec = terminalConfig.windowsExec || getDefaultTerminalWindows();
|
||||
|
||||
return new Promise<number | undefined>((c, e) => {
|
||||
|
||||
const title = `"${dir} - ${TERMINAL_TITLE}"`;
|
||||
const command = `""${args.join('" "')}" & pause"`; // use '|' to only pause on non-zero exit code
|
||||
|
||||
const cmdArgs = [
|
||||
'/c', 'start', title, '/wait', exec, '/c', command
|
||||
];
|
||||
|
||||
// merge environment variables into a copy of the process.env
|
||||
const env = assign({}, process.env, envVars);
|
||||
|
||||
// delete environment variables that have a null value
|
||||
Object.keys(env).filter(v => env[v] === null).forEach(key => delete env[key]);
|
||||
|
||||
const options: any = {
|
||||
cwd: dir,
|
||||
env: env,
|
||||
windowsVerbatimArguments: true
|
||||
};
|
||||
|
||||
const cmd = cp.spawn(WindowsExternalTerminalService.CMD, cmdArgs, options);
|
||||
cmd.on('error', e);
|
||||
|
||||
c(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
private spawnTerminal(spawner, configuration: IExternalTerminalConfiguration, command: string, cwd?: string): Promise<void> {
|
||||
const terminalConfig = configuration.terminal.external;
|
||||
const exec = terminalConfig.windowsExec || getDefaultTerminalWindows();
|
||||
const spawnType = this.getSpawnType(exec);
|
||||
|
||||
// Make the drive letter uppercase on Windows (see #9448)
|
||||
if (cwd && cwd[1] === ':') {
|
||||
cwd = cwd[0].toUpperCase() + cwd.substr(1);
|
||||
}
|
||||
|
||||
// cmder ignores the environment cwd and instead opts to always open in %USERPROFILE%
|
||||
// unless otherwise specified
|
||||
if (spawnType === WinSpawnType.CMDER) {
|
||||
spawner.spawn(exec, [cwd]);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
const cmdArgs = ['/c', 'start', '/wait'];
|
||||
if (exec.indexOf(' ') >= 0) {
|
||||
// The "" argument is the window title. Without this, exec doesn't work when the path
|
||||
// contains spaces
|
||||
cmdArgs.push('""');
|
||||
}
|
||||
cmdArgs.push(exec);
|
||||
|
||||
return new Promise<void>((c, e) => {
|
||||
const env = cwd ? { cwd: cwd } : undefined;
|
||||
const child = spawner.spawn(command, cmdArgs, env);
|
||||
child.on('error', e);
|
||||
child.on('exit', () => c());
|
||||
});
|
||||
}
|
||||
|
||||
private getSpawnType(exec: string): WinSpawnType {
|
||||
const basename = path.basename(exec).toLowerCase();
|
||||
if (basename === 'cmder' || basename === 'cmder.exe') {
|
||||
return WinSpawnType.CMDER;
|
||||
}
|
||||
return WinSpawnType.CMD;
|
||||
}
|
||||
}
|
||||
|
||||
export class MacExternalTerminalService implements IExternalTerminalService {
|
||||
public _serviceBrand: any;
|
||||
|
||||
private static readonly OSASCRIPT = '/usr/bin/osascript'; // osascript is the AppleScript interpreter on OS X
|
||||
|
||||
constructor(
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService
|
||||
) { }
|
||||
|
||||
public openTerminal(cwd?: string): void {
|
||||
const configuration = this._configurationService.getValue<IExternalTerminalConfiguration>();
|
||||
|
||||
this.spawnTerminal(cp, configuration, cwd);
|
||||
}
|
||||
|
||||
public runInTerminal(title: string, dir: string, args: string[], envVars: IProcessEnvironment): Promise<number | undefined> {
|
||||
|
||||
const configuration = this._configurationService.getValue<IExternalTerminalConfiguration>();
|
||||
const terminalConfig = configuration.terminal.external;
|
||||
const terminalApp = terminalConfig.osxExec || DEFAULT_TERMINAL_OSX;
|
||||
|
||||
return new Promise<number | undefined>((c, e) => {
|
||||
|
||||
if (terminalApp === DEFAULT_TERMINAL_OSX || terminalApp === 'iTerm.app') {
|
||||
|
||||
// On OS X we launch an AppleScript that creates (or reuses) a Terminal window
|
||||
// and then launches the program inside that window.
|
||||
|
||||
const script = terminalApp === DEFAULT_TERMINAL_OSX ? 'TerminalHelper' : 'iTermHelper';
|
||||
const scriptpath = getPathFromAmdModule(require, `vs/workbench/contrib/externalTerminal/electron-browser/${script}.scpt`);
|
||||
|
||||
const osaArgs = [
|
||||
scriptpath,
|
||||
'-t', title || TERMINAL_TITLE,
|
||||
'-w', dir,
|
||||
];
|
||||
|
||||
for (let a of args) {
|
||||
osaArgs.push('-a');
|
||||
osaArgs.push(a);
|
||||
}
|
||||
|
||||
if (envVars) {
|
||||
for (let key in envVars) {
|
||||
const value = envVars[key];
|
||||
if (value === null) {
|
||||
osaArgs.push('-u');
|
||||
osaArgs.push(key);
|
||||
} else {
|
||||
osaArgs.push('-e');
|
||||
osaArgs.push(`${key}=${value}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let stderr = '';
|
||||
const osa = cp.spawn(MacExternalTerminalService.OSASCRIPT, osaArgs);
|
||||
osa.on('error', e);
|
||||
osa.stderr.on('data', (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
osa.on('exit', (code: number) => {
|
||||
if (code === 0) { // OK
|
||||
c(undefined);
|
||||
} else {
|
||||
if (stderr) {
|
||||
const lines = stderr.split('\n', 1);
|
||||
e(new Error(lines[0]));
|
||||
} else {
|
||||
e(new Error(nls.localize('mac.terminal.script.failed', "Script '{0}' failed with exit code {1}", script, code)));
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
e(new Error(nls.localize('mac.terminal.type.not.supported', "'{0}' not supported", terminalApp)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private spawnTerminal(spawner, configuration: IExternalTerminalConfiguration, cwd?: string): Promise<void> {
|
||||
const terminalConfig = configuration.terminal.external;
|
||||
const terminalApp = terminalConfig.osxExec || DEFAULT_TERMINAL_OSX;
|
||||
|
||||
return new Promise<void>((c, e) => {
|
||||
const child = spawner.spawn('/usr/bin/open', ['-a', terminalApp, cwd]);
|
||||
child.on('error', e);
|
||||
child.on('exit', () => c());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class LinuxExternalTerminalService implements IExternalTerminalService {
|
||||
public _serviceBrand: any;
|
||||
|
||||
private static readonly WAIT_MESSAGE = nls.localize('press.any.key', "Press any key to continue...");
|
||||
|
||||
constructor(
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService
|
||||
) { }
|
||||
|
||||
|
||||
public openTerminal(cwd?: string): void {
|
||||
const configuration = this._configurationService.getValue<IExternalTerminalConfiguration>();
|
||||
|
||||
this.spawnTerminal(cp, configuration, cwd);
|
||||
}
|
||||
|
||||
public runInTerminal(title: string, dir: string, args: string[], envVars: IProcessEnvironment): Promise<number | undefined> {
|
||||
|
||||
const configuration = this._configurationService.getValue<IExternalTerminalConfiguration>();
|
||||
const terminalConfig = configuration.terminal.external;
|
||||
const execPromise = terminalConfig.linuxExec ? Promise.resolve(terminalConfig.linuxExec) : getDefaultTerminalLinuxReady();
|
||||
|
||||
return new Promise<number | undefined>((c, e) => {
|
||||
|
||||
let termArgs: string[] = [];
|
||||
//termArgs.push('--title');
|
||||
//termArgs.push(`"${TERMINAL_TITLE}"`);
|
||||
execPromise.then(exec => {
|
||||
if (exec.indexOf('gnome-terminal') >= 0) {
|
||||
termArgs.push('-x');
|
||||
} else {
|
||||
termArgs.push('-e');
|
||||
}
|
||||
termArgs.push('bash');
|
||||
termArgs.push('-c');
|
||||
|
||||
const bashCommand = `${quote(args)}; echo; read -p "${LinuxExternalTerminalService.WAIT_MESSAGE}" -n1;`;
|
||||
termArgs.push(`''${bashCommand}''`); // wrapping argument in two sets of ' because node is so "friendly" that it removes one set...
|
||||
|
||||
// merge environment variables into a copy of the process.env
|
||||
const env = assign({}, process.env, envVars);
|
||||
|
||||
// delete environment variables that have a null value
|
||||
Object.keys(env).filter(v => env[v] === null).forEach(key => delete env[key]);
|
||||
|
||||
const options: any = {
|
||||
cwd: dir,
|
||||
env: env
|
||||
};
|
||||
|
||||
let stderr = '';
|
||||
const cmd = cp.spawn(exec, termArgs, options);
|
||||
cmd.on('error', e);
|
||||
cmd.stderr.on('data', (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
cmd.on('exit', (code: number) => {
|
||||
if (code === 0) { // OK
|
||||
c(undefined);
|
||||
} else {
|
||||
if (stderr) {
|
||||
const lines = stderr.split('\n', 1);
|
||||
e(new Error(lines[0]));
|
||||
} else {
|
||||
e(new Error(nls.localize('linux.term.failed', "'{0}' failed with exit code {1}", exec, code)));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private spawnTerminal(spawner, configuration: IExternalTerminalConfiguration, cwd?: string): Promise<void> {
|
||||
const terminalConfig = configuration.terminal.external;
|
||||
const execPromise = terminalConfig.linuxExec ? Promise.resolve(terminalConfig.linuxExec) : getDefaultTerminalLinuxReady();
|
||||
const env = cwd ? { cwd: cwd } : undefined;
|
||||
|
||||
return new Promise<void>((c, e) => {
|
||||
execPromise.then(exec => {
|
||||
const child = spawner.spawn(exec, [], env);
|
||||
child.on('error', e);
|
||||
child.on('exit', () => c());
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Quote args if necessary and combine into a space separated string.
|
||||
*/
|
||||
function quote(args: string[]): string {
|
||||
let r = '';
|
||||
for (let a of args) {
|
||||
if (a.indexOf(' ') >= 0) {
|
||||
r += '"' + a + '"';
|
||||
} else {
|
||||
r += a;
|
||||
}
|
||||
r += ' ';
|
||||
}
|
||||
return r;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,221 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { deepEqual, equal } from 'assert';
|
||||
import { WindowsExternalTerminalService, LinuxExternalTerminalService, MacExternalTerminalService } from 'vs/workbench/contrib/externalTerminal/electron-browser/externalTerminalService';
|
||||
import { getDefaultTerminalWindows, getDefaultTerminalLinuxReady, DEFAULT_TERMINAL_OSX } from 'vs/workbench/contrib/externalTerminal/electron-browser/externalTerminal';
|
||||
|
||||
suite('ExternalTerminalService', () => {
|
||||
let mockOnExit: Function;
|
||||
let mockOnError: Function;
|
||||
let mockConfig: any;
|
||||
|
||||
setup(() => {
|
||||
mockConfig = {
|
||||
terminal: {
|
||||
explorerKind: 'external',
|
||||
external: {
|
||||
windowsExec: 'testWindowsShell',
|
||||
osxExec: 'testOSXShell',
|
||||
linuxExec: 'testLinuxShell'
|
||||
}
|
||||
}
|
||||
};
|
||||
mockOnExit = (s: any) => s;
|
||||
mockOnError = (e: any) => e;
|
||||
});
|
||||
|
||||
test(`WinTerminalService - uses terminal from configuration`, done => {
|
||||
let testShell = 'cmd';
|
||||
let testCwd = 'path/to/workspace';
|
||||
let mockSpawner = {
|
||||
spawn: (command: any, args: any, opts: any) => {
|
||||
// assert
|
||||
equal(command, testShell, 'shell should equal expected');
|
||||
equal(args[args.length - 1], mockConfig.terminal.external.windowsExec, 'terminal should equal expected');
|
||||
equal(opts.cwd, testCwd, 'opts.cwd should equal expected');
|
||||
done();
|
||||
return {
|
||||
on: (evt: any) => evt
|
||||
};
|
||||
}
|
||||
};
|
||||
let testService = new WindowsExternalTerminalService(mockConfig);
|
||||
(<any>testService).spawnTerminal(
|
||||
mockSpawner,
|
||||
mockConfig,
|
||||
testShell,
|
||||
testCwd,
|
||||
mockOnExit,
|
||||
mockOnError
|
||||
);
|
||||
});
|
||||
|
||||
test(`WinTerminalService - uses default terminal when configuration.terminal.external.windowsExec is undefined`, done => {
|
||||
let testShell = 'cmd';
|
||||
let testCwd = 'path/to/workspace';
|
||||
let mockSpawner = {
|
||||
spawn: (command: any, args: any, opts: any) => {
|
||||
// assert
|
||||
equal(args[args.length - 1], getDefaultTerminalWindows(), 'terminal should equal expected');
|
||||
done();
|
||||
return {
|
||||
on: (evt: any) => evt
|
||||
};
|
||||
}
|
||||
};
|
||||
mockConfig.terminal.external.windowsExec = undefined;
|
||||
let testService = new WindowsExternalTerminalService(mockConfig);
|
||||
(<any>testService).spawnTerminal(
|
||||
mockSpawner,
|
||||
mockConfig,
|
||||
testShell,
|
||||
testCwd,
|
||||
mockOnExit,
|
||||
mockOnError
|
||||
);
|
||||
});
|
||||
|
||||
test(`WinTerminalService - uses default terminal when configuration.terminal.external.windowsExec is undefined`, done => {
|
||||
let testShell = 'cmd';
|
||||
let testCwd = 'c:/foo';
|
||||
let mockSpawner = {
|
||||
spawn: (command: any, args: any, opts: any) => {
|
||||
// assert
|
||||
equal(opts.cwd, 'C:/foo', 'cwd should be uppercase regardless of the case that\'s passed in');
|
||||
done();
|
||||
return {
|
||||
on: (evt: any) => evt
|
||||
};
|
||||
}
|
||||
};
|
||||
let testService = new WindowsExternalTerminalService(mockConfig);
|
||||
(<any>testService).spawnTerminal(
|
||||
mockSpawner,
|
||||
mockConfig,
|
||||
testShell,
|
||||
testCwd,
|
||||
mockOnExit,
|
||||
mockOnError
|
||||
);
|
||||
});
|
||||
|
||||
test(`WinTerminalService - cmder should be spawned differently`, done => {
|
||||
let testShell = 'cmd';
|
||||
mockConfig.terminal.external.windowsExec = 'cmder';
|
||||
let testCwd = 'c:/foo';
|
||||
let mockSpawner = {
|
||||
spawn: (command: any, args: any, opts: any) => {
|
||||
// assert
|
||||
deepEqual(args, ['C:/foo']);
|
||||
equal(opts, undefined);
|
||||
done();
|
||||
return { on: (evt: any) => evt };
|
||||
}
|
||||
};
|
||||
let testService = new WindowsExternalTerminalService(mockConfig);
|
||||
(<any>testService).spawnTerminal(
|
||||
mockSpawner,
|
||||
mockConfig,
|
||||
testShell,
|
||||
testCwd,
|
||||
mockOnExit,
|
||||
mockOnError
|
||||
);
|
||||
});
|
||||
|
||||
test(`MacTerminalService - uses terminal from configuration`, done => {
|
||||
let testCwd = 'path/to/workspace';
|
||||
let mockSpawner = {
|
||||
spawn: (command: any, args: any, opts: any) => {
|
||||
// assert
|
||||
equal(args[1], mockConfig.terminal.external.osxExec, 'terminal should equal expected');
|
||||
done();
|
||||
return {
|
||||
on: (evt: any) => evt
|
||||
};
|
||||
}
|
||||
};
|
||||
let testService = new MacExternalTerminalService(mockConfig);
|
||||
(<any>testService).spawnTerminal(
|
||||
mockSpawner,
|
||||
mockConfig,
|
||||
testCwd,
|
||||
mockOnExit,
|
||||
mockOnError
|
||||
);
|
||||
});
|
||||
|
||||
test(`MacTerminalService - uses default terminal when configuration.terminal.external.osxExec is undefined`, done => {
|
||||
let testCwd = 'path/to/workspace';
|
||||
let mockSpawner = {
|
||||
spawn: (command: any, args: any, opts: any) => {
|
||||
// assert
|
||||
equal(args[1], DEFAULT_TERMINAL_OSX, 'terminal should equal expected');
|
||||
done();
|
||||
return {
|
||||
on: (evt: any) => evt
|
||||
};
|
||||
}
|
||||
};
|
||||
mockConfig.terminal.external.osxExec = undefined;
|
||||
let testService = new MacExternalTerminalService(mockConfig);
|
||||
(<any>testService).spawnTerminal(
|
||||
mockSpawner,
|
||||
mockConfig,
|
||||
testCwd,
|
||||
mockOnExit,
|
||||
mockOnError
|
||||
);
|
||||
});
|
||||
|
||||
test(`LinuxTerminalService - uses terminal from configuration`, done => {
|
||||
let testCwd = 'path/to/workspace';
|
||||
let mockSpawner = {
|
||||
spawn: (command: any, args: any, opts: any) => {
|
||||
// assert
|
||||
equal(command, mockConfig.terminal.external.linuxExec, 'terminal should equal expected');
|
||||
equal(opts.cwd, testCwd, 'opts.cwd should equal expected');
|
||||
done();
|
||||
return {
|
||||
on: (evt: any) => evt
|
||||
};
|
||||
}
|
||||
};
|
||||
let testService = new LinuxExternalTerminalService(mockConfig);
|
||||
(<any>testService).spawnTerminal(
|
||||
mockSpawner,
|
||||
mockConfig,
|
||||
testCwd,
|
||||
mockOnExit,
|
||||
mockOnError
|
||||
);
|
||||
});
|
||||
|
||||
test(`LinuxTerminalService - uses default terminal when configuration.terminal.external.linuxExec is undefined`, done => {
|
||||
getDefaultTerminalLinuxReady().then(defaultTerminalLinux => {
|
||||
let testCwd = 'path/to/workspace';
|
||||
let mockSpawner = {
|
||||
spawn: (command: any, args: any, opts: any) => {
|
||||
// assert
|
||||
equal(command, defaultTerminalLinux, 'terminal should equal expected');
|
||||
done();
|
||||
return {
|
||||
on: (evt: any) => evt
|
||||
};
|
||||
}
|
||||
};
|
||||
mockConfig.terminal.external.linuxExec = undefined;
|
||||
let testService = new LinuxExternalTerminalService(mockConfig);
|
||||
(<any>testService).spawnTerminal(
|
||||
mockSpawner,
|
||||
mockConfig,
|
||||
testCwd,
|
||||
mockOnExit,
|
||||
mockOnError
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user