Skip to content

Commit

Permalink
Implement SkipDiff (#8666)
Browse files Browse the repository at this point in the history
* Implement SkippDiff

* Skip Docs when comparing APIRevisions
  • Loading branch information
chidozieononiwu authored Jul 23, 2024
1 parent 4f440fb commit 60925ca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
36 changes: 26 additions & 10 deletions src/dotnet/APIView/APIViewWeb/Helpers/CodeFileHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ private static void BuildTokensForDiffNodes(CodePanelData codePanelData, CodePan
{
var token = beforeTokens[beforeIndex++];

if (codePanelRawData.ApplySkipDiff && token.TagsObj.Contains(StructuredToken.SKIPP_DIFF))
{
continue;
}

if (token.Kind == StructuredTokenKind.LineBreak)
{
break;
Expand All @@ -416,19 +421,27 @@ private static void BuildTokensForDiffNodes(CodePanelData codePanelData, CodePan

if (beforeTokenRow.Count > 0)
{
beforeTokensInProcess.Enqueue(new DiffLineInProcess()
if (!(codePanelRawData.SkipDocsWhenDiffing && beforeRowGroupId == StructuredToken.DOCUMENTATION))
{
GroupId = beforeRowGroupId,
RowOfTokens = beforeTokenRow,
TokenIdsInRow = new HashSet<string>(beforeTokenIdsInRow)
});
beforeTokensInProcess.Enqueue(new DiffLineInProcess()
{
GroupId = beforeRowGroupId,
RowOfTokens = beforeTokenRow,
TokenIdsInRow = new HashSet<string>(beforeTokenIdsInRow)
});
}
beforeTokenIdsInRow.Clear();
}

while (afterIndex < afterTokens.Count)
{
var token = afterTokens[afterIndex++];

if (codePanelRawData.ApplySkipDiff && token.TagsObj.Contains(StructuredToken.SKIPP_DIFF))
{
continue;
}

if (token.Kind == StructuredTokenKind.LineBreak)
{
break;
Expand All @@ -451,12 +464,15 @@ private static void BuildTokensForDiffNodes(CodePanelData codePanelData, CodePan

if (afterTokenRow.Count > 0)
{
afterTokensInProcess.Enqueue(new DiffLineInProcess()
if (!(codePanelRawData.SkipDocsWhenDiffing && afterRowGroupId == StructuredToken.DOCUMENTATION))
{
GroupId = afterRowGroupId,
RowOfTokens = afterTokenRow,
TokenIdsInRow = new HashSet<string>(afterTokenIdsInRow)
});
afterTokensInProcess.Enqueue(new DiffLineInProcess()
{
GroupId = afterRowGroupId,
RowOfTokens = afterTokenRow,
TokenIdsInRow = new HashSet<string>(afterTokenIdsInRow)
});
}
afterTokenIdsInRow.Clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class CodePanelRawData
public List<APITreeNode> APIForest { get; set; } = new List<APITreeNode>();
public CodeDiagnostic[] Diagnostics { get; set; } = new CodeDiagnostic[0];
public string Language { get; set; }
public bool ApplySkipDiff { get; set; }
public bool SkipDocsWhenDiffing { get; set; }
}

public class CodePanelRowData
Expand Down
7 changes: 4 additions & 3 deletions src/dotnet/APIView/APIViewWeb/Managers/CodeFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using APIViewWeb.Managers.Interfaces;
using APIViewWeb.Models;
using APIViewWeb.Repositories;
using Microsoft.CodeAnalysis.Host;

namespace APIViewWeb.Managers
{
Expand Down Expand Up @@ -208,11 +207,13 @@ public async Task<bool> AreAPICodeFilesTheSame(RenderedCodeFile codeFileA, Rende

if (LanguageServiceHelpers.UseTreeStyleParser(codeFileA.CodeFile.Language))
{
var diffTree =CodeFileHelpers.ComputeAPIForestDiff(codeFileA.CodeFile.APIForest, codeFileB.CodeFile.APIForest);
var diffTree = CodeFileHelpers.ComputeAPIForestDiff(codeFileA.CodeFile.APIForest, codeFileB.CodeFile.APIForest);
var codePanelRawData = new CodePanelRawData()
{
APIForest = diffTree,
Language = codeFileA.CodeFile.Language
Language = codeFileA.CodeFile.Language,
SkipDocsWhenDiffing = true,
ApplySkipDiff = true
};
var result = await CodeFileHelpers.GenerateCodePanelDataAsync(codePanelRawData);
return !result.HasDiff;
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/APIView/apiview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
default: 'https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json'
- name: CSharpAPIParserVersion
type: string
default: '1.0.0-dev.20240716.16'
default: '1.0.0-dev.20240719.1'

trigger:
branches:
Expand Down

0 comments on commit 60925ca

Please sign in to comment.