|
2 | 2 |
|
3 | 3 | ## Purpose |
4 | 4 |
|
5 | | -Manages debug launch configurations by reading from `launch.json` for explicitly named configs, creating defaults when needed, and supporting test-specific debugging across multiple languages and test frameworks. |
| 5 | +Produces the argument passed to `vscode.debug.startDebugging()` — either a launch.json configuration name or a minimal `DebugConfiguration` stub. |
6 | 6 |
|
7 | 7 | ## Motivation |
8 | 8 |
|
9 | | -Different languages and test frameworks require different debug configurations. Rather than forcing AI agents to understand these details, `DebugConfigurationManager` auto-detects the appropriate configuration based on file extension and test framework conventions. |
| 9 | +Earlier versions of this class manually parsed `launch.json`, scored configurations, and assembled fully populated per-language config objects. That duplicated work VS Code and the language debug extensions already do better: |
| 10 | + |
| 11 | +- **VS Code** resolves launch.json configurations by name when you pass a string to `startDebugging`. |
| 12 | +- **Language extensions** (Python, JS/TS, Java, .NET, Go, …) each register a `DebugConfigurationProvider` whose `resolveDebugConfiguration` hook fills in `cwd`, `console`, `env`, `stopOnEntry`, and other sensible defaults for a minimal stub. |
| 13 | + |
| 14 | +Delegating to those mechanisms keeps this class small and ensures defaults stay aligned with whatever the installed language extensions consider current. |
10 | 15 |
|
11 | 16 | ## Responsibility |
12 | 17 |
|
13 | | -- Read and parse `.vscode/launch.json` configurations |
14 | | -- Auto-select the most relevant launch configuration for the target file/test |
15 | | -- Respect an explicitly provided `configurationName` when supplied by the agent |
16 | | -- Create default configurations when none exist |
17 | | -- Detect programming language from file extensions |
18 | | -- Generate test-specific configurations for various frameworks |
19 | | -- Validate workspace setup for debugging |
| 18 | +- Return a launch.json configuration name when the caller provides one — VS Code looks it up itself. |
| 19 | +- Otherwise, return a minimal launch stub (`type`, `request`, `name`, `program`) for the file's language and let the language extension resolve the rest. |
| 20 | +- For `.NET` (`coreclr`), locate the project's built DLL since `program` cannot be a `.cs` source file. |
| 21 | +- Detect the debugger `type` from a file extension. |
| 22 | + |
| 23 | +**Test debugging is not handled here.** It is routed through `DebuggingExecutor.debugTestAtCursor`, which uses VS Code's built-in `testing.debugAtCursor` command to dispatch to whichever `TestController` owns the test under the cursor. That path supports any language whose extension registers a Test Explorer integration and correctly handles parent/child process attach (e.g. `dotnet test`'s testhost). |
20 | 24 |
|
21 | 25 | ## Key Concepts |
22 | 26 |
|
23 | | -### Configuration Sources |
| 27 | +### Return type |
24 | 28 |
|
25 | | -1. **User's launch.json**: Preferred if available |
26 | | -2. **Default Configuration**: Auto-generated based on file extension |
27 | | -3. **Test Configuration**: Special handling for unit test files |
| 29 | +`getDebugConfig()` returns `string | vscode.DebugConfiguration`. Both forms are accepted by `vscode.debug.startDebugging(folder, nameOrConfiguration)`. |
28 | 30 |
|
29 | | -### Language Detection |
| 31 | +### Language detection |
30 | 32 |
|
31 | | -Maps file extensions to debug types: |
| 33 | +Maps file extensions to debugger `type` values: |
32 | 34 | - `.py` → `python` |
33 | | -- `.js/.ts/.jsx/.tsx` → `node` (pwa-node) |
| 35 | +- `.js/.ts/.jsx/.tsx` → `pwa-node` |
34 | 36 | - `.java` → `java` |
35 | | -- `.cs` → `coreclr` |
| 37 | +- `.cs/.csproj` → `coreclr` |
36 | 38 | - `.cpp/.cc/.c` → `cppdbg` |
37 | 39 | - `.go` → `go` |
38 | 40 | - `.rs` → `lldb` |
39 | 41 | - `.php` → `php` |
40 | 42 | - `.rb` → `ruby` |
41 | 43 |
|
42 | | -### Test Framework Support |
| 44 | +### Test framework support |
43 | 45 |
|
44 | | -| Language | Frameworks | |
45 | | -|----------|------------| |
46 | | -| Python | unittest | |
47 | | -| Node.js | Jest, Mocha (auto-detected) | |
48 | | -| Java | JUnit | |
49 | | -| .NET | xUnit, NUnit, MSTest | |
| 46 | +Test launches are dispatched via `DebuggingExecutor.debugTestAtCursor`, not via this class. Any language with a registered `TestController` is supported (Python unittest/pytest, Jest, Mocha, JUnit, C# Dev Kit, Go, Rust, ...). |
50 | 47 |
|
51 | | -### Configuration Selection Flow |
| 48 | +### Selection flow |
52 | 49 |
|
53 | | -When starting debugging, the manager: |
54 | | -1. Loads available launch.json configurations |
55 | | -2. Scores configurations based on language/type/request/test relevance |
56 | | -3. Selects the best match automatically |
57 | | -4. Falls back to an auto-detected default configuration when needed |
| 50 | +1. If `configurationName` is provided and is not the sentinel `Default Configuration`, return that name verbatim. |
| 51 | +2. Otherwise, if the file is C# (`coreclr`), walk up to find the `.csproj`, locate its built DLL under `bin/{Debug,Release}/<tfm>/`, and return a coreclr config pointing at that assembly. |
| 52 | +3. Otherwise, return `{ type, request: 'launch', name: 'DebugMCP Launch', program: fileFullPath }`. |
58 | 53 |
|
59 | | -## Key Code Locations |
| 54 | +## Key code locations |
60 | 55 |
|
61 | 56 | - Class definition: `src/utils/debugConfigurationManager.ts` |
62 | 57 | - Interface: `IDebugConfigurationManager` |
63 | | -- Default configs: `createDefaultDebugConfig()` |
64 | | -- Test configs: `createTestDebugConfig()` |
| 58 | +- .NET assembly lookup: `findNearestCsproj()`, `findBuiltAssembly()`, `createDotNetLaunchConfig()` |
65 | 59 | - Language detection: `detectLanguageFromFilePath()` |
66 | | -- Configuration selection: `selectBestLaunchConfiguration()` |
67 | | - |
68 | | -## JSON Parsing |
69 | | - |
70 | | -Handles common launch.json quirks: |
71 | | -- Strips comments (`//` and `/* */`) |
72 | | -- Removes trailing commas before `}` or `]` |
| 60 | +- Test launches: see `DebuggingExecutor.debugTestAtCursor` in `src/debuggingExecutor.ts` |
73 | 61 |
|
74 | | -## Python Test Name Formatting |
| 62 | +## Python test name formatting |
75 | 63 |
|
76 | | -For Python tests, the manager auto-detects the class name from the test file to build the full test path (`module.ClassName.test_method`). This allows AI agents to specify just the test method name. |
| 64 | +Python test name handling now lives in the Python extension's `TestController`; we no longer format `module.ClassName.test_method` ourselves. |
0 commit comments