Skip to content

Commit bdd5f99

Browse files
Feature/cross language API revision context (#7849)
* Implement Cross Language View in Context
1 parent 9465eaf commit bdd5f99

39 files changed

Lines changed: 4535 additions & 171 deletions

src/dotnet/APIView/APIView/CodeFileRenderer.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private void Render(List<CodeLine> list, IEnumerable<CodeFileToken> node, bool s
3333
{
3434
var stringBuilder = new StringBuilder();
3535
string currentId = null;
36+
string currentCrossLangId = null;
3637
string currentTableId = null;
3738
bool isDocumentationRange = false;
3839
bool isHiddenApiToken = false;
@@ -57,7 +58,7 @@ private void Render(List<CodeLine> list, IEnumerable<CodeFileToken> node, bool s
5758
switch (token.Kind)
5859
{
5960
case CodeFileTokenKind.Newline:
60-
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, isDocumentationRange, isHiddenApiToken);
61+
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, ref currentCrossLangId, isDocumentationRange, isHiddenApiToken);
6162
break;
6263

6364
case CodeFileTokenKind.DocumentRangeStart:
@@ -97,6 +98,7 @@ private void Render(List<CodeLine> list, IEnumerable<CodeFileToken> node, bool s
9798
case CodeFileTokenKind.FoldableSectionHeading:
9899
nodesInProcess.Push(SectionType.Heading);
99100
currentId = (token.DefinitionId != null) ? token.DefinitionId : currentId;
101+
currentCrossLangId = (token.CrossLanguageDefinitionId != null) ? token.CrossLanguageDefinitionId : currentCrossLangId;
100102
RenderToken(token, stringBuilder, isDeprecatedToken, isHiddenApiToken);
101103
break;
102104

@@ -149,7 +151,7 @@ private void Render(List<CodeLine> list, IEnumerable<CodeFileToken> node, bool s
149151
stringBuilder.Append("</strong></li>");
150152
stringBuilder.Append("</ul>");
151153
tableColumnCount.Curr = 0;
152-
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, isDocumentationRange, isHiddenApiToken);
154+
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, ref currentCrossLangId, isDocumentationRange, isHiddenApiToken);
153155
}
154156
else
155157
{
@@ -186,7 +188,7 @@ private void Render(List<CodeLine> list, IEnumerable<CodeFileToken> node, bool s
186188
if (tableColumnCount.Curr == 0)
187189
{
188190
stringBuilder.Append("</ul>");
189-
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, isDocumentationRange, isHiddenApiToken);
191+
CaptureCodeLine(list, sections, nodesInProcess, ref section, stringBuilder, ref lineNumber, ref leafSectionPlaceHolderNumber, ref currentId, ref currentCrossLangId, isDocumentationRange, isHiddenApiToken);
190192
}
191193
break;
192194

@@ -208,6 +210,7 @@ private void Render(List<CodeLine> list, IEnumerable<CodeFileToken> node, bool s
208210

209211
default:
210212
currentId = (token.DefinitionId != null) ? token.DefinitionId : currentId;
213+
currentCrossLangId = (token.CrossLanguageDefinitionId != null) ? token.CrossLanguageDefinitionId : currentCrossLangId;
211214
RenderToken(token, stringBuilder, isDeprecatedToken, isHiddenApiToken);
212215
break;
213216
}
@@ -228,11 +231,11 @@ protected virtual void StartDocumentationRange(StringBuilder stringBuilder) { }
228231
protected virtual void CloseDocumentationRange(StringBuilder stringBuilder) { }
229232

230233
private void CaptureCodeLine(List<CodeLine> list, Dictionary<int, TreeNode<CodeLine>> sections, Stack<SectionType> nodesInProcess,
231-
ref TreeNode<CodeLine> section, StringBuilder stringBuilder, ref int lineNumber, ref int leafSectionPlaceHolderNumber, ref string currentId,
234+
ref TreeNode<CodeLine> section, StringBuilder stringBuilder, ref int lineNumber, ref int leafSectionPlaceHolderNumber, ref string currentId, ref string currentCrossLangId,
232235
bool isDocumentationRange = false, bool isHiddenApiToken = false)
233236
{
234237
int? sectionKey = (nodesInProcess.Count > 0 && section == null) ? sections.Count : null;
235-
CodeLine codeLine = new CodeLine(stringBuilder.ToString(), currentId, String.Empty, ++lineNumber, sectionKey, isDocumentation: isDocumentationRange, isHiddenApi: isHiddenApiToken);
238+
CodeLine codeLine = new CodeLine(stringBuilder.ToString(), currentId, currentCrossLangId, String.Empty, ++lineNumber, sectionKey, isDocumentation: isDocumentationRange, isHiddenApi: isHiddenApiToken);
236239
if (leafSectionPlaceHolderNumber != 0)
237240
{
238241
lineNumber += leafSectionPlaceHolderNumber - 1;

src/dotnet/APIView/APIView/CodeLine.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace ApiView
77
{
88
public string DisplayString { get; }
99
public string ElementId { get; }
10+
public string CrossLanguageDefinitionId { get; }
1011
public string LineClass { get; }
1112
public int? LineNumber { get; }
1213
public int? SectionKey { get; }
@@ -15,10 +16,11 @@ namespace ApiView
1516
public TreeNode<CodeLine> NodeRef { get; }
1617
public bool IsHiddenApi { get; }
1718

18-
public CodeLine(string html, string id, string lineClass, int? lineNumber = null, int? sectionKey = null, int indent = 0, bool isDocumentation = false, TreeNode<CodeLine> nodeRef = null, bool isHiddenApi = false)
19+
public CodeLine(string html, string id, string crossLangId, string lineClass, int? lineNumber = null, int? sectionKey = null, int indent = 0, bool isDocumentation = false, TreeNode<CodeLine> nodeRef = null, bool isHiddenApi = false)
1920
{
2021
this.DisplayString = html;
2122
this.ElementId = id;
23+
this.CrossLanguageDefinitionId = crossLangId;
2224
this.LineClass = lineClass;
2325
this.LineNumber = lineNumber;
2426
this.SectionKey = sectionKey;
@@ -28,10 +30,11 @@ public CodeLine(string html, string id, string lineClass, int? lineNumber = null
2830
this.IsHiddenApi = isHiddenApi;
2931
}
3032

31-
public CodeLine(CodeLine codeLine, string html = null, string id = null, string lineClass = null, int? lineNumber = null, int? sectionKey = null, int indent = 0, bool isDocumentation = false, TreeNode<CodeLine> nodeRef = null, bool isHiddenApi = false)
33+
public CodeLine(CodeLine codeLine, string html = null, string id = null, string crossLangId = null, string lineClass = null, int? lineNumber = null, int? sectionKey = null, int indent = 0, bool isDocumentation = false, TreeNode<CodeLine> nodeRef = null, bool isHiddenApi = false)
3234
{
3335
this.DisplayString = html ?? codeLine.DisplayString;
3436
this.ElementId = id ?? codeLine.ElementId;
37+
this.CrossLanguageDefinitionId = crossLangId ?? codeLine.CrossLanguageDefinitionId;
3538
this.LineClass = lineClass ?? codeLine.LineClass;
3639
this.LineNumber = lineNumber ?? codeLine.LineNumber;
3740
this.SectionKey = sectionKey ?? codeLine.SectionKey;

src/dotnet/APIView/APIView/Model/CodeFileToken.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public CodeFileToken(string value, CodeFileTokenKind kind, int? numberOfLinesinL
88
NavigateToId = null;
99
Kind = kind;
1010
DefinitionId = null;
11-
CrossLanguageDefId = null;
11+
CrossLanguageDefinitionId = null;
1212
NumberOfLinesinLeafSection = numberOfLinesinLeafSection;
1313
}
1414

@@ -20,7 +20,7 @@ public CodeFileToken(string value, CodeFileTokenKind kind, int? numberOfLinesinL
2020

2121
public CodeFileTokenKind Kind { get; set; }
2222

23-
public string CrossLanguageDefId { get; set; }
23+
public string CrossLanguageDefinitionId { get; set; }
2424

2525
public int? NumberOfLinesinLeafSection { get; set; }
2626

src/dotnet/APIView/APIViewWeb/Client/css/main.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@import "./shared/sumo-select.scss";
55
@import "./shared/bootstraps-overrides.scss";
66
@import "./shared/off-canvas.scss";
7-
@import "./shared/icons.scss";
7+
@import "./shared/language-customizations.scss";
88
@import "./shared/codeline-navigation.scss";
99
@import "./shared/codeline.scss";
1010
@import "./shared/comments.scss";

src/dotnet/APIView/APIViewWeb/Client/css/shared/codeline.scss

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
animation: glow normal 1.5s ease-in-out;
4242
}
4343

44+
.code-line.cl-active, .code-line tr.cl-active {
45+
background: rgba(239,155,15, 0.22);
46+
}
47+
4448
.code {
4549
padding: 0px;
4650
position: relative;
@@ -133,6 +137,48 @@
133137
width: auto;
134138
}
135139

140+
.cl-line-no {
141+
color: goldenrod;
142+
}
143+
144+
.cross-language-panel {
145+
.nav-link {
146+
color: var(--link-color);
147+
}
148+
149+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
150+
background-color: transparent;
151+
box-shadow: var(--box-shadow-left);
152+
}
153+
154+
.nav-pills .nav-link {
155+
border-radius: 0;
156+
}
157+
158+
.badge {
159+
background-color: var(--link-color);
160+
border-color: var(--link-color);
161+
color: var(--primary-btn-color);
162+
}
163+
}
164+
165+
166+
.cross-language-pills-tab-content {
167+
width: 55dvw;
168+
margin-right: 5px;
169+
max-height: 35dvh;
170+
overflow: auto;
171+
}
172+
173+
.cl-custom-popover {
174+
--bs-popover-max-width: 200px;
175+
--bs-popover-border-color: var(--bd-violet-bg);
176+
--bs-popover-header-bg: var(--bd-violet-bg);
177+
--bs-popover-header-color: var(--bs-white);
178+
--bs-popover-body-padding-x: 1rem;
179+
--bs-popover-body-padding-y: .5rem;
180+
}
181+
136182
.line-comment-button:hover {
137183
transform: scale(1);
138184
text-decoration: none;

src/dotnet/APIView/APIViewWeb/Client/css/shared/icons.scss renamed to src/dotnet/APIView/APIViewWeb/Client/css/shared/language-customizations.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@
228228
background: url(/icons/swagger-original.svg) center/contain no-repeat;
229229
}
230230

231+
.icon-typespec {
232+
@extend .icon-language;
233+
background: url(/icons/typespec-original.svg) center center no-repeat;
234+
}
235+
231236
.icon-comments {
232237
cursor: pointer;
233238
position: absolute;

0 commit comments

Comments
 (0)