| 1 | using AgentForge.Contracts; |
| 2 | using AgentForge.Plugin.View.Components; |
| 3 | using AgentForge.Plugin.View.Components.Artifact; |
| 4 | using AgentForge.Services; |
| 5 | |
| 6 | namespace AgentForge.Plugin.View; |
| 7 | |
| 8 | public static class ForgeAnchorList |
| 9 | { |
| 10 | public static string Render( |
| 11 | string repoName, |
| 12 | IReadOnlyList<CodeAnchor> anchors, |
| 13 | string? defaultBranch, |
| 14 | ForgeUrls urls, |
| 15 | int? issueNumber = null) |
| 16 | { |
| 17 | if (anchors.Count == 0) |
| 18 | return ""; |
| 19 | |
| 20 | var items = new List<string>(anchors.Count); |
| 21 | foreach (var anchor in anchors) |
| 22 | { |
| 23 | var label = BracketCodeReferenceFormatter.Format(anchor); |
| 24 | var lensUrl = issueNumber is > 0 |
| 25 | ? ForgeLinkBuilder.LensMagicLink(urls.PublicBaseUrl, repoName, issueNumber.Value, anchor) |
| 26 | : null; |
| 27 | |
| 28 | string inner; |
| 29 | if (!string.IsNullOrWhiteSpace(defaultBranch) && !string.IsNullOrWhiteSpace(anchor.File)) |
| 30 | { |
| 31 | var href = ForgeViewLinks.BlobHref(repoName, defaultBranch, anchor.File, anchor.LineStart, anchor.LineEnd); |
| 32 | inner = ForgeViewAnchorLink.Render(href, label, lensUrl); |
| 33 | } |
| 34 | else |
| 35 | inner = ForgeHtml.Code(label); |
| 36 | |
| 37 | items.Add(ForgeHtml.Li(null, inner)); |
| 38 | } |
| 39 | |
| 40 | return ForgeHtml.Fragment( |
| 41 | ForgeViewSectionHeading.Render("Code anchors"), |
| 42 | ForgeHtml.Ul("plain", [.. items])); |
| 43 | } |
| 44 | } |
| 45 | |