Forge
csharpdeeb25a2
1using CascadeIDE.Models;
2using CascadeIDE.Services.CodeNavigation;
3
4namespace CascadeIDE.Features.IdeMcp.Application;
5
6internal sealed partial class MainWindowIdeMcpHost
7{
8
9 /// <inheritdoc />
10 public Task<string> GetCodeNavigationContextAsync(
11 string mode,
12 string? filePath,
13 int? line,
14 int? column,
15 int? maxRelated,
16 int? maxNodes,
17 int? maxEdges,
18 string? preset,
19 IReadOnlyList<string>? includeKinds,
20 IReadOnlyList<string>? excludeKinds,
21 string? level)
22 {
23 if (!IdeMcpNavigationOrchestrator.TryNormalizeRequestedMode(mode, out var requestedMode))
24 return Task.FromResult(IdeMcpNavigationOrchestrator.BuildInvalidModeJson());
25
26 var (effectiveLevel, effectiveMode) = IdeMcpNavigationOrchestrator.ResolveEffectiveLevelAndMode(
27 level,
28 _host.McpSettings.CodeNavigationMap.Depth,
29 requestedMode);
30
31 if (effectiveLevel == CodeNavigationMapLevelKind.ControlFlow)
32 {
33 var (effectiveLine, effectiveColumn) = IdeMcpNavigationOrchestrator.ResolveControlFlowLineColumn(
34 line,
35 column,
36 _host.EditorText,
37 _host.McpEditorCaretOffset ?? _host.EditorSelectionStart);
38
39 var maxN = maxNodes ?? CodeNavigationContextBuilder.DefaultControlFlowSubgraphMaxNodes;
40 var maxE = maxEdges ?? CodeNavigationContextBuilder.DefaultControlFlowSubgraphMaxEdges;
41 var path = string.IsNullOrWhiteSpace(filePath) ? _host.CurrentFilePath : filePath;
42 var grain = CodeNavigationMapControlFlowGrainKind.Normalize(_host.McpSettings.CodeNavigationMap.ControlFlowGrain);
43
44 return UiScheduler.Default.InvokeAsync(() =>
45 CodeNavigationMapControlFlowGrainKind.IsDetailed(grain)
46 ? CodeNavigationControlFlowSubgraphBuilder.BuildJson(
47 path,
48 _host.EditorText,
49 effectiveLine,
50 effectiveColumn,
51 maxN,
52 maxE)
53 : CodeNavigationMethodIntentSubgraphBuilder.BuildJson(
54 path,
55 _host.EditorText,
56 effectiveLine,
57 effectiveColumn,
58 maxN,
59 maxE));
60 }
61
62 return UiScheduler.Default.InvokeAsync(() =>
63 CodeNavigationContextBuilder.BuildJson(
64 effectiveMode,
65 filePath,
66 _host.CurrentFilePath,
67 _host.Workspace.SolutionRoots,
68 _host.Workspace.SolutionPath,
69 line,
70 column,
71 maxRelated ?? CodeNavigationContextBuilder.DefaultMaxRelated,
72 maxNodes ?? CodeNavigationContextBuilder.DefaultMaxNodes,
73 maxEdges ?? CodeNavigationContextBuilder.DefaultMaxEdges,
74 includeKinds,
75 excludeKinds,
76 preset,
77 _host.McpSettings.CodeNavigation));
78 }
79
80}
81
View only · write via MCP/CIDE