| 1 | #nullable enable |
| 2 | using CascadeIDE.Contracts; |
| 3 | using CascadeIDE.Models; |
| 4 | using CascadeIDE.Services; |
| 5 | using CascadeIDE.Services.CodeNavigation; |
| 6 | |
| 7 | namespace CascadeIDE.Features.WorkspaceNavigation.Application; |
| 8 | |
| 9 | /// <summary> |
| 10 | /// Сборка JSON контекста карты намерений для PFD (тяжёлая работа — вызывать из фона, см. refresh в <c>MainWindowViewModel.WorkspaceNavigationMap</c>). |
| 11 | /// </summary> |
| 12 | [ComputingUnit] |
| 13 | public static class WorkspaceNavigationMapContextJsonBuilder |
| 14 | { |
| 15 | /// <summary> |
| 16 | /// Должен совпадать с логикой refresh: control flow всегда отдельная ветка; иначе <c>subgraph</c> при <paramref name="wantGraph"/> или уровне control flow уже обработанным выше. |
| 17 | /// </summary> |
| 18 | /// <param name="normalizedLevel">Результат <see cref="CodeNavigationMapLevelKind.Normalize"/></param> |
| 19 | /// <param name="rawFilePathsFromSolution">Полные пути из <see cref="McpSolutionTree.CollectFileEntries"/>.</param> |
| 20 | /// <param name="controlFlowGrain">Канон <see cref="CodeNavigationMapControlFlowGrainKind"/>; null → intent.</param> |
| 21 | public static string Build( |
| 22 | string normalizedLevel, |
| 23 | bool wantGraph, |
| 24 | string? currentPath, |
| 25 | string? editorText, |
| 26 | int? cursorLine, |
| 27 | int? cursorColumn, |
| 28 | IEnumerable<string> rawFilePathsFromSolution, |
| 29 | string? solutionPath, |
| 30 | CodeNavigationSettings? navSettings, |
| 31 | string? controlFlowGrain = null) |
| 32 | { |
| 33 | var settings = navSettings ?? new CodeNavigationSettings(); |
| 34 | var useSubgraphMode = normalizedLevel == CodeNavigationMapLevelKind.ControlFlow || wantGraph; |
| 35 | |
| 36 | if (normalizedLevel == CodeNavigationMapLevelKind.ControlFlow) |
| 37 | { |
| 38 | var grain = CodeNavigationMapControlFlowGrainKind.Normalize(controlFlowGrain); |
| 39 | if (CodeNavigationMapControlFlowGrainKind.IsDetailed(grain)) |
| 40 | { |
| 41 | return CodeNavigationControlFlowSubgraphBuilder.BuildJson( |
| 42 | currentPath, |
| 43 | editorText, |
| 44 | cursorLine, |
| 45 | cursorColumn, |
| 46 | CodeNavigationContextBuilder.DefaultControlFlowSubgraphMaxNodes, |
| 47 | CodeNavigationContextBuilder.DefaultControlFlowSubgraphMaxEdges); |
| 48 | } |
| 49 | |
| 50 | return CodeNavigationMethodIntentSubgraphBuilder.BuildJson( |
| 51 | currentPath, |
| 52 | editorText, |
| 53 | cursorLine, |
| 54 | cursorColumn, |
| 55 | CodeNavigationContextBuilder.DefaultControlFlowSubgraphMaxNodes, |
| 56 | CodeNavigationContextBuilder.DefaultControlFlowSubgraphMaxEdges); |
| 57 | } |
| 58 | |
| 59 | if (useSubgraphMode) |
| 60 | { |
| 61 | return CodeNavigationContextBuilder.BuildJson( |
| 62 | "subgraph", |
| 63 | null, |
| 64 | currentPath, |
| 65 | rawFilePathsFromSolution, |
| 66 | solutionPath, |
| 67 | null, |
| 68 | null, |
| 69 | CodeNavigationContextBuilder.DefaultMaxRelated, |
| 70 | CodeNavigationContextBuilder.DefaultMaxNodes, |
| 71 | CodeNavigationContextBuilder.DefaultMaxEdges, |
| 72 | null, |
| 73 | null, |
| 74 | null, |
| 75 | settings); |
| 76 | } |
| 77 | |
| 78 | return CodeNavigationContextBuilder.BuildJson( |
| 79 | "related", |
| 80 | null, |
| 81 | currentPath, |
| 82 | rawFilePathsFromSolution, |
| 83 | solutionPath, |
| 84 | null, |
| 85 | null, |
| 86 | CodeNavigationContextBuilder.DefaultMaxRelated, |
| 87 | CodeNavigationContextBuilder.DefaultMaxNodes, |
| 88 | CodeNavigationContextBuilder.DefaultMaxEdges, |
| 89 | null, |
| 90 | null, |
| 91 | null, |
| 92 | settings); |
| 93 | } |
| 94 | } |
| 95 | |