提交 044c1692 编写于 作者: T Tomas Matousek

Report rude edit when a partially executed active statement is edited

上级 6b0f3c0b
......@@ -7648,6 +7648,45 @@ static void Foo(int a)
Diagnostic(RudeEditKind.Delete, null, FeaturesResources.Class));
}
[Fact]
public void PartiallyExecutedActiveStatement()
{
string src1 = @"
class C
{
public static void F()
{
<AS:0>Console.WriteLine(1);</AS:0>
<AS:1>Console.WriteLine(2);</AS:1>
<AS:2>Console.WriteLine(3);</AS:2>
<AS:3>Console.WriteLine(4);</AS:3>
}
}";
string src2 = @"
class C
{
public static void F()
{
<AS:0>Console.WriteLine(10);</AS:0>
<AS:1>Console.WriteLine(20);</AS:1>
<AS:2>Console.WriteLine(30);</AS:2>
<AS:3>Console.WriteLine(40);</AS:3>
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
active.OldSpans[0] = new ActiveStatementSpan(ActiveStatementFlags.PartiallyExecuted | ActiveStatementFlags.LeafFrame, active.OldSpans[0].Span);
active.OldSpans[1] = new ActiveStatementSpan(ActiveStatementFlags.PartiallyExecuted, active.OldSpans[1].Span);
active.OldSpans[2] = new ActiveStatementSpan(ActiveStatementFlags.LeafFrame, active.OldSpans[2].Span);
active.OldSpans[3] = new ActiveStatementSpan(ActiveStatementFlags.None, active.OldSpans[3].Span);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.PartiallyExecutedActiveStatementUpdate, "Console.WriteLine(10);"),
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Console.WriteLine(20);"),
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Console.WriteLine(40);"));
}
#endregion
}
}
......@@ -22,6 +22,7 @@ public void ToDiagnostic()
var arg0 = new HashSet<RudeEditKind>()
{
RudeEditKind.ActiveStatementUpdate,
RudeEditKind.PartiallyExecutedActiveStatementUpdate,
RudeEditKind.DeleteActiveStatement,
RudeEditKind.UpdateExceptionHandlerOfActiveTry,
RudeEditKind.UpdateTryOrCatchWithActiveFinally,
......
......@@ -4975,8 +4975,44 @@ End Module"
Extensions.VerifyUnchangedDocument(src2, active)
End Sub
#End Region
<Fact>
Public Sub PartiallyExecutedActiveStatement()
Dim src1 As String = "
Class C
Sub F()
<AS:0>Console.WriteLine(1)</AS:0>
<AS:1>Console.WriteLine(2)</AS:1>
<AS:2>Console.WriteLine(3)</AS:2>
<AS:3>Console.WriteLine(4)</AS:3>
End Sub
End Class
"
Dim src2 As String = "
Class C
Sub F()
<AS:0>Console.WriteLine(10)</AS:0>
<AS:1>Console.WriteLine(20)</AS:1>
<AS:2>Console.WriteLine(30)</AS:2>
<AS:3>Console.WriteLine(40)</AS:3>
End Sub
End Class
"
Dim edits = GetTopEdits(src1, src2)
Dim active = GetActiveStatements(src1, src2)
active.OldSpans(0) = New ActiveStatementSpan(ActiveStatementFlags.PartiallyExecuted Or ActiveStatementFlags.LeafFrame, active.OldSpans(0).Span)
active.OldSpans(1) = New ActiveStatementSpan(ActiveStatementFlags.PartiallyExecuted, active.OldSpans(1).Span)
active.OldSpans(2) = New ActiveStatementSpan(ActiveStatementFlags.LeafFrame, active.OldSpans(2).Span)
active.OldSpans(3) = New ActiveStatementSpan(ActiveStatementFlags.None, active.OldSpans(3).Span)
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.PartiallyExecutedActiveStatementUpdate, "Console.WriteLine(10)"),
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Console.WriteLine(20)"),
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Console.WriteLine(40)"))
End Sub
End Class
End Namespace
......@@ -991,6 +991,7 @@ internal struct UpdatedMemberInfo
int ordinal = start + i;
bool hasMatching = false;
bool isLeaf = (oldActiveStatements[ordinal].Flags & ActiveStatementFlags.LeafFrame) != 0;
bool isPartiallyExecuted = (oldActiveStatements[ordinal].Flags & ActiveStatementFlags.PartiallyExecuted) != 0;
int statementPart = activeNodes[i].StatementPart;
var oldStatementSyntax = activeNodes[i].OldNode;
var oldEnclosingLambdaBody = activeNodes[i].EnclosingLambdaBodyOpt;
......@@ -1036,10 +1037,10 @@ internal struct UpdatedMemberInfo
// E.g. "const" keyword is inserted into a local variable declaration with an initializer.
newSpan = FindClosestActiveSpan(newStatementSyntax, statementPart);
if (!isLeaf && !AreEquivalentActiveStatements(oldStatementSyntax, newStatementSyntax, statementPart))
if ((!isLeaf || isPartiallyExecuted) && !AreEquivalentActiveStatements(oldStatementSyntax, newStatementSyntax, statementPart))
{
// rude edit: internal active statement changed
diagnostics.Add(new RudeEditDiagnostic(RudeEditKind.ActiveStatementUpdate, newSpan));
diagnostics.Add(new RudeEditDiagnostic(isLeaf ? RudeEditKind.PartiallyExecutedActiveStatementUpdate : RudeEditKind.ActiveStatementUpdate, newSpan));
}
// exception handling around the statement:
......
......@@ -17,6 +17,13 @@ internal enum ActiveStatementFlags
/// <summary>
/// The statement is partially executed.
/// </summary>
/// <remarks>
/// An active statement is partially executed if the thread is stopped in between two sequence points.
/// This may happen when the users steps trhough the code in disassembly window (stepping over machine instructions),
/// when the compiler emits a call to Debugger.Break (VB Stop statement), etc.
///
/// Partially executed active statement can't be edited.
/// </remarks>
PartiallyExecuted = 2,
/// <summary>
......
......@@ -75,6 +75,8 @@ internal static class RudeEditDiagnosticDescriptors
{ GetDescriptorPair(RudeEditKind.DeleteLambdaWithMultiScopeCapture, FeaturesResources.DeleteLambdaWithMultiScopeCapture) },
{ GetDescriptorPair(RudeEditKind.ActiveStatementUpdate, FeaturesResources.UpdatingAnActiveStatement) },
{ GetDescriptorPair(RudeEditKind.ActiveStatementLambdaRemoved, FeaturesResources.RemovingThatContainsActiveStatement) },
// TODO: change the error message to better explain what's going on
{ GetDescriptorPair(RudeEditKind.PartiallyExecutedActiveStatementUpdate, FeaturesResources.UpdatingAnActiveStatement) },
{ GetDescriptorPair(RudeEditKind.InsertFile, FeaturesResources.AddingANewFile) },
{ GetDescriptorPair(RudeEditKind.RUDE_EDIT_COMPLEX_QUERY_EXPRESSION, FeaturesResources.ModifyingAWhichContainsComplexQuery) },
......
......@@ -87,6 +87,7 @@ internal enum RudeEditKind : ushort
InsertHandlesClause = 70,
InsertFile = 71,
PartiallyExecutedActiveStatementUpdate = 72,
// TODO: remove values below
RUDE_EDIT_COMPLEX_QUERY_EXPRESSION = 0x103,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册