Skip to content

Commit

Permalink
Ensure node-based debug adapters spawn same node exec as Theia
Browse files Browse the repository at this point in the history
Signed-off-by: Vered Constantin <vered.constantin@sap.com>
  • Loading branch information
veredcon authored and akosyakov committed Mar 12, 2020
1 parent fa39af3 commit 07d0133
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import * as net from 'net';
import * as theia from '@theia/plugin';
import { CommunicationProvider, DebugAdapterForkExecutable } from '@theia/debug/lib/common/debug-model';
import { ChildProcess, spawn, fork } from 'child_process';
import { CommunicationProvider } from '@theia/debug/lib/common/debug-model';
import { ChildProcess, spawn, fork, ForkOptions } from 'child_process';

/**
* Starts debug adapter process.
Expand All @@ -37,16 +37,26 @@ export function startDebugAdapter(executable: theia.DebugAdapterExecutable): Com
}

let childProcess: ChildProcess;
if ('command' in executable) {
const { command, args } = executable;
childProcess = spawn(command, args, options);
} else if ('modulePath' in executable) {
const forkExecutable = <DebugAdapterForkExecutable>executable;
const { modulePath, args } = forkExecutable;
options.stdio.push('ipc');
childProcess = fork(modulePath, args, options);
const { command, args } = executable;
if (command === 'node') {
if (Array.isArray(args) && args.length > 0) {
const isElectron = !!process.env['ELECTRON_RUN_AS_NODE'];
const forkOptions: ForkOptions = {
env: options.env,
execArgv: isElectron ? ['-e', 'delete process.env.ELECTRON_RUN_AS_NODE;require(process.argv[1])'] : [],
silent: true
};
if (options.cwd) {
forkOptions.cwd = options.cwd;
}
options.stdio.push('ipc');
forkOptions.stdio = options.stdio;
childProcess = fork(args[0], args.slice(1), forkOptions);
} else {
throw new Error(`It is not possible to launch debug adapter with the command: ${JSON.stringify(executable)}`);
}
} else {
throw new Error(`It is not possible to launch debug adapter with the command: ${JSON.stringify(executable)}`);
childProcess = spawn(command, args, options);
}

return {
Expand Down

0 comments on commit 07d0133

Please sign in to comment.