| 1 | namespace CascadeIDE.Features.IdeMcp.Execution; |
| 2 | |
| 3 | /// <summary>MCP DAP: ping, launch и attach.</summary> |
| 4 | internal sealed partial class IdeMcpCommandExecutor |
| 5 | { |
| 6 | private void RegisterDapDebugLaunchAttach(Action<string, Handler> add) |
| 7 | { |
| 8 | add(Services.IdeCommands.DebugPing, async (_, _) => await Task.FromResult(Services.IdeDapDebugSession.Ping())); |
| 9 | |
| 10 | add(Services.IdeCommands.DebugLaunch, async (args, ct) => |
| 11 | { |
| 12 | var ws = McpCommandJsonArgs.String(args, "workspace_path"); |
| 13 | var target = McpCommandJsonArgs.String(args, "target_path"); |
| 14 | if (string.IsNullOrWhiteSpace(ws)) |
| 15 | return await _vm.DebugLaunchInteractiveAsync().ConfigureAwait(false); |
| 16 | if (string.IsNullOrWhiteSpace(target)) |
| 17 | { |
| 18 | try |
| 19 | { |
| 20 | return await _vm.DebugLaunchByProfileOrResolvedTargetAsync( |
| 21 | ws!, |
| 22 | targetPath: null, |
| 23 | McpCommandJsonArgs.String(args, "profile_name"), |
| 24 | McpCommandJsonArgs.String(args, "netcoredbg_path"), |
| 25 | McpCommandJsonArgs.StringList(args, "program_args"), |
| 26 | ct).ConfigureAwait(false); |
| 27 | } |
| 28 | catch (Exception ex) |
| 29 | { |
| 30 | return "# Error: " + ex.Message; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | try |
| 35 | { |
| 36 | return await _vm.DapDebug.LaunchAsync( |
| 37 | ws!, |
| 38 | target!, |
| 39 | McpCommandJsonArgs.String(args, "netcoredbg_path"), |
| 40 | McpCommandJsonArgs.StringList(args, "program_args"), |
| 41 | environment: null, |
| 42 | workingDirectoryOverride: null, |
| 43 | ct).ConfigureAwait(false); |
| 44 | } |
| 45 | catch (Exception ex) |
| 46 | { |
| 47 | return "# Error: " + ex.Message; |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | add(Services.IdeCommands.DebugAttach, async (args, ct) => |
| 52 | { |
| 53 | var ws = McpCommandJsonArgs.String(args, "workspace_path"); |
| 54 | if (string.IsNullOrWhiteSpace(ws)) |
| 55 | return "workspace_path is required."; |
| 56 | if (args is null || !args.TryGetValue("process_id", out var pidEl) || !pidEl.TryGetInt32(out var pid) || pid <= 0) |
| 57 | return "process_id (positive integer) is required."; |
| 58 | try |
| 59 | { |
| 60 | return await _vm.DapDebug.AttachAsync( |
| 61 | ws!, |
| 62 | pid, |
| 63 | McpCommandJsonArgs.String(args, "target_path"), |
| 64 | McpCommandJsonArgs.String(args, "netcoredbg_path"), |
| 65 | ct).ConfigureAwait(false); |
| 66 | } |
| 67 | catch (Exception ex) |
| 68 | { |
| 69 | return "# Error: " + ex.Message; |
| 70 | } |
| 71 | }); |
| 72 | } |
| 73 | } |
| 74 | |