Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EnC] Support more symbol deletes #62151

Merged
merged 6 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,13 @@ public void Property_BlockBodyToExpressionBody2()
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifySemanticDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "int P", DeletedSymbolDisplay(CSharpFeaturesResources.property_setter, "P.set")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_P")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down Expand Up @@ -688,8 +693,13 @@ public void Indexer_BlockBodyToExpressionBody2()
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifySemanticDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "int this[int a]", DeletedSymbolDisplay(CSharpFeaturesResources.indexer_setter, "this[int a].set")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_Item")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_Item"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2442,8 +2442,14 @@ class C
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifySemanticDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "class C", DeletedSymbolDisplay(FeaturesResources.auto_property, "a")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Insert, c => c.GetMember("C.a")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.get_a"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C..ctor"), preserveLocalVariables: true),
},
capabilities: EditAndContinueCapabilities.AddInstanceFieldToExistingType);
}

#endregion
Expand Down
224 changes: 191 additions & 33 deletions src/EditorFeatures/CSharpTest/EditAndContinue/TopLevelEditingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3233,8 +3233,13 @@ public void Record_DeleteProperty_NotPrimary()

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "record C", DeletedSymbolDisplay(FeaturesResources.auto_property, "P")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.get_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down Expand Up @@ -3627,8 +3632,13 @@ record C(int X)

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "record C", DeletedSymbolDisplay(FeaturesResources.auto_property, "Y")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.get_Y"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_Y"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down Expand Up @@ -9037,9 +9047,13 @@ class C
}";
var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "class C", DeletedSymbolDisplay(CSharpFeaturesResources.conversion_operator, "implicit operator bool(C c)")),
Diagnostic(RudeEditKind.Delete, "class C", DeletedSymbolDisplay(FeaturesResources.operator_, "operator +(C c, C d)")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.op_Implicit"), deletedSymbolContainerProvider: c => c.GetMember("C")),
davidwengier marked this conversation as resolved.
Show resolved Hide resolved
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.op_Addition"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down Expand Up @@ -9255,6 +9269,19 @@ public void Operator_ReadOnlyRef_Parameter_Update()
Diagnostic(RudeEditKind.ModifiersUpdate, "in Test b", FeaturesResources.parameter));
}

[Fact]
public void Operator_Delete()
{
var src1 = "class C { public static bool operator !(C b) => true; }";
var src2 = "class C { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemantics(
new[] { SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.op_LogicalNot"), deletedSymbolContainerProvider: c => c.GetMember("C")) },
capabilities: EditAndContinueCapabilities.Baseline);
}

#endregion

#region Constructor, Destructor
Expand Down Expand Up @@ -9470,6 +9497,19 @@ public void ConstructorUpdate_AnonymousTypeInFieldInitializer()
edits.VerifySemanticDiagnostics();
}

[Fact]
public void Constructor_Delete()
{
var src1 = "class C { public C(int x) { } }";
var src2 = "class C { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemantics(
new[] { SemanticEdit(SemanticEditKind.Delete, c => c.GetMember<INamedTypeSymbol>("C").InstanceConstructors.FirstOrDefault(c => c.Parameters.Length == 1), deletedSymbolContainerProvider: c => c.GetMember("C")) },
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
public void Constructor_Static_Delete()
{
Expand Down Expand Up @@ -13448,8 +13488,13 @@ public void Property_BlockBodyToExpressionBody2()
"Delete [get { return 2; }]@18",
"Delete [set { }]@36");

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "int P", DeletedSymbolDisplay(CSharpFeaturesResources.property_setter, "P.set")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_P"), preserveLocalVariables: false),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact, WorkItem(17681, "https://github.com/dotnet/roslyn/issues/17681")]
Expand Down Expand Up @@ -13626,13 +13671,50 @@ public void Property_RenameAndUpdate()
[Fact]
public void PropertyDelete()
{
var src1 = "class C { int P { get { return 1; } } }";
var src1 = "class C { int P { get { return 1; } set { } } }";
davidwengier marked this conversation as resolved.
Show resolved Hide resolved
var src2 = "class C { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "class C", DeletedSymbolDisplay(FeaturesResources.property_, "P")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.get_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
public void PropertyAccessorDelete1()
{
var src1 = "class C { int P { get { return 1; } set { } } }";
var src2 = "class C { int P { get { return 1; } } }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C"))
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
public void PropertyAccessorDelete2()
{
var src1 = "class C { int P { set { } get { return 1; } } }";
var src2 = "class C { int P { set { } } }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.get_P"), deletedSymbolContainerProvider: c => c.GetMember("C"))
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down Expand Up @@ -13948,8 +14030,12 @@ public void PrivatePropertyAccessorDelete()

edits.VerifyEdits("Delete [set { _p = value; }]@44");

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "int P", DeletedSymbolDisplay(CSharpFeaturesResources.property_setter, "P.set")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down Expand Up @@ -14047,8 +14133,12 @@ public void PrivateAutoPropertyAccessorDelete_Get()

edits.VerifyEdits("Delete [get;]@18");

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "int P", DeletedSymbolDisplay(CSharpFeaturesResources.property_getter, "P.get")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.get_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down Expand Up @@ -14093,8 +14183,13 @@ public void PrivateAutoPropertyAccessorDelete_Set()

edits.VerifyEdits("Delete [set;]@23");

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "int P", DeletedSymbolDisplay(CSharpFeaturesResources.property_setter, "P.set")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C..ctor"), preserveLocalVariables: true),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand All @@ -14107,8 +14202,13 @@ public void PrivateAutoPropertyAccessorDelete_Init()

edits.VerifyEdits("Delete [init;]@23");

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "int P", DeletedSymbolDisplay(CSharpFeaturesResources.property_setter, "P.init")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_P"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C..ctor"), preserveLocalVariables: true),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down Expand Up @@ -14774,8 +14874,13 @@ public void Indexer_GetterAndSetterBlockBodiesToExpressionBody()
"Delete [get { return 1; }]@28",
"Delete [set { Console.WriteLine(0); }]@46");

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "int this[int a]", DeletedSymbolDisplay(CSharpFeaturesResources.indexer_setter, "this[int a].set")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.get_Item")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_Item"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact, WorkItem(17681, "https://github.com/dotnet/roslyn/issues/17681")]
Expand Down Expand Up @@ -15005,6 +15110,33 @@ class C<T>
Diagnostic(RudeEditKind.InsertIntoGenericType, "set", CSharpFeaturesResources.indexer_setter));
}

[Fact]
public void Indexer_Delete()
{
var src1 = @"
class C<T>
{
public T this[int i]
{
get { return arr[i]; }
set { arr[i] = value; }
}
}";
var src2 = @"
class C<T>
{
}";
var edits = GetTopEdits(src1, src2);

edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.get_Item"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_Item"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[WorkItem(750109, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/750109")]
[Fact]
public void Indexer_DeleteGetAccessor()
Expand All @@ -15028,10 +15160,12 @@ public T this[int i]
}";
var edits = GetTopEdits(src1, src2);

edits.VerifyEdits("Delete [get { return arr[i]; }]@58");

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "public T this[int i]", DeletedSymbolDisplay(CSharpFeaturesResources.indexer_getter, "this[int i].get")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.get_Item"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand All @@ -15049,10 +15183,12 @@ class C
}";
var edits = GetTopEdits(src1, src2);

edits.VerifyEdits("Delete [set { }]@61");

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "public int this[int i]", DeletedSymbolDisplay(CSharpFeaturesResources.indexer_setter, "this[int i].set")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.set_Item"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact, WorkItem(1174850, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1174850")]
Expand Down Expand Up @@ -15403,15 +15539,37 @@ public void Event_Insert()
}

[Fact]
public void Event_Delete()
public void Event_Delete1()
{
var src1 = "class C { event int E { remove { } add { } } }";
var src2 = "class C { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Delete, "class C", DeletedSymbolDisplay(FeaturesResources.event_, "E")));
edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.add_E"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.remove_E"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
public void Event_Delete2()
{
var src1 = "class C { event int E; }";
var src2 = "class C { }";

var edits = GetTopEdits(src1, src2);

edits.VerifySemantics(
new[]
{
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.add_E"), deletedSymbolContainerProvider: c => c.GetMember("C")),
SemanticEdit(SemanticEditKind.Delete, c => c.GetMember("C.remove_E"), deletedSymbolContainerProvider: c => c.GetMember("C")),
},
capabilities: EditAndContinueCapabilities.Baseline);
}

[Fact]
Expand Down
Loading