| 1 | using System.Diagnostics.CodeAnalysis; |
| 2 | |
| 3 | namespace CascadeIDE.Cockpit.Composition.HostSurface; |
| 4 | |
| 5 | /// <summary> |
| 6 | /// Публичные alias инструмента в TOML → канонические <c>instrument_id</c> для <see cref="CockpitStandardInstrumentIds"/>. |
| 7 | /// </summary> |
| 8 | public static class InstrumentRoutingAliasResolver |
| 9 | { |
| 10 | /// <summary> |
| 11 | /// Принимает alias или уже канонический <c>instrument_id</c> (для обратной совместимости копипаста из CDS). |
| 12 | /// </summary> |
| 13 | public static bool TryResolve(string? token, [NotNullWhen(true)] out string? canonicalInstrumentId) |
| 14 | { |
| 15 | canonicalInstrumentId = null; |
| 16 | var t = token?.Trim() ?? ""; |
| 17 | if (t.Length == 0) |
| 18 | return false; |
| 19 | |
| 20 | if (IsKnownCanonical(t)) |
| 21 | { |
| 22 | canonicalInstrumentId = NormalizeCanonical(t); |
| 23 | return true; |
| 24 | } |
| 25 | |
| 26 | if (t.Equals("solution_explorer", StringComparison.OrdinalIgnoreCase)) |
| 27 | { |
| 28 | canonicalInstrumentId = CockpitStandardInstrumentIds.SolutionExplorerTree; |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | if (t.Equals("workspace_map", StringComparison.OrdinalIgnoreCase)) |
| 33 | { |
| 34 | canonicalInstrumentId = CockpitStandardInstrumentIds.WorkspaceNavigationMap; |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | if (t.Equals("ide_health", StringComparison.OrdinalIgnoreCase)) |
| 39 | { |
| 40 | canonicalInstrumentId = CockpitStandardInstrumentIds.IdeHealthStatusV1; |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | if (t.Equals("background_status", StringComparison.OrdinalIgnoreCase)) |
| 45 | { |
| 46 | canonicalInstrumentId = CockpitStandardInstrumentIds.WorkspaceBackgroundStatusV1; |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | private static bool IsKnownCanonical(string t) => |
| 54 | t.Equals(CockpitStandardInstrumentIds.SolutionExplorerTree, StringComparison.OrdinalIgnoreCase) |
| 55 | || t.Equals(CockpitStandardInstrumentIds.WorkspaceNavigationMap, StringComparison.OrdinalIgnoreCase) |
| 56 | || t.Equals(CockpitStandardInstrumentIds.IdeHealthStatusV1, StringComparison.OrdinalIgnoreCase) |
| 57 | || t.Equals(CockpitStandardInstrumentIds.WorkspaceBackgroundStatusV1, StringComparison.OrdinalIgnoreCase); |
| 58 | |
| 59 | private static string NormalizeCanonical(string t) |
| 60 | { |
| 61 | if (t.Equals(CockpitStandardInstrumentIds.SolutionExplorerTree, StringComparison.OrdinalIgnoreCase)) |
| 62 | return CockpitStandardInstrumentIds.SolutionExplorerTree; |
| 63 | if (t.Equals(CockpitStandardInstrumentIds.WorkspaceNavigationMap, StringComparison.OrdinalIgnoreCase)) |
| 64 | return CockpitStandardInstrumentIds.WorkspaceNavigationMap; |
| 65 | if (t.Equals(CockpitStandardInstrumentIds.WorkspaceBackgroundStatusV1, StringComparison.OrdinalIgnoreCase)) |
| 66 | return CockpitStandardInstrumentIds.WorkspaceBackgroundStatusV1; |
| 67 | return CockpitStandardInstrumentIds.IdeHealthStatusV1; |
| 68 | } |
| 69 | } |
| 70 | |