| 1 | #nullable enable |
| 2 | |
| 3 | namespace CascadeIDE.Features.WorkspaceNavigation.Application; |
| 4 | |
| 5 | /// <summary>Какие слои correspondence L0–L4 активны для текущего якоря (ADR 0155 §3).</summary> |
| 6 | public readonly record struct CorrespondenceLayerSignals( |
| 7 | bool SemanticCanonL0, |
| 8 | bool FeatureRegistryL1p, |
| 9 | bool AdrPathMapL1, |
| 10 | bool CodeIntentGraphL2, |
| 11 | bool ChangeIntentL3, |
| 12 | bool DiscourseCodeL4); |
| 13 | |
| 14 | /// <summary>Строки PFD: бейдж слоёв и tooltip из каталога.</summary> |
| 15 | public static class CorrespondenceLayersProjection |
| 16 | { |
| 17 | public static string BuildLayersBadge(CorrespondenceLayerSignals signals) |
| 18 | { |
| 19 | var parts = new List<string>(6); |
| 20 | if (signals.SemanticCanonL0) |
| 21 | parts.Add(Label("L0")); |
| 22 | if (signals.FeatureRegistryL1p) |
| 23 | parts.Add(Label("L1p")); |
| 24 | if (signals.AdrPathMapL1) |
| 25 | parts.Add(Label("L1")); |
| 26 | if (signals.CodeIntentGraphL2) |
| 27 | parts.Add(Label("L2")); |
| 28 | if (signals.ChangeIntentL3) |
| 29 | parts.Add(Label("L3")); |
| 30 | if (signals.DiscourseCodeL4) |
| 31 | parts.Add(Label("L4")); |
| 32 | |
| 33 | return parts.Count == 0 ? "" : $"Correspondence: {string.Join(" · ", parts)}"; |
| 34 | } |
| 35 | |
| 36 | public static string BuildLayersTooltip(CorrespondenceLayerSignals signals) |
| 37 | { |
| 38 | var lines = new List<string>(); |
| 39 | AppendTooltipLine(lines, signals.SemanticCanonL0, "L0"); |
| 40 | AppendTooltipLine(lines, signals.FeatureRegistryL1p, "L1p"); |
| 41 | AppendTooltipLine(lines, signals.AdrPathMapL1, "L1"); |
| 42 | AppendTooltipLine(lines, signals.CodeIntentGraphL2, "L2"); |
| 43 | AppendTooltipLine(lines, signals.ChangeIntentL3, "L3"); |
| 44 | AppendTooltipLine(lines, signals.DiscourseCodeL4, "L4"); |
| 45 | return lines.Count == 0 |
| 46 | ? "Нет активных слоёв correspondence для этого якоря." |
| 47 | : string.Join(Environment.NewLine, lines); |
| 48 | } |
| 49 | |
| 50 | public static CorrespondenceLayerSignals FromCorrespondence( |
| 51 | bool hasHciOrientation, |
| 52 | bool hasFeature, |
| 53 | bool hasAdrDocs, |
| 54 | bool hasCodeGraph, |
| 55 | bool hasChangeIntent = false, |
| 56 | bool hasDiscourse = false) => |
| 57 | new( |
| 58 | SemanticCanonL0: hasHciOrientation, |
| 59 | FeatureRegistryL1p: hasFeature, |
| 60 | AdrPathMapL1: hasAdrDocs, |
| 61 | CodeIntentGraphL2: hasCodeGraph, |
| 62 | ChangeIntentL3: hasChangeIntent, |
| 63 | DiscourseCodeL4: hasDiscourse); |
| 64 | |
| 65 | private static void AppendTooltipLine(List<string> lines, bool active, string layerId) |
| 66 | { |
| 67 | if (!active) |
| 68 | return; |
| 69 | |
| 70 | if (CorrespondenceKindsCatalog.TryGetLayer(layerId, out var layer)) |
| 71 | lines.Add($"{layer.Label} — {layer.Title}"); |
| 72 | else |
| 73 | lines.Add(layerId); |
| 74 | } |
| 75 | |
| 76 | private static string Label(string layerId) => |
| 77 | CorrespondenceKindsCatalog.TryGetLayer(layerId, out var layer) ? layer.Label : layerId; |
| 78 | } |
| 79 | |