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

use async version of fs.exists; fixes #69860

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