Skip to content

Commit d99e90c

Browse files
Hide the navigation nodes for unmodified nodes in diff (#9015)
1 parent 34d0ef6 commit d99e90c

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

src/dotnet/APIView/APIView/Model/CodeFile.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ public void ConvertToTreeTokenModel()
186186
List<ReviewToken> currentLineTokens = new List<ReviewToken>();
187187
foreach(var oldToken in Tokens)
188188
{
189+
//Don't include documentation in converted code file due to incorrect documentation formatting used in previous model.
190+
if (isDocumentation && oldToken.Kind != CodeFileTokenKind.DocumentRangeEnd)
191+
continue;
189192
ReviewToken token = null;
190193
switch(oldToken.Kind)
191194
{
@@ -270,6 +273,13 @@ public void ConvertToTreeTokenModel()
270273
reviewLine.parentLine = parent;
271274
}
272275

276+
//Handle specific cases for C++ line with 'public:' and '{' to mark related line
277+
if ((currentLineTokens.Count == 1 && currentLineTokens.First().Value == "{") ||
278+
(currentLineTokens.Count == 2 && currentLineTokens.Any(t => t.Kind == TokenKind.Keyword && t.Value == "public")))
279+
{
280+
reviewLine.RelatedToLine = previousLine?.LineId;
281+
}
282+
273283
if (currentLineTokens.Count == 0)
274284
{
275285
//Empty line. So just add previous line as related line

src/dotnet/APIView/ClientSPA/src/app/_models/navigationTreeModels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export class NavigationTreeNode {
99
data: NavigationTreeNodeData = new NavigationTreeNodeData();
1010
expanded: boolean = false;
1111
children: NavigationTreeNode[] = [];
12+
visible: boolean = true;
1213
}

src/dotnet/APIView/ClientSPA/src/app/_workers/apitree-builder.worker.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,22 @@ addEventListener('message', ({ data }) => {
2727
if (!codePanelData?.hasDiff) {
2828
apiTreeBuilderData!.diffStyle = FULL_DIFF_STYLE; // If there is no diff nodes and tree diff will not work
2929
}
30-
31-
if (codePanelData?.navigationTreeNodes && codePanelData?.navigationTreeNodes.length > 0)
32-
{
33-
isNavigationTreeCreated = true;
34-
navigationTree = codePanelData?.navigationTreeNodes;
35-
}
30+
3631
buildCodePanelRows("root", navigationTree);
3732
const codePanelRowDataMessage : InsertCodePanelRowDataMessage = {
3833
directive: ReviewPageWorkerMessageDirective.UpdateCodePanelRowData,
3934
payload: codePanelRowData
4035
};
4136

37+
if (codePanelData?.navigationTreeNodes && codePanelData?.navigationTreeNodes.length > 0)
38+
{
39+
isNavigationTreeCreated = true;
40+
navigationTree = codePanelData?.navigationTreeNodes;
41+
//Remove navigation nodes for nodes that are not visible in diff style view
42+
navigationTree.forEach(node => FilterVisibleNavigationNodes(node));
43+
navigationTree = navigationTree.filter(n => n.visible);
44+
}
45+
4246
postMessage(codePanelRowDataMessage);
4347

4448
const navigationTreeMessage : InsertCodePanelRowDataMessage = {
@@ -259,4 +263,18 @@ function shouldAppendIfRowIsHiddenAPI(row: CodePanelRowData) {
259263
} else {
260264
return true;
261265
}
266+
}
267+
268+
function FilterVisibleNavigationNodes(node: NavigationTreeNode) {
269+
// Recursively perform a bottom up traversal and trim down any invisible nodes
270+
if (node.children) {
271+
for (let child of node.children) {
272+
FilterVisibleNavigationNodes(child);
273+
}
274+
node.children = node.children.filter(c => c.visible);
275+
}
276+
277+
if (visibleNodes.has(node.data.nodeIdHashed) || (node.children && node.children.some(c => c.visible))) {
278+
node.visible = true;
279+
}
262280
}

0 commit comments

Comments
 (0)