csharp4405de34 | 1 | #nullable enable |
| 2 | |
| 3 | using CascadeIDE.Models.Intercom; |
| 4 | using CascadeIDE.Services; |
| 5 | |
| 6 | namespace CascadeIDE.Services.Intercom; |
| 7 | |
| 8 | /// <summary>Resolve draft bracket → file + line range (без записи anchor в лог).</summary> |
| 9 | public static class AnchorDraftPreviewResolver |
| 10 | { |
| 11 | public sealed record ResolvedPreview(string AbsoluteFilePath, int StartLine, int EndLine); |
| 12 | |
| 13 | public static bool TryResolve( |
| 14 | string bracketText, |
| 15 | string? activeFilePath, |
| 16 | string? workspaceRoot, |
| 17 | string? solutionPath, |
| 18 | string? indexDirectoryRelative, |
| 19 | out ResolvedPreview resolved, |
| 20 | out string error) |
| 21 | { |
| 22 | resolved = default!; |
| 23 | error = ""; |
| 24 | |
| 25 | var text = (bracketText ?? "").Trim(); |
| 26 | if (text.Length == 0) |
| 27 | { |
| 28 | error = "empty_bracket"; |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | if (!BracketCodeReferenceParser.TryParse(text, out var reference, out error)) |
| 33 | return false; |
| 34 | |
| 35 | if (!BracketCodeReferenceParser.TryToAttachmentAnchor( |
| 36 | reference, |
| 37 | activeFilePath, |
| 38 | workspaceRoot, |
| 39 | solutionPath, |
| 40 | indexDirectoryRelative, |
| 41 | out var anchor, |
| 42 | out error)) |
| 43 | { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | if (!IntercomAttachmentResolveAtSend.TryResolveBracketDraft( |
| 48 | reference, |
| 49 | activeFilePath, |
| 50 | workspaceRoot, |
| 51 | solutionPath, |
| 52 | indexDirectoryRelative, |
| 53 | out anchor, |
| 54 | out error)) |
| 55 | { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | var plan = IntercomAttachmentRevealPlan.Create(anchor, workspaceRoot, solutionPath); |
| 60 | if (string.IsNullOrWhiteSpace(plan.AbsoluteFilePath)) |
| 61 | { |
| 62 | error = plan.Message; |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | if (plan.Lines is not { } lines) |
| 67 | { |
| 68 | error = plan.OpenFileOnly ? "open_file_only" : plan.Message; |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | resolved = new ResolvedPreview( |
| 73 | plan.AbsoluteFilePath, |
| 74 | lines.Start.Value, |
| 75 | lines.End.Value); |
| 76 | return true; |
| 77 | } |
| 78 | } |
| 79 | |
View only · write via MCP/CIDE