Skip to content

Commit 1e5aa8d

Browse files
Rework comments to work across multi lines nodes
1 parent 221cb8d commit 1e5aa8d

File tree

10 files changed

+137
-86
lines changed

10 files changed

+137
-86
lines changed

src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
using Amazon.Runtime.Internal.Transform;
23
using APIView.TreeToken;
34
using APIViewWeb.Extensions;
45
using APIViewWeb.LeanModels;
@@ -632,12 +633,11 @@ private static string CreateHashFromString(string inputString)
632633
private static CodePanelRowData CollectUserCommentsForRow(CodePanelRawData codePanelRawData, HashSet<string> tokenIdsInRow, string nodeId, string nodeIdHashed, RowOfTokensPosition linesOfTokensPosition, CodePanelRowData codePanelRowData)
633634
{
634635
var commentRowData = new CodePanelRowData();
635-
var toggleCommentClass = (codePanelRawData.Diagnostics.Any(d => d.TargetId == nodeId) && codePanelRowData.Type == CodePanelRowDatatype.CodeLine) ? "bi bi-chat-right-text show" : "";
636+
//var toggleCommentClass = (codePanelRawData.Diagnostics.Any(d => d.TargetId == nodeId) && codePanelRowData.Type == CodePanelRowDatatype.CodeLine) ? "bi bi-chat-right-text show" : "";
636637

637638
if (tokenIdsInRow.Any())
638639
{
639-
toggleCommentClass = (String.IsNullOrWhiteSpace(toggleCommentClass)) ? "bi bi-chat-right-text can-show" : toggleCommentClass;
640-
codePanelRowData.ToggleCommentsClasses = toggleCommentClass;
640+
codePanelRowData.ToggleCommentsClasses = "bi bi-chat-right-text can-show";
641641

642642
var commentsForRow = codePanelRawData.Comments.Where(c => tokenIdsInRow.Contains(c.ElementId));
643643
if (commentsForRow.Any())
@@ -648,15 +648,13 @@ private static CodePanelRowData CollectUserCommentsForRow(CodePanelRawData codeP
648648
commentRowData.RowOfTokensPosition = linesOfTokensPosition;
649649
commentRowData.RowClassesObj.Add("user-comment-thread");
650650
commentRowData.CommentsObj = commentsForRow.ToList();
651-
toggleCommentClass = toggleCommentClass.Replace("can-show", "show");
652-
codePanelRowData.ToggleCommentsClasses = toggleCommentClass;
651+
codePanelRowData.ToggleCommentsClasses = codePanelRowData.ToggleCommentsClasses.Replace("can-show", "show");
653652
commentRowData.IsResolvedCommentThread = commentsForRow.Any(c => c.IsResolved);
654653
}
655654
}
656655
else
657656
{
658-
toggleCommentClass = (!String.IsNullOrWhiteSpace(toggleCommentClass)) ? toggleCommentClass.Replace("can-show", "show") : "bi bi-chat-right-text hide";
659-
codePanelRowData.ToggleCommentsClasses = toggleCommentClass;
657+
codePanelRowData.ToggleCommentsClasses = "bi bi-chat-right-text hide";
660658
}
661659
return commentRowData;
662660
}
@@ -689,11 +687,13 @@ private static void InsertCodePanelRowData(CodePanelData codePanelData, CodePane
689687
{
690688
if (codePanelData.NodeMetaDataObj.ContainsKey(nodeIdHashed))
691689
{
690+
rowData.RowPositionInGroup = codePanelData.NodeMetaDataObj[nodeIdHashed].DocumentationObj.Count();
692691
codePanelData.NodeMetaDataObj[nodeIdHashed].DocumentationObj.Add(rowData);
693692
}
694693
else
695694
{
696695
codePanelData.NodeMetaDataObj.TryAdd(nodeIdHashed, new CodePanelNodeMetaData());
696+
rowData.RowPositionInGroup = codePanelData.NodeMetaDataObj[nodeIdHashed].DocumentationObj.Count();
697697
codePanelData.NodeMetaDataObj[nodeIdHashed].DocumentationObj.Add(rowData);
698698
}
699699
}
@@ -702,25 +702,28 @@ private static void InsertCodePanelRowData(CodePanelData codePanelData, CodePane
702702
{
703703
if (codePanelData.NodeMetaDataObj.ContainsKey(nodeIdHashed))
704704
{
705+
rowData.RowPositionInGroup = codePanelData.NodeMetaDataObj[nodeIdHashed].CodeLinesObj.Count();
705706
codePanelData.NodeMetaDataObj[nodeIdHashed].CodeLinesObj.Add(rowData);
706707
}
707708
else
708709
{
709710
codePanelData.NodeMetaDataObj.TryAdd(nodeIdHashed, new CodePanelNodeMetaData());
711+
rowData.RowPositionInGroup = codePanelData.NodeMetaDataObj[nodeIdHashed].CodeLinesObj.Count();
710712
codePanelData.NodeMetaDataObj[nodeIdHashed].CodeLinesObj.Add(rowData);
711713
}
712714
}
713715

714716
if (commentsForRow != null && commentsForRow.Type == CodePanelRowDatatype.CommentThread && commentsForRow.CommentsObj.Any())
715717
{
718+
commentsForRow.AssociatedRowPositionInGroup = rowData.RowPositionInGroup;
716719
if (codePanelData.NodeMetaDataObj.ContainsKey(nodeIdHashed))
717720
{
718-
codePanelData.NodeMetaDataObj[nodeIdHashed].CommentThreadObj.Add(commentsForRow);
721+
codePanelData.NodeMetaDataObj[nodeIdHashed].CommentThreadObj.Add(codePanelData.NodeMetaDataObj[nodeIdHashed].CodeLinesObj.Count() - 1, commentsForRow); //Map comment to the index of associated codeLine
719722
}
720723
else
721724
{
722725
codePanelData.NodeMetaDataObj.TryAdd(nodeIdHashed, new CodePanelNodeMetaData());
723-
codePanelData.NodeMetaDataObj[nodeIdHashed].CommentThreadObj.Add(commentsForRow);
726+
codePanelData.NodeMetaDataObj[nodeIdHashed].CommentThreadObj.Add(codePanelData.NodeMetaDataObj[nodeIdHashed].CodeLinesObj.Count() - 1, commentsForRow); //Map comment to the index of associated codeLine
724727
}
725728
}
726729
}

src/dotnet/APIView/APIViewWeb/Helpers/LanguageServiceHelpers.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public static bool UseLineBreakForParameterSeparator(string language)
5252
{
5353
case "Python":
5454
return true;
55+
case "C#":
56+
return true;
5557
default:
5658
return false;
5759
}

src/dotnet/APIView/APIViewWeb/Languages/CSharpLanguageService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@
66
using System.IO;
77
using System.Text.RegularExpressions;
88
using ApiView;
9+
using Microsoft.ApplicationInsights;
10+
using Microsoft.Extensions.Configuration;
911

1012
namespace APIViewWeb
1113
{
1214
public class CSharpLanguageService : LanguageProcessor
1315
{
16+
private readonly string _csharpParserToolPath;
1417
private static Regex _packageNameParser = new Regex("([A-Za-z.]*[a-z]).([\\S]*)", RegexOptions.Compiled);
1518
public override string Name { get; } = "C#";
1619
public override string[] Extensions { get; } = { ".dll" };
17-
public override string ProcessName { get; } = $"{Environment.GetEnvironmentVariable("USERPROFILE")}\\.dotnet\\tools\\CSharpAPIParserForAPIView";
20+
public override string ProcessName => _csharpParserToolPath;
1821
public override string VersionString { get; } = "27";
1922

23+
public CSharpLanguageService(IConfiguration configuration, TelemetryClient telemetryClient)
24+
{
25+
_csharpParserToolPath = configuration["CSHARPPARSEREXECUTABLEPATH"];
26+
}
27+
2028
public override string GetProcessorArguments(string originalName, string tempDirectory, string jsonPath)
2129
{
2230
var outputFileName = Path.GetFileName(jsonPath).Replace(".json.tgz", "");

src/dotnet/APIView/APIViewWeb/LeanModels/ReviewRevisionPageModels.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public class CodePanelRowData
7878
public List<StructuredToken> RowOfTokens => RowOfTokensObj.Count > 0 ? RowOfTokensObj : null;
7979
public string NodeId { get; set; }
8080
public string NodeIdHashed { get; set; }
81+
public int RowPositionInGroup { get; set; } // The position / index of the row within the group of similar rows
82+
public int AssociatedRowPositionInGroup { get; set; } // For comment threads, this is the position of the associated code line within the group of similar rows
8183
public RowOfTokensPosition RowOfTokensPosition { get; set; }
8284
[JsonIgnore]
8385
public HashSet<string> RowClassesObj { get; set; } = new HashSet<string>();
@@ -107,8 +109,8 @@ public class CodePanelNodeMetaData
107109
public List<CodePanelRowData> CodeLinesObj { get; set; } = new List<CodePanelRowData>();
108110
public List<CodePanelRowData> CodeLines => CodeLinesObj.Count > 0 ? CodeLinesObj : null;
109111
[JsonIgnore]
110-
public List<CodePanelRowData> CommentThreadObj { get; set; } = new List<CodePanelRowData>();
111-
public List<CodePanelRowData> CommentThread => CommentThreadObj.Count > 0 ? CommentThreadObj : null;
112+
public Dictionary<int, CodePanelRowData> CommentThreadObj { get; set; } = new Dictionary<int, CodePanelRowData>(); //Dictionary key map to the index of the code line within this node which the comment thread is mapped to
113+
public Dictionary<int, CodePanelRowData> CommentThread => CommentThreadObj.Count > 0 ? CommentThreadObj : null;
112114
public NavigationTreeNode NavigationTreeNode { get; set; }
113115
public string ParentNodeIdHashed { get; set; }
114116
[JsonIgnore]

src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<span class="visually-hidden">Loading...</span>
44
</div>
55
<div *ngIf="codePanelRowSource" class="viewport {{languageSafeName!}}" (click)="onCodePanelItemClick($event)">
6-
<div *uiScroll="let item of codePanelRowSource; let index = index" class="code-line" [attr.data-node-id]="item.nodeIdHashed" [ngClass]="getRowClassObject(item)">
6+
<div *uiScroll="let item of codePanelRowSource; let index = index" class="code-line" [attr.data-node-id]="item.nodeIdHashed"
7+
[attr.data-row-position-in-group]="item.rowPositionInGroup" [ngClass]="getRowClassObject(item)">
78
<ng-container *ngIf="item.type === CodePanelRowDatatype.CodeLine || item.type === CodePanelRowDatatype.Documentation">
89
<div class="line-actions">
910
<span *ngIf="showLineNumbers" class="line-number first">{{item.lineNumber}}</span>

0 commit comments

Comments
 (0)