Skip to content

Commit

Permalink
Interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Sep 26, 2024
1 parent 0af607b commit 2f3bb9e
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 49 deletions.
98 changes: 91 additions & 7 deletions src/Features/CSharpTest/EditAndContinue/TopLevelEditingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8412,17 +8412,103 @@ class C
}

[Fact]
public void MethodReorder1()
public void Method_Reorder()
{
var src1 = "class C { void f(int a, int b) { a = b; } void g() { } }";
var src2 = "class C { void g() { } void f(int a, int b) { a = b; } }";
var src1 = """
class C
{

void F() {}
void G() {}
void H() {}
}
""";

var src2 = """
class C
{
void H() {}
void F() {}
void G() {}

}
""";

var edits = GetTopEdits(src1, src2);

edits.VerifyEdits(EditKind.Reorder);

edits.VerifySemantics([SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.H"))]);
}

[Theory]
[CombinatorialData]
public void Method_Reorder_Interface(bool isStatic)
{
var (modifier, body) = isStatic ? ("static", ";") : ("", " {}");

var src1 = $$"""
interface I
{
{{modifier}} void F(){{body}}
{{modifier}} void G(){{body}}
{{modifier}} void H(){{body}}
}
""";

var src2 = $$"""
interface I
{
{{modifier}} void H(){{body}}
{{modifier}} void F(){{body}}
{{modifier}} void G(){{body}}
}
""";

var edits = GetTopEdits(src1, src2);

edits.VerifyEdits(EditKind.Reorder);

edits.VerifySemantics([SemanticEdit(SemanticEditKind.Update, c => c.GetMember("I.H"))]);
}

[Theory]
[InlineData("static extern ")] // static method must be extern in COM interface
[InlineData("")]
public void Method_Reorder_Interface_ComImport(string modifier)
{
var src1 = $$"""
[System.Runtime.InteropServices.ComImport]
[Guid("DBE8A85B-7883-4657-83FD-1FA27A9561EB")]
interface I
{
{{modifier}}void F();
{{modifier}}void G();
{{modifier}}void H();
}
""";

var src2 = $$"""
[System.Runtime.InteropServices.ComImport]
[Guid("DBE8A85B-7883-4657-83FD-1FA27A9561EB")]
interface I
{
{{modifier}}void H();
{{modifier}}void F();
{{modifier}}void G();
}
""";

var edits = GetTopEdits(src1, src2);
edits.VerifyEdits("Reorder [void g() { }]@42 -> @10");

edits.VerifyEdits(EditKind.Reorder);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.InsertIntoComInterface, modifier + "void H()", GetResource("method")));
}

[Fact]
public void MethodInsertDelete1()
public void Method_InsertDelete()
{
var src1 = "class C { class D { } void f(int a, int b) { a = b; } }";
var src2 = "class C { class D { void f(int a, int b) { a = b; } } }";
Expand Down Expand Up @@ -16779,8 +16865,6 @@ struct S

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.InsertIntoStruct, "b", FeaturesResources.field, CSharpFeaturesResources.struct_),
Diagnostic(RudeEditKind.InsertIntoStruct, "c", FeaturesResources.field, CSharpFeaturesResources.struct_),
Diagnostic(RudeEditKind.InsertIntoStruct, "f = 1", FeaturesResources.field, CSharpFeaturesResources.struct_),
Diagnostic(RudeEditKind.InsertIntoStruct, "d", CSharpFeaturesResources.event_field, CSharpFeaturesResources.struct_));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5020,6 +5020,19 @@ private DiagnosticContext CreateDiagnosticContext(ArrayBuilder<RudeEditDiagnosti

internal void ReportTypeLayoutUpdateRudeEdits(in DiagnosticContext diagnosticContext, ISymbol newSymbol, CancellationToken cancellationToken)
{
// can't modify order of members in a COM interface:
if (newSymbol.ContainingType is INamedTypeSymbol { IsComImport: true })
{
diagnosticContext.Report(RudeEditKind.InsertIntoComInterface, cancellationToken, arguments: [GetDisplayKind(newSymbol)]);
return;
}

// static members do not affect type layout:
if (newSymbol.IsStatic)
{
return;
}

switch (newSymbol.Kind)
{
case SymbolKind.Field:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void AddGeneralDiagnostic(EditAndContinueErrorCode code, string resourceName, Di
AddRudeEdit(RudeEditKind.InsertDllImport, nameof(FeaturesResources.Adding_an_imported_method_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.InsertOperator, nameof(FeaturesResources.Adding_a_user_defined_0_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.InsertIntoStruct, nameof(FeaturesResources.Adding_0_into_a_1_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.InsertIntoClassWithLayout, nameof(FeaturesResources.Adding_0_into_a_class_with_explicit_or_sequential_layout_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.InsertIntoClassWithLayout, nameof(FeaturesResources.Adding_0_into_a_1_with_explicit_or_sequential_layout_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.Move, nameof(FeaturesResources.Moving_0_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.Delete, nameof(FeaturesResources.Deleting_0_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.GenericMethodUpdate, nameof(FeaturesResources.Modifying_a_generic_method_requires_restarting_the_application));
Expand Down Expand Up @@ -149,6 +149,7 @@ void AddGeneralDiagnostic(EditAndContinueErrorCode code, string resourceName, Di
AddRudeEdit(RudeEditKind.ChangingNameOrSignatureOfActiveMember, nameof(FeaturesResources.Changing_name_or_signature_of_0_that_contains_an_active_statement_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.UpdateMightNotHaveAnyEffect, nameof(FeaturesResources.Changing_0_might_not_have_any_effect_until_the_application_is_restarted), DiagnosticSeverity.Warning);
AddRudeEdit(RudeEditKind.TypeUpdateAroundActiveStatement, nameof(FeaturesResources.Updating_a_0_around_an_active_statement_requires_restarting_the_application));
AddRudeEdit(RudeEditKind.InsertIntoComInterface, nameof(FeaturesResources.Adding_0_into_a_COM_interface_requires_restarting_the_application));

// VB specific
AddRudeEdit(RudeEditKind.HandlesClauseUpdate, nameof(FeaturesResources.Updating_the_Handles_clause_of_0_requires_restarting_the_application));
Expand Down
1 change: 1 addition & 0 deletions src/Features/Core/Portable/EditAndContinue/RudeEditKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ internal enum RudeEditKind : ushort
ChangingNameOrSignatureOfActiveMember = 117,
UpdateMightNotHaveAnyEffect = 118,
TypeUpdateAroundActiveStatement = 119,
InsertIntoComInterface = 120,
}
7 changes: 5 additions & 2 deletions src/Features/Core/Portable/FeaturesResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,11 @@
<data name="Adding_0_into_an_interface_method_requires_restarting_the_application" xml:space="preserve">
<value>Adding {0} into an interface method requires restarting the application.</value>
</data>
<data name="Adding_0_into_a_class_with_explicit_or_sequential_layout_requires_restarting_the_application" xml:space="preserve">
<value>Adding {0} into a class with explicit or sequential layout requires restarting the application.</value>
<data name="Adding_0_into_a_1_with_explicit_or_sequential_layout_requires_restarting_the_application" xml:space="preserve">
<value>Adding {0} into a {1} with explicit or sequential layout requires restarting the application.</value>
</data>
<data name="Adding_0_into_a_COM_interface_requires_restarting_the_application" xml:space="preserve">
<value>Adding {0} into a COM interface requires restarting the application.</value>
</data>
<data name="Updating_the_modifiers_of_0_requires_restarting_the_application" xml:space="preserve">
<value>Updating the modifiers of {0} requires restarting the application.</value>
Expand Down
11 changes: 8 additions & 3 deletions src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Features/Core/Portable/xlf/FeaturesResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Features/Core/Portable/xlf/FeaturesResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Features/Core/Portable/xlf/FeaturesResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2f3bb9e

Please sign in to comment.