@@ -21,32 +21,27 @@ public static async Task<CodePanelData> GenerateCodePanelDataAsync(CodePanelRawD
2121
2222 // Create root node
2323 var rootNodeId = "root" ;
24- if ( ! codePanelData . NodeMetaDataObj . ContainsKey ( rootNodeId ) )
25- {
26- codePanelData . NodeMetaDataObj . TryAdd ( rootNodeId , new CodePanelNodeMetaData ( ) ) ;
27- }
24+ codePanelData . NodeMetaDataObj [ rootNodeId ] = new CodePanelNodeMetaData ( ) ;
2825 var codeFile = codePanelRawData . activeRevisionCodeFile ;
29- codePanelData . NodeMetaDataObj [ rootNodeId ] . NavigationTreeNode = CreateRootNode ( $ "{ codeFile . PackageName } { codeFile . PackageVersion } ", rootNodeId ) ;
26+ codePanelData . AddNavigation ( rootNodeId , CreateRootNode ( $ "{ codeFile . PackageName } { codeFile . PackageVersion } ", rootNodeId ) ) ;
3027
3128 //Collect documentation lines from active revision
32- Dictionary < string , List < CodePanelRowData > > documentationMap = new Dictionary < string , List < CodePanelRowData > > ( ) ;
33- Dictionary < string , List < CodePanelRowData > > diffDdocumentationMap = new Dictionary < string , List < CodePanelRowData > > ( ) ;
34- CollectDocumentationLines ( codeFile . ReviewLines , documentationMap , 1 , "root" ) ;
29+ CollectDocumentationLines ( codeFile . ReviewLines , codePanelData . ActiveDocumentationMap , 1 , "root" ) ;
3530
3631 //Calculate the diff if diff revision code file is present
3732 if ( codePanelRawData . diffRevisionCodeFile != null )
3833 {
3934 var diffLines = codePanelRawData . diffRevisionCodeFile . ReviewLines ;
40- CollectDocumentationLines ( diffLines , diffDdocumentationMap , 1 , "root" , true ) ;
35+ CollectDocumentationLines ( diffLines , codePanelData . DiffDocumentationMap , 1 , "root" , true ) ;
4136 // Check if diff is required for active revision and diff revision to avoid unnecessary diff calculation
4237 bool hasSameApis = AreCodeFilesSame ( codePanelRawData . activeRevisionCodeFile , codePanelRawData . diffRevisionCodeFile ) ;
4338 if ( ! hasSameApis )
4439 {
4540 reviewLines = FindDiff ( reviewLines , codePanelRawData . diffRevisionCodeFile . ReviewLines ) ;
4641 // Remap nodeIdHashed for documentation to diff adjusted nodeIdHashed so that documentation is correctly listed on review.
47- RemapDocumentationLines ( reviewLines , documentationMap ) ;
42+ RemapDocumentationLines ( reviewLines , codePanelData . ActiveDocumentationMap ) ;
4843 // Remap documentation is diff revision using node hash ID for active revision. We don't need to show documentation if it's node itself is not present in active revision.
49- RemapDocumentationLines ( reviewLines , diffDdocumentationMap ) ;
44+ RemapDocumentationLines ( reviewLines , codePanelData . DiffDocumentationMap ) ;
5045 codePanelData . HasDiff = true ;
5146 }
5247 else
@@ -56,56 +51,60 @@ public static async Task<CodePanelData> GenerateCodePanelDataAsync(CodePanelRawD
5651 }
5752
5853 int idx = 0 ;
59- string previousNodeHashId = "" ;
60- foreach ( var reviewLine in reviewLines )
54+ string nodeHashId = "" ;
55+ Dictionary < string , string > relatedLineMap = new Dictionary < string , string > ( ) ;
56+ foreach ( var reviewLine in reviewLines )
6157 {
6258 if ( reviewLine . IsDocumentation ) continue ;
63- previousNodeHashId = await BuildAPITree ( codePanelData : codePanelData , codePanelRawData : codePanelRawData , reviewLine : reviewLines [ idx ] ,
64- parentNodeIdHashed : rootNodeId , nodePositionAtLevel : idx , documentationMap : documentationMap , diffDocumentationMap : diffDdocumentationMap , prevNodeHashId : previousNodeHashId ) ;
65- idx ++ ;
59+ nodeHashId = await BuildAPITree ( codePanelData : codePanelData , codePanelRawData : codePanelRawData , reviewLine : reviewLines [ idx ] ,
60+ parentNodeIdHashed : rootNodeId , nodePositionAtLevel : idx , prevNodeHashId : nodeHashId , relatedLineMap : relatedLineMap ) ;
61+ idx ++ ;
6662 }
67- return codePanelData ;
68- }
69-
7063
71- // Creates tree reference for code line nodes in the review. This tree helps to render the code panel in the UI.
72- private static void ConnectNodeToParent ( CodePanelData codePanelData , string nodeIdHashed , string parentNodeIdHashed , int nodePosition )
73- {
74- if ( ! codePanelData . NodeMetaDataObj . ContainsKey ( nodeIdHashed ) )
64+ //Set related line's node ID hashed in tree metadata
65+ foreach ( var key in relatedLineMap . Keys )
7566 {
76- codePanelData . NodeMetaDataObj . TryAdd ( nodeIdHashed , new CodePanelNodeMetaData ( ) ) ;
67+ codePanelData . SetLineAsRelated ( key , relatedLineMap [ key ] ) ;
7768 }
78- codePanelData . NodeMetaDataObj [ nodeIdHashed ] . ParentNodeIdHashed = parentNodeIdHashed ;
79- codePanelData . NodeMetaDataObj [ parentNodeIdHashed ] . ChildrenNodeIdsInOrderObj . TryAdd ( nodePosition , nodeIdHashed ) ;
69+ return codePanelData ;
8070 }
8171
72+
8273 private static async Task < string > BuildAPITree ( CodePanelData codePanelData , CodePanelRawData codePanelRawData , ReviewLine reviewLine , string parentNodeIdHashed , int nodePositionAtLevel ,
83- Dictionary < string , List < CodePanelRowData > > documentationMap , Dictionary < string , List < CodePanelRowData > > diffDocumentationMap , string prevNodeHashId , int indent = 1 )
74+ string prevNodeHashId , Dictionary < string , string > relatedLineMap , int indent = 1 )
8475 {
8576 //Create hashed node ID for current review line(node)
8677 var nodeIdHashed = reviewLine . GetTokenNodeIdHash ( parentNodeIdHashed , nodePositionAtLevel ) ;
78+ codePanelData . AddLineIdNodeHashMapping ( reviewLine . LineId , nodeIdHashed ) ;
8779 //Create parent and child tree reference map
88- ConnectNodeToParent ( codePanelData , nodeIdHashed , parentNodeIdHashed , nodePositionAtLevel ) ;
89-
80+ codePanelData . ConnectNodeToParent ( nodeIdHashed , parentNodeIdHashed , nodePositionAtLevel ) ;
81+
82+ //Populate the map of nodeHashId to it's related line ID
83+ // This is later used to set related line's node ID hashed in tree metadata since related tree node is built after current node.
84+ if ( ! string . IsNullOrEmpty ( reviewLine . RelatedToLine ) )
85+ {
86+ relatedLineMap [ nodeIdHashed ] = reviewLine . RelatedToLine ;
87+ }
88+
9089 // Build current code line node
91- BuildNodeTokens ( codePanelData , codePanelRawData , reviewLine , nodeIdHashed , indent , documentationMap , diffDocumentationMap ) ;
90+ BuildNodeTokens ( codePanelData , codePanelRawData , reviewLine , nodeIdHashed , indent ) ;
9291
9392 //Create navigation node for current line
9493 var navTreeNode = CreateNavigationNode ( reviewLine , nodeIdHashed ) ;
9594 if ( navTreeNode != null )
9695 {
97- codePanelData . NodeMetaDataObj [ nodeIdHashed ] . NavigationTreeNode = navTreeNode ;
96+ codePanelData . AddNavigation ( nodeIdHashed , navTreeNode ) ;
9897 }
9998
10099 // Process all child lines
101100 int idx = 0 ;
102- string prevChildNodeHashId = "" ;
101+ string childNodeHashId = "" ;
103102 foreach ( var childLine in reviewLine . Children )
104103 {
105104 if ( childLine . IsDocumentation ) continue ;
106105
107- prevChildNodeHashId = await BuildAPITree ( codePanelData : codePanelData , codePanelRawData : codePanelRawData , reviewLine : childLine ,
108- parentNodeIdHashed : nodeIdHashed , nodePositionAtLevel : idx , documentationMap , diffDocumentationMap , prevNodeHashId : prevChildNodeHashId , indent : indent + 1 ) ;
106+ childNodeHashId = await BuildAPITree ( codePanelData : codePanelData , codePanelRawData : codePanelRawData , reviewLine : childLine ,
107+ parentNodeIdHashed : nodeIdHashed , nodePositionAtLevel : idx , prevNodeHashId : childNodeHashId , relatedLineMap : relatedLineMap , indent : indent + 1 ) ;
109108 idx ++ ;
110109 } ;
111110
@@ -173,17 +172,16 @@ private static NavigationTreeNode CreateRootNode(string rootName, string nodeIdH
173172 return navTreeNode ;
174173 }
175174
176- private static void BuildNodeTokens ( CodePanelData codePanelData , CodePanelRawData codePanelRawData , ReviewLine reviewLine , string nodeIdHashed , int indent ,
177- Dictionary < string , List < CodePanelRowData > > documentationMap , Dictionary < string , List < CodePanelRowData > > diffDocumentationMap )
175+ private static void BuildNodeTokens ( CodePanelData codePanelData , CodePanelRawData codePanelRawData , ReviewLine reviewLine , string nodeIdHashed , int indent )
178176 {
179177 // Generate code line row
180178 var codePanelRow = GetCodePanelRowData ( reviewLine , nodeIdHashed , indent ) ;
181179
182180 // Add documentation rows to code panel data
183- if ( documentationMap . ContainsKey ( nodeIdHashed ) )
181+ if ( codePanelData . ActiveDocumentationMap . ContainsKey ( nodeIdHashed ) )
184182 {
185- var activeDocLines = documentationMap [ nodeIdHashed ] ;
186- var diffDocLines = diffDocumentationMap . ContainsKey ( nodeIdHashed ) ? diffDocumentationMap [ nodeIdHashed ] : new List < CodePanelRowData > ( ) ;
183+ var activeDocLines = codePanelData . ActiveDocumentationMap [ nodeIdHashed ] ;
184+ var diffDocLines = codePanelData . DiffDocumentationMap . ContainsKey ( nodeIdHashed ) ? codePanelData . DiffDocumentationMap [ nodeIdHashed ] : new List < CodePanelRowData > ( ) ;
187185 var docLines = activeDocLines . InterleavedUnion ( diffDocLines ) ;
188186 var docsIntersect = new HashSet < CodePanelRowData > ( diffDocLines . Intersect ( activeDocLines ) ) ;
189187 var activeDocs = new HashSet < CodePanelRowData > ( activeDocLines ) ;
0 commit comments