提交 00ead383 编写于 作者: A Andre Weinand

use async version of fs.exists; fixes #69860

上级 68842a0c
...@@ -310,65 +310,67 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter { ...@@ -310,65 +310,67 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter {
super(); super();
} }
startSession(): Promise<void> { async startSession(): Promise<void> {
return new Promise<void>((resolve, reject) => { const command = this.adapterExecutable.command;
const args = this.adapterExecutable.args;
// verify executables const options = this.adapterExecutable.options || {};
if (this.adapterExecutable.command) {
if (path.isAbsolute(this.adapterExecutable.command)) { try {
if (!fs.existsSync(this.adapterExecutable.command)) { // verify executables asynchronously
reject(new Error(nls.localize('debugAdapterBinNotFound', "Debug adapter executable '{0}' does not exist.", this.adapterExecutable.command))); if (command) {
if (path.isAbsolute(command)) {
const ok = await new Promise<boolean>(resolve => fs.exists(command, resolve));
if (!ok) {
throw new Error(nls.localize('debugAdapterBinNotFound', "Debug adapter executable '{0}' does not exist.", command));
} }
} else { } else {
// relative path // relative path
if (this.adapterExecutable.command.indexOf('/') < 0 && this.adapterExecutable.command.indexOf('\\') < 0) { if (command.indexOf('/') < 0 && command.indexOf('\\') < 0) {
// no separators: command looks like a runtime name like 'node' or 'mono' // no separators: command looks like a runtime name like 'node' or 'mono'
// TODO: check that the runtime is available on PATH // TODO: check that the runtime is available on PATH
} }
} }
} else { } else {
reject(new Error(nls.localize({ key: 'debugAdapterCannotDetermineExecutable', comment: ['Adapter executable file not found'] }, throw new Error(nls.localize({ key: 'debugAdapterCannotDetermineExecutable', comment: ['Adapter executable file not found'] },
"Cannot determine executable for debug adapter '{0}'.", this.debugType))); "Cannot determine executable for debug adapter '{0}'.", this.debugType));
} }
let env = objects.mixin({}, process.env); let env = objects.mixin({}, process.env);
if (this.adapterExecutable.options && this.adapterExecutable.options.env) { if (options.env) {
env = objects.mixin(env, this.adapterExecutable.options.env); env = objects.mixin(env, options.env);
} }
delete env.VSCODE_PREVENT_FOREIGN_INSPECT; delete env.VSCODE_PREVENT_FOREIGN_INSPECT;
if (this.adapterExecutable.command === 'node') { if (command === 'node') {
if (Array.isArray(this.adapterExecutable.args) && this.adapterExecutable.args.length > 0) { if (Array.isArray(args) && args.length > 0) {
const isElectron = !!process.env['ELECTRON_RUN_AS_NODE'] || !!process.versions['electron']; const isElectron = !!process.env['ELECTRON_RUN_AS_NODE'] || !!process.versions['electron'];
const options: cp.ForkOptions = { const forkOptions: cp.ForkOptions = {
env: env, env: env,
execArgv: isElectron ? ['-e', 'delete process.env.ELECTRON_RUN_AS_NODE;require(process.argv[1])'] : [], execArgv: isElectron ? ['-e', 'delete process.env.ELECTRON_RUN_AS_NODE;require(process.argv[1])'] : [],
silent: true silent: true
}; };
if (this.adapterExecutable.options && this.adapterExecutable.options.cwd) { if (options.cwd) {
options.cwd = this.adapterExecutable.options.cwd; forkOptions.cwd = options.cwd;
} }
const child = cp.fork(this.adapterExecutable.args[0], this.adapterExecutable.args.slice(1), options); const child = cp.fork(args[0], args.slice(1), forkOptions);
if (!child.pid) { if (!child.pid) {
reject(new Error(nls.localize('unableToLaunchDebugAdapter', "Unable to launch debug adapter from '{0}'.", this.adapterExecutable.args[0]))); throw new Error(nls.localize('unableToLaunchDebugAdapter', "Unable to launch debug adapter from '{0}'.", args[0]));
} }
this.serverProcess = child; this.serverProcess = child;
resolve();
} else { } else {
reject(new Error(nls.localize('unableToLaunchDebugAdapterNoArgs', "Unable to launch debug adapter."))); throw new Error(nls.localize('unableToLaunchDebugAdapterNoArgs', "Unable to launch debug adapter."));
} }
} else { } else {
const options: cp.SpawnOptions = { const spawnOptions: cp.SpawnOptions = {
env: env env: env
}; };
if (this.adapterExecutable.options && this.adapterExecutable.options.cwd) { if (options.cwd) {
options.cwd = this.adapterExecutable.options.cwd; spawnOptions.cwd = options.cwd;
} }
this.serverProcess = cp.spawn(this.adapterExecutable.command, this.adapterExecutable.args, options); this.serverProcess = cp.spawn(command, args, spawnOptions);
resolve();
} }
}).then(_ => {
this.serverProcess.on('error', err => { this.serverProcess.on('error', err => {
this._onError.fire(err); this._onError.fire(err);
}); });
...@@ -401,10 +403,12 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter { ...@@ -401,10 +403,12 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter {
}); });
} }
// finally connect to the DA
this.connect(this.serverProcess.stdout, this.serverProcess.stdin); this.connect(this.serverProcess.stdout, this.serverProcess.stdin);
}, (err: Error) => {
} catch (err) {
this._onError.fire(err); this._onError.fire(err);
}); }
} }
stopSession(): Promise<void> { stopSession(): Promise<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册