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

Reloadable types - IDE #54960

Merged
merged 3 commits into from
Jul 21, 2021
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 @@ -63,6 +63,87 @@ static void Goo(int a)
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Goo(2);"));
}

[Fact]
public void Update_Inner_NewCommentAtEndOfActiveStatement()
{
var src1 = @"
class C
{
static void Main(string[] args)
{
<AS:1>Goo(1);</AS:1>
}

static void Goo(int a)
{
<AS:0>Console.WriteLine(a);</AS:0>
}
}";
var src2 = @"
class C
{
static void Main(string[] args)
{
<AS:1>Goo(1);</AS:1>//
}

static void Goo(int a)
{
<AS:0>Console.WriteLine(a);</AS:0>
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active);
}

/// <summary>
/// CreateNewOnMetadataUpdate has no effect in presence of active statements (in break mode).
/// </summary>
[Fact]
public void Update_Inner_Reloadable()
{
var src1 = ReloadableAttributeSrc + @"
[CreateNewOnMetadataUpdate]
class C
{
static void Main()
{
<AS:1>Goo(1);</AS:1>
}

static void Goo(int a)
{
<AS:0>Console.WriteLine(a);</AS:0>
}
}";
var src2 = ReloadableAttributeSrc + @"
[CreateNewOnMetadataUpdate]
class C
{
static void Main()
{
while (true)
{
<AS:1>Goo(2);</AS:1>
}
}

static void Goo(int a)
{
<AS:0>Console.WriteLine(a);</AS:0>
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Goo(2);"));
}

[Fact]
public void Update_Leaf()
{
Expand Down Expand Up @@ -138,10 +219,14 @@ static void Goo(int a)
edits.VerifyRudeDiagnostics(active);
}

/// <summary>
/// CreateNewOnMetadataUpdate has no effect in presence of active statements (in break mode).
/// </summary>
[Fact]
public void Update_Inner_NewCommentAtEndOfActiveStatement()
public void Update_Leaf_Reloadable()
{
var src1 = @"
var src1 = ReloadableAttributeSrc + @"
[CreateNewOnMetadataUpdate]
class C
{
static void Main(string[] args)
Expand All @@ -154,24 +239,33 @@ static void Goo(int a)
<AS:0>Console.WriteLine(a);</AS:0>
}
}";
var src2 = @"
var src2 = ReloadableAttributeSrc + @"
[CreateNewOnMetadataUpdate]
class C
{
static void Main(string[] args)
{
<AS:1>Goo(1);</AS:1>//
while (true)
{
<AS:1>Goo(1);</AS:1>
}
}

static void Goo(int a)
{
<AS:0>Console.WriteLine(a);</AS:0>
<AS:0>Console.WriteLine(a + 1);</AS:0>
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active);
edits.VerifySemantics(active,
expectedSemanticEdits: new[]
{
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.Main"), preserveLocalVariables: true),
SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.Goo"), preserveLocalVariables: true)
});
}

[WorkItem(846588, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/846588")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ namespace Microsoft.CodeAnalysis.CSharp.EditAndContinue.UnitTests
{
public abstract class EditingTestBase : CSharpTestBase
{
public static readonly string ReloadableAttributeSrc = @"
using System.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices { class CreateNewOnMetadataUpdateAttribute : Attribute {} }
";

internal static CSharpEditAndContinueAnalyzer CreateAnalyzer()
{
return new CSharpEditAndContinueAnalyzer(testFaultInjector: null);
Expand Down
51 changes: 51 additions & 0 deletions src/EditorFeatures/CSharpTest/EditAndContinue/LineEditTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,32 @@ class C
new SourceLineUpdate[] { new SourceLineUpdate(3, 4) });
}

[Fact]
public void Field_LineChange_Reloadable()
{
var src1 = ReloadableAttributeSrc + @"
[CreateNewOnMetadataUpdate]
class C
{
int Goo = 1, Bar = 2;
}
";
var src2 = ReloadableAttributeSrc + @"
[CreateNewOnMetadataUpdate]
class C
{
int Goo = 1,
Bar = 2;
}";
var edits = GetTopEdits(src1, src2);
edits.VerifyLineEdits(
Array.Empty<SequencePointUpdates>(),
semanticEdits: new[]
{
SemanticEdit(SemanticEditKind.Replace, c => c.GetMember("C"))
});
}

[Fact]
public void Field_Recompile1a()
{
Expand Down Expand Up @@ -1178,6 +1204,31 @@ class C<T>
});
}

[Fact]
public void Field_Generic_Reloadable()
{
var src1 = ReloadableAttributeSrc + @"
[CreateNewOnMetadataUpdate]
class C<T>
{
static int Goo = 1 + 1;
}
";
var src2 = ReloadableAttributeSrc + @"
[CreateNewOnMetadataUpdate]
class C<T>
{
static int Goo = 1 + 1;
}";
var edits = GetTopEdits(src1, src2);
edits.VerifyLineEdits(
Array.Empty<SequencePointUpdates>(),
semanticEdits: new[]
{
SemanticEdit(SemanticEditKind.Replace, c => c.GetMember("C"))
});
}

#endregion

#region Properties
Expand Down
Loading