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

Move remaining member rude edit analysis to semantics #54826

Merged
merged 6 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -62,26 +62,26 @@ static void Main(string[] args)
public void Method_Body_Delete1()
{
var src1 = "class C { int M() { <AS:0>return 1;</AS:0> } }";
var src2 = "class C { <AS:0>int M();</AS:0> }";
var src2 = "class C { <AS:0>extern int M();</AS:0> }";

var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.MethodBodyDelete, "int M()", FeaturesResources.method));
Diagnostic(RudeEditKind.ModifiersUpdate, "extern int M()", FeaturesResources.method));
}

[Fact]
public void Method_ExpressionBody_Delete1()
{
var src1 = "class C { int M() => <AS:0>1</AS:0>; }";
var src2 = "class C { <AS:0>int M();</AS:0> }";
var src2 = "class C { <AS:0>extern int M();</AS:0> }";

var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.MethodBodyDelete, "int M()", FeaturesResources.method));
Diagnostic(RudeEditKind.ModifiersUpdate, "extern int M()", FeaturesResources.method));
}

[Fact]
Expand Down Expand Up @@ -232,7 +232,7 @@ static void Swap<T>(T lhs, T rhs) where T : System.IComparable<T>
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.GenericMethodUpdate, "static void Swap<T>(T lhs, T rhs)", FeaturesResources.method));
Diagnostic(RudeEditKind.GenericMethodUpdate, "static void Swap<T>(T lhs, T rhs)"));
}

// Async
Expand Down Expand Up @@ -711,7 +711,7 @@ public T this[int i]
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.GenericTypeUpdate, "set", CSharpFeaturesResources.indexer_setter));
Diagnostic(RudeEditKind.GenericTypeUpdate, "set"));
}

[WorkItem(750244, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/750244")]
Expand Down Expand Up @@ -765,7 +765,7 @@ public T this[int i]

// Rude edits of active statements (AS:1) are not reported if the top-level edits are rude.
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.GenericTypeUpdate, "set", CSharpFeaturesResources.indexer_setter),
Diagnostic(RudeEditKind.GenericTypeUpdate, "set"),
Diagnostic(RudeEditKind.ActiveStatementUpdate, "stringCollection[1] = \"hello\";"));
}

Expand Down Expand Up @@ -816,7 +816,7 @@ public T this[int i]
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.GenericTypeUpdate, "get", CSharpFeaturesResources.indexer_getter));
Diagnostic(RudeEditKind.GenericTypeUpdate, "get"));
}

[WorkItem(750244, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/750244")]
Expand Down Expand Up @@ -868,7 +868,7 @@ public T this[int i]

// Rude edits of active statements (AS:1) are not reported if the top-level edits are rude.
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.GenericTypeUpdate, "get", CSharpFeaturesResources.indexer_getter),
Diagnostic(RudeEditKind.GenericTypeUpdate, "get"),
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Console.WriteLine(stringCollection[1]);"));
}

Expand Down Expand Up @@ -919,7 +919,7 @@ public T this[int i]
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.GenericTypeUpdate, "set", CSharpFeaturesResources.indexer_setter));
Diagnostic(RudeEditKind.GenericTypeUpdate, "set"));
}

[Fact]
Expand Down Expand Up @@ -1018,7 +1018,7 @@ public T this[int i]
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.GenericTypeUpdate, "get", CSharpFeaturesResources.indexer_getter));
Diagnostic(RudeEditKind.GenericTypeUpdate, "get"));
}

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

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.MethodBodyAdd, "get", CSharpFeaturesResources.property_getter));
edits.VerifyRudeDiagnostics(active);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,30 @@ internal static void VerifyRudeDiagnostics(

internal static void VerifyLineEdits(
this EditScript<SyntaxNode> editScript,
IEnumerable<SourceLineUpdate> expectedLineEdits,
IEnumerable<string> expectedNodeUpdates,
params RudeEditDiagnosticDescription[] expectedDiagnostics)
SourceLineUpdate[] lineEdits,
SemanticEditDescription[]? semanticEdits = null,
RudeEditDiagnosticDescription[]? diagnostics = null)
{
Assert.NotEmpty(expectedLineEdits);
Assert.NotEmpty(lineEdits);

VerifyLineEdits(
editScript,
new[] { new SequencePointUpdates(editScript.Match.OldRoot.SyntaxTree.FilePath, expectedLineEdits.ToImmutableArray()) },
expectedNodeUpdates,
expectedDiagnostics);
new[] { new SequencePointUpdates(editScript.Match.OldRoot.SyntaxTree.FilePath, lineEdits.ToImmutableArray()) },
semanticEdits,
diagnostics);
}

internal static void VerifyLineEdits(
this EditScript<SyntaxNode> editScript,
IEnumerable<SequencePointUpdates> expectedLineEdits,
IEnumerable<string> expectedNodeUpdates,
params RudeEditDiagnosticDescription[] expectedDiagnostics)
SequencePointUpdates[] lineEdits,
SemanticEditDescription[]? semanticEdits = null,
RudeEditDiagnosticDescription[]? diagnostics = null)
{
new CSharpEditAndContinueTestHelpers().VerifyLineEdits(
editScript,
expectedLineEdits,
expectedNodeUpdates,
expectedDiagnostics);
lineEdits,
semanticEdits,
diagnostics);
}

internal static void VerifySemanticDiagnostics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ internal static DocumentAnalysisResultsDescription DocumentResults(
ActiveStatementsDescription? activeStatements = null,
SemanticEditDescription[]? semanticEdits = null,
RudeEditDiagnosticDescription[]? diagnostics = null)
=> new(activeStatements, semanticEdits, diagnostics);
=> new(activeStatements, semanticEdits, lineEdits: null, diagnostics);

private static SyntaxTree ParseSource(string markedSource)
private static SyntaxTree ParseSource(string markedSource, int documentIndex = 0)
=> SyntaxFactory.ParseSyntaxTree(
ActiveStatementsDescription.ClearTags(markedSource),
CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview),
path: "test.cs");
path: documentIndex.ToString());

internal static EditScript<SyntaxNode> GetTopEdits(string src1, string src2)
internal static EditScript<SyntaxNode> GetTopEdits(string src1, string src2, int documentIndex = 0)
{
var tree1 = ParseSource(src1);
var tree2 = ParseSource(src2);
var tree1 = ParseSource(src1, documentIndex);
var tree2 = ParseSource(src2, documentIndex);

tree1.GetDiagnostics().Verify();
tree2.GetDiagnostics().Verify();
Expand Down
Loading