Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/test/suite/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,22 @@ suite('Debug Tools Tests', () => {
}
});

test('should start debug session with a preLaunchTask', async () => {
const result = await callTool('debug_startSession', {
configuration: 'Debug With PreLaunchTask',
format: 'detailed',
});

// A preLaunchTask only resolves when startDebugging is given the
// owning workspace folder. Without it, VS Code reports
// "Could not find the task 'prelaunch-noop'" and startDebugging
// returns false.
assert.ok(!result.error, `Should not have error: ${result.error}`);
assert.strictEqual(result.success, true, 'Debug session should start');

await vscode.debug.stopDebugging();
});

// Skip debug session tests for now as they require more setup
test.skip('should start debug session', async () => {
const result = await callTool('debug_startSession', {
Expand Down
13 changes: 11 additions & 2 deletions src/tools/debug/startDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export const debug_startSessionTool: Tool = {
handler: async (args) => {
const { configuration, format = 'compact' } = args;

const configs = vscode.workspace.getConfiguration('launch').get<any[]>('configurations') || [];
// Single-root only: a multi-root workspace can host per-folder launch
// configs and tasks, which this does not resolve.
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];

const configs =
vscode.workspace
.getConfiguration('launch', workspaceFolder?.uri)
.get<any[]>('configurations') || [];

if (configs.length === 0) {
return format === 'compact'
Expand All @@ -46,7 +53,9 @@ export const debug_startSessionTool: Tool = {
configToUse = found;
}

const success = await vscode.debug.startDebugging(undefined, configToUse);
// The workspace folder must be passed so VS Code can resolve a
// preLaunchTask and folder-scoped variables like ${workspaceFolder}.
const success = await vscode.debug.startDebugging(workspaceFolder, configToUse);

if (format === 'compact') {
return { started: success, config: configToUse.name };
Expand Down
9 changes: 9 additions & 0 deletions test-workspace/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
"args": ["--timeout", "999999", "--colors", "${file}"],
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**"]
},
{
"type": "node",
"request": "launch",
"name": "Debug With PreLaunchTask",
"program": "${workspaceFolder}/src/noop.cjs",
"preLaunchTask": "prelaunch-noop",
"internalConsoleOptions": "neverOpen",
"skipFiles": ["<node_internals>/**"]
}
]
}
15 changes: 15 additions & 0 deletions test-workspace/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "prelaunch-noop",
"type": "shell",
"command": "node",
"args": ["-e", "process.exit(0)"],
"presentation": {
"reveal": "never"
},
"problemMatcher": []
}
]
}
3 changes: 3 additions & 0 deletions test-workspace/src/noop.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Minimal program launched by the preLaunchTask debug regression test.
// Exits on its own so the debug session does not linger.
setTimeout(() => process.exit(0), 200);