csharpa2ee7322 | 1 | using System.Text.Json; |
| 2 | using CascadeIDE.Features.Workspace.Application; |
| 3 | using CascadeIDE.ViewModels; |
| 4 | |
| 5 | namespace CascadeIDE.Features.IdeMcp.Execution; |
| 6 | |
| 7 | /// <summary>Вспомогательные методы MCP: корень workspace из solution_path.</summary> |
| 8 | internal sealed partial class IdeMcpCommandExecutor |
| 9 | { |
| 10 | private string? TryGetAttachSolutionPath() => |
| 11 | _vm is MainWindowViewModel mw ? mw.ChatPanel.ResolveAttachSolutionPath() : null; |
| 12 | |
| 13 | internal static string? TryGetWorkspaceRoot(IIdeMcpActions actions) |
| 14 | { |
| 15 | try |
| 16 | { |
| 17 | var json = actions.GetSolutionInfo(); |
| 18 | using var doc = JsonDocument.Parse(json); |
| 19 | if (doc.RootElement.TryGetProperty("error", out _)) |
| 20 | return null; |
| 21 | var sln = doc.RootElement.TryGetProperty("solution_path", out var sp) ? sp.GetString() : null; |
| 22 | if (string.IsNullOrWhiteSpace(sln)) |
| 23 | return null; |
| 24 | return WorkspaceDirectoryFromSolutionPath.Resolve(sln); |
| 25 | } |
| 26 | catch (JsonException) |
| 27 | { |
| 28 | return null; |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
View only · write via MCP/CIDE