Skip to content

Commit

Permalink
Runtime capability to allow attribute editing (#52986)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier authored Jun 8, 2021
1 parent 4c0d708 commit 88bb074
Show file tree
Hide file tree
Showing 30 changed files with 1,502 additions and 445 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CSharpEditAndContinueAnalyzerTests

#region Helpers

private static void TestSpans(string source, Func<SyntaxKind, bool> hasLabel)
private static void TestSpans(string source, Func<SyntaxNode, bool> hasLabel)
{
var tree = SyntaxFactory.ParseSyntaxTree(source);

Expand All @@ -41,7 +41,7 @@ private static void TestSpans(string source, Func<SyntaxKind, bool> hasLabel)
var expectedText = source.Substring(expected.Start, expected.Length);
var token = tree.GetRoot().FindToken(expected.Start);
var node = token.Parent;
while (!hasLabel(node.Kind()))
while (!hasLabel(node))
{
node = node.Parent;
}
Expand Down Expand Up @@ -146,8 +146,7 @@ public void ErrorSpans_TopLevel()
/*<span>*/delegate C<T> D2()/*</span>*/;
[/*<span>*/Attrib/*</span>*/]
/*<span>*/[Attrib]/*</span>*/
[Attrib]
/*<span>*/public class Z/*</span>*/
{
/*<span>*/int f/*</span>*/;
Expand Down Expand Up @@ -181,7 +180,7 @@ public void ErrorSpans_TopLevel()
}
";
TestSpans(source, kind => SyntaxComparer.TopLevel.HasLabel(kind));
TestSpans(source, node => SyntaxComparer.TopLevel.HasLabel(node));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7201,12 +7201,11 @@ public void LocalFunction_AddAttribute()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Insert [[A]]@2",
"Insert [A]@3");
"Update [void L() { }]@2 -> [[A]void L() { }]@2");

// Get top edits so we can validate rude edits
GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Insert, "[A]", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "L", FeaturesResources.local_function));
}

[Fact]
Expand All @@ -7218,12 +7217,11 @@ public void LocalFunction_RemoveAttribute()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Delete [[A]]@2",
"Delete [A]@3");
"Update [[A]void L() { }]@2 -> [void L() { }]@2");

// Get top edits so we can validate rude edits
GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Delete, "L", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "L", FeaturesResources.local_function));
}

[Fact]
Expand All @@ -7234,7 +7232,7 @@ public void LocalFunction_ReorderAttribute()

var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits("Reorder [B]@6 -> @3");
edits.VerifyEdits("Update [[A, B]void L() { }]@2 -> [[B, A]void L() { }]@2");

// Get top edits so we can validate rude edits
GetTopEdits(edits).VerifyRudeDiagnostics();
Expand All @@ -7249,15 +7247,9 @@ public void LocalFunction_CombineAttributeLists()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Update [[A]]@2 -> [[A, B]]@2",
"Insert [B]@6",
"Delete [[B]]@5",
"Delete [B]@6");
"Update [[A][B]void L() { }]@2 -> [[A, B]void L() { }]@2");

// Get top edits so we can validate rude edits
GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Insert, "B", FeaturesResources.attribute),
Diagnostic(RudeEditKind.Delete, "L", FeaturesResources.attribute));
GetTopEdits(edits).VerifyRudeDiagnostics();
}

[Fact]
Expand All @@ -7269,13 +7261,9 @@ public void LocalFunction_SplitAttributeLists()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Update [[A, B]]@2 -> [[A]]@2",
"Insert [[B]]@5",
"Insert [B]@6",
"Delete [B]@6");
"Update [[A, B]void L() { }]@2 -> [[A][B]void L() { }]@2");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Insert, "[B]", FeaturesResources.attribute));
GetTopEdits(edits).VerifyRudeDiagnostics();
}

[Fact]
Expand All @@ -7286,10 +7274,11 @@ public void LocalFunction_ChangeAttributeListTarget1()

var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits("Update [[return: A]]@2 -> [[A]]@2");
edits.VerifyEdits("Update [[return: A]void L() { }]@2 -> [[A]void L() { }]@2");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Update, "[A]", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "L", FeaturesResources.local_function),
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "L", FeaturesResources.local_function));
}

[Fact]
Expand All @@ -7300,10 +7289,11 @@ public void LocalFunction_ChangeAttributeListTarget2()

var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits("Update [[A]]@2 -> [[return: A]]@2");
edits.VerifyEdits("Update [[A]void L() { }]@2 -> [[return: A]void L() { }]@2");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Update, "return:", CSharpFeaturesResources.attribute_target));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "L", FeaturesResources.local_function),
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "L", FeaturesResources.local_function));
}

[Fact]
Expand All @@ -7315,11 +7305,10 @@ public void LocalFunction_ReturnType_AddAttribute()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Insert [[return: A]]@2",
"Insert [A]@11");
"Update [int L() { return 1; }]@2 -> [[return: A]int L() { return 1; }]@2");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Insert, "[return: A]", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "L", FeaturesResources.local_function));
}

[Fact]
Expand All @@ -7331,11 +7320,10 @@ public void LocalFunction_ReturnType_RemoveAttribute()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Delete [[return: A]]@2",
"Delete [A]@11");
"Update [[return: A]int L() { return 1; }]@2 -> [int L() { return 1; }]@2");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Delete, "L", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "L", FeaturesResources.local_function));
}

[Fact]
Expand All @@ -7346,7 +7334,7 @@ public void LocalFunction_ReturnType_ReorderAttribute()

var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits("Reorder [B]@14 -> @11");
edits.VerifyEdits("Update [[return: A, B]int L() { return 1; }]@2 -> [[return: B, A]int L() { return 1; }]@2");

GetTopEdits(edits).VerifyRudeDiagnostics();
}
Expand All @@ -7360,11 +7348,10 @@ public void LocalFunction_Parameter_AddAttribute()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Insert [[A]]@9",
"Insert [A]@10");
"Update [int i]@9 -> [[A]int i]@9");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Insert, "[A]", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "int i", FeaturesResources.parameter));
}

[Fact]
Expand All @@ -7376,11 +7363,10 @@ public void LocalFunction_Parameter_RemoveAttribute()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Delete [[A]]@9",
"Delete [A]@10");
"Update [[A]int i]@9 -> [int i]@9");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Delete, "int i", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "int i", FeaturesResources.parameter));
}

[Fact]
Expand All @@ -7391,7 +7377,7 @@ public void LocalFunction_Parameter_ReorderAttribute()

var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits("Reorder [B]@13 -> @10");
edits.VerifyEdits("Update [[A, B]int i]@9 -> [[B, A]int i]@9");

GetTopEdits(edits).VerifyRudeDiagnostics();
}
Expand All @@ -7405,11 +7391,10 @@ public void LocalFunction_TypeParameter_AddAttribute()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Insert [[A]]@9",
"Insert [A]@10");
"Update [T]@9 -> [[A] T]@9");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Insert, "[A]", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "T", FeaturesResources.type_parameter));
}

[Fact]
Expand All @@ -7421,11 +7406,10 @@ public void LocalFunction_TypeParameter_RemoveAttribute()
var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits(
"Delete [[A]]@9",
"Delete [A]@10");
"Update [[A] T]@9 -> [T]@9");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Delete, "T", FeaturesResources.attribute));
Diagnostic(RudeEditKind.ChangingAttributesNotSupportedByRuntime, "T", FeaturesResources.type_parameter));
}

[Fact]
Expand All @@ -7436,7 +7420,7 @@ public void LocalFunction_TypeParameter_ReorderAttribute()

var edits = GetMethodEdits(src1, src2);

edits.VerifyEdits("Reorder [B]@13 -> @10");
edits.VerifyEdits("Update [[A, B] T]@9 -> [[B, A] T]@9");

GetTopEdits(edits).VerifyRudeDiagnostics();
}
Expand Down
Loading

0 comments on commit 88bb074

Please sign in to comment.