Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void TestDiffClassChangedToStruct()
Assert.Equal("struct", changes[0].NewText);
}

[Fact(Skip = "https://github.com/dotnet/roslyn/issues/320")]
[Fact]
public void TestQualifyWithThis()
{
var original = @"
Expand Down
46 changes: 37 additions & 9 deletions src/Compilers/Core/Portable/Syntax/SyntaxDiffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,16 @@ private DiffAction GetNextAction()

if (indexOfOldInNew > 0)
{
return new DiffAction(DiffOp.InsertNew, indexOfOldInNew);
// look ahead to see if the old node also appears again later in its own list
var oldHasIdenticalSibling = FindExactMatch(_oldNodes, _oldNodes.Peek(), 1) >= 1;

if (!oldHasIdenticalSibling)
{
return new DiffAction(DiffOp.InsertNew, indexOfOldInNew);
}
}
else if (!newIsToken)

if (!newIsToken)
{
if (AreSimilar(_oldNodes.Peek(), _newNodes.Peek()))
{
Expand Down Expand Up @@ -324,20 +331,41 @@ private static void ReplaceFirstWithChildren(Stack<SyntaxNodeOrToken> stack)
}
}

private int FindExactMatch(Stack<SyntaxNodeOrToken> stack, SyntaxNodeOrToken node, int startIndex)
{
int i = 0;
foreach (var stackNode in stack)
{
if (i >= MaxSearchLength)
{
break;
}

if (i >= startIndex && AreIdentical(stackNode, node))
{
return i;
}

i++;
}

return -1;
}

private void FindBestMatch(Stack<SyntaxNodeOrToken> stack, SyntaxNodeOrToken node, out int index, out int similarity)
{
index = -1;
similarity = -1;

int i = 0;
foreach (var listNode in stack)
foreach (var stackNode in stack)
{
if (i >= MaxSearchLength)
{
break;
}

if (AreIdentical(listNode, node))
if (AreIdentical(stackNode, node))
{
var sim = node.FullSpan.Length;
if (sim > similarity)
Expand All @@ -347,15 +375,15 @@ private void FindBestMatch(Stack<SyntaxNodeOrToken> stack, SyntaxNodeOrToken nod
return;
}
}
else if (AreSimilar(listNode, node))
else if (AreSimilar(stackNode, node))
{
var sim = GetSimilarity(listNode, node);
var sim = GetSimilarity(stackNode, node);

// Are these really the same? This may be expensive so only check this if
// similarity is rated equal to them being identical.
if (sim == node.FullSpan.Length && node.IsToken)
{
if (listNode.ToFullString() == node.ToFullString())
if (stackNode.ToFullString() == node.ToFullString())
{
index = i;
similarity = sim;
Expand All @@ -373,7 +401,7 @@ private void FindBestMatch(Stack<SyntaxNodeOrToken> stack, SyntaxNodeOrToken nod
{
// check one level deep inside list node's children
int j = 0;
foreach (var child in listNode.ChildNodesAndTokens())
foreach (var child in stackNode.ChildNodesAndTokens())
{
if (j >= MaxSearchLength)
{
Expand Down Expand Up @@ -716,7 +744,7 @@ private static void GetCommonEdgeLengths(StringBuilder oldText, StringBuilder ne
}
}

// don't double count the chars we matches at the start of the strings
// don't double count the chars we matched at the start of the strings
maxChars = maxChars - commonLeadingCount;

commonTrailingCount = 0;
Expand Down