Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Fix #175
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Mar 25, 2018
1 parent e325095 commit 58072bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/nodeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,7 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {
this._continueAfterConfigDone = !args.stopOnEntry;

if (this.isExtensionHost()) {
// we always launch in 'debug-brk' mode, but we only show the break event if 'stopOnEntry' attribute is true.
let launchArgs = [];
if (!args.noDebug) {
launchArgs.push(`--debugBrkPluginHost=${port}`);

// pass the debug session ID to the EH so that broadcast events know where they come from
if (args.__sessionId) {
launchArgs.push(`--debugId=${args.__sessionId}`);
}
}

const runtimeArgs = args.runtimeArgs || [];
const programArgs = args.args || [];
launchArgs = launchArgs.concat(runtimeArgs, programArgs);

const envArgs = this.collectEnvFileArgs(args) || args.env;
return this.launchInInternalConsole(runtimeExecutable, launchArgs, envArgs);
return this.extensionHostLaunch(args, runtimeExecutable, port);
}

let programPath = args.program;
Expand Down Expand Up @@ -189,7 +173,7 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {
const runtimeArgs = args.runtimeArgs || [];
const programArgs = args.args || [];

const debugArgs = detectSupportedDebugArgsForLaunch(args);
const debugArgs = detectSupportedDebugArgsForLaunch(args, runtimeExecutable, args.env);
let launchArgs = [];
if (!args.noDebug && !args.port) {
// Always stop on entry to set breakpoints
Expand Down Expand Up @@ -236,6 +220,26 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {
}
}

private extensionHostLaunch(args: ILaunchRequestArguments, runtimeExecutable: string, port: number): Promise<void> {
// we always launch in 'debug-brk' mode, but we only show the break event if 'stopOnEntry' attribute is true.
let launchArgs = [];
if (!args.noDebug) {
launchArgs.push(`--debugBrkPluginHost=${port}`);

// pass the debug session ID to the EH so that broadcast events know where they come from
if (args.__sessionId) {
launchArgs.push(`--debugId=${args.__sessionId}`);
}
}

const runtimeArgs = args.runtimeArgs || [];
const programArgs = args.args || [];
launchArgs = launchArgs.concat(runtimeArgs, programArgs);

const envArgs = this.collectEnvFileArgs(args) || args.env;
return this.launchInInternalConsole(runtimeExecutable, launchArgs, envArgs);
}

public async attach(args: IAttachRequestArguments): Promise<void> {
try {
return super.attach(args);
Expand Down Expand Up @@ -852,7 +856,7 @@ export enum DebugArgs {
}

const defaultDebugArgs = DebugArgs.InspectBrk;
function detectSupportedDebugArgsForLaunch(config: any): DebugArgs {
function detectSupportedDebugArgsForLaunch(config: ILaunchRequestArguments, runtimeExecutable: string, env: any): DebugArgs {
if (config.__nodeVersion) {
return getSupportedDebugArgsForVersion(config.__nodeVersion);
} else if (config.runtimeExecutable) {
Expand All @@ -863,7 +867,7 @@ function detectSupportedDebugArgsForLaunch(config: any): DebugArgs {
logger.log('Spawning `node --version` to determine supported debug args');
let result: cp.SpawnSyncReturns<string>;
try {
result = cp.spawnSync('node', ['--version']);
result = cp.spawnSync(runtimeExecutable, ['--version']);
} catch (e) {
logger.error('Node version detection failed: ' + (e && e.message));
}
Expand Down
3 changes: 3 additions & 0 deletions src/nodeDebugInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export interface ILaunchRequestArguments extends Core.ILaunchRequestArgs, ICommo

// extensionHost option
__sessionId?: number;

// When node version is detected by node-debug
__nodeVersion?: string;
}

/**
Expand Down

0 comments on commit 58072bb

Please sign in to comment.