Skip to content

Commit

Permalink
feat: contribute node.js debug terminal as a dynamic configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed May 18, 2020
1 parent 92a7d52 commit 99aaa3a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
29 changes: 21 additions & 8 deletions src/ui/configuration/nodeDebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,31 @@ export class NodeDynamicDebugConfigurationProvider extends BaseConfigurationProv
* Adds suggestions discovered from npm scripts.
*/
protected async getFromNpmScripts(folder?: vscode.WorkspaceFolder): Promise<DynamicConfig> {
const openTerminal: AnyResolvingConfiguration = {
type: DebugType.Terminal,
name: localize('debug.terminal.label', 'Create JavaScript Debug Terminal'),
request: 'launch',
cwd: folder?.uri.fsPath,
};

if (!folder) {
return;
return [openTerminal];
}

const scripts = await findScripts(folder, true);
return scripts?.map(script => ({
type: DebugType.Terminal,
name: localize('node.launch.script', 'Run Script: {0}', script.name),
request: 'launch',
command: getRunScriptCommand(script.name, folder),
cwd: script.directory.uri.fsPath,
}));
if (!scripts) {
return [openTerminal];
}

return scripts
.map<AnyResolvingConfiguration>(script => ({
type: DebugType.Terminal,
name: localize('node.launch.script', 'Run Script: {0}', script.name),
request: 'launch',
command: getRunScriptCommand(script.name, folder),
cwd: script.directory.uri.fsPath,
}))
.concat(openTerminal);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/ui/configuration/terminalDebugConfigurationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../../configuration';
import { BaseConfigurationResolver } from './baseConfigurationResolver';
import { guessWorkingDirectory } from './nodeDebugConfigurationResolver';
import { DebugType } from '../../common/contributionUtils';
import { DebugType, runCommand, Commands } from '../../common/contributionUtils';

/**
* Configuration provider for node debugging. In order to allow for a
Expand All @@ -28,6 +28,11 @@ export class TerminalDebugConfigurationResolver
config.cwd = guessWorkingDirectory(undefined, folder);
}

if (config.request === 'launch' && !config.command) {
await runCommand(vscode.commands, Commands.CreateDebuggerTerminal, undefined, folder);
return undefined;
}

// if a 'remoteRoot' is specified without a corresponding 'localRoot', set 'localRoot' to the workspace folder.
// see https://github.com/Microsoft/vscode/issues/63118
if (config.remoteRoot && !config.localRoot) {
Expand Down

0 comments on commit 99aaa3a

Please sign in to comment.