public async Task AnalyzeDocumentAsync_InsignificantChangesInMethodBody()
        {
            var source1 = @"
class C
{
    public static void Main()
    {
        // comment
        System.Console.WriteLine(1);
    }
}
";
            var source2 = @"
class C
{
    public static void Main()
    {
        System.Console.WriteLine(1);
    }
}
";

            using var workspace = TestWorkspace.CreateCSharp(source1, composition: s_composition);
            var oldSolution = workspace.CurrentSolution;
            var oldProject  = oldSolution.Projects.Single();
            var oldDocument = oldProject.Documents.Single();
            var oldText     = await oldDocument.GetTextAsync();

            var oldSyntaxRoot = await oldDocument.GetSyntaxRootAsync();

            var documentId  = oldDocument.Id;
            var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));
            var newDocument = newSolution.GetDocument(documentId);
            var newText     = await newDocument.GetTextAsync();

            var newSyntaxRoot = await newDocument.GetSyntaxRootAsync();

            const string oldStatementSource   = "System.Console.WriteLine(1);";
            var          oldStatementPosition = source1.IndexOf(oldStatementSource, StringComparison.Ordinal);
            var          oldStatementTextSpan = new TextSpan(oldStatementPosition, oldStatementSource.Length);
            var          oldStatementSpan     = oldText.Lines.GetLinePositionSpan(oldStatementTextSpan);
            var          oldStatementSyntax   = oldSyntaxRoot.FindNode(oldStatementTextSpan);

            var baseActiveStatements = ImmutableArray.Create(ActiveStatementsDescription.CreateActiveStatement(ActiveStatementFlags.IsLeafFrame, oldStatementSpan, DocumentId.CreateNewId(ProjectId.CreateNewId())));
            var analyzer             = new CSharpEditAndContinueAnalyzer();

            var result = await analyzer.AnalyzeDocumentAsync(oldProject, baseActiveStatements, newDocument, ImmutableArray <TextSpan> .Empty, CancellationToken.None);

            Assert.True(result.HasChanges);
            Assert.True(result.SemanticEdits[0].PreserveLocalVariables);
            var syntaxMap = result.SemanticEdits[0].SyntaxMap;

            var newStatementSpan     = result.ActiveStatements[0].Span;
            var newStatementTextSpan = newText.Lines.GetTextSpan(newStatementSpan);
            var newStatementSyntax   = newSyntaxRoot.FindNode(newStatementTextSpan);

            var oldStatementSyntaxMapped = syntaxMap(newStatementSyntax);

            Assert.Same(oldStatementSyntax, oldStatementSyntaxMapped);
        }
 internal static void VerifySemanticDiagnostics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     VerifySemanticDiagnostics(editScript, activeStatements, capabilities: null, expectedDiagnostics);
 }
Example #3
0
 internal static void VerifySemantics(
     this EditScript<SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     SemanticEditDescription[] expectedSemanticEdits,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     VerifySemantics(editScript, activeStatements, null, null, expectedSemanticEdits, expectedDiagnostics);
 }
Example #4
0
 internal static void VerifyRudeDiagnostics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription description,
     params RudeEditDiagnosticDescription[] expectedDiagnostics
     )
 {
     VerifySemanticDiagnostics(editScript, description, expectedDiagnostics);
 }
Example #5
0
 internal static void VerifySemantics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     SemanticEditDescription[] expectedSemanticEdits)
 {
     VerifySemantics(
         new[] { editScript },
         new[] { new DocumentAnalysisResultsDescription(activeStatements, semanticEdits: expectedSemanticEdits) });
 }
Example #6
0
 internal static void VerifySemanticDiagnostics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     VerifySemantics(
         new[] { editScript },
         new[] { new DocumentAnalysisResultsDescription(activeStatements: activeStatements, diagnostics: expectedDiagnostics) });
 }
Example #7
0
 internal static void VerifySemantics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     SemanticEditDescription[] expectedSemanticEdits,
     DiagnosticDescription expectedDeclarationError,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     VerifySemantics(editScript, activeStatements, null, null, expectedSemanticEdits, expectedDeclarationError, expectedDiagnostics);
 }
 internal static void VerifyRudeDiagnostics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription description,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     CSharpEditAndContinueTestHelpers.CreateInstance().VerifyRudeDiagnostics(
         editScript,
         description,
         expectedDiagnostics);
 }
Example #9
0
 internal static void VerifyRudeDiagnostics(
     this EditScript<SyntaxNode> editScript,
     ActiveStatementsDescription description,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     CSharpEditAndContinueTestHelpers.Instance.VerifyRudeDiagnostics(
         editScript,
         description,
         expectedDiagnostics);
 }
 internal static void VerifyUnchangedDocument(
     string source,
     ActiveStatementsDescription description)
 {
     CSharpEditAndContinueTestHelpers.CreateInstance().VerifyUnchangedDocument(
         ActiveStatementsDescription.ClearTags(source),
         description.OldStatements,
         description.NewSpans,
         description.NewRegions);
 }
 internal static void VerifySemantics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     SemanticEditDescription[] expectedSemanticEdits)
 {
     VerifySemantics(
         new[] { editScript },
         activeStatements,
         expectedSemanticEdits: expectedSemanticEdits,
         expectedDiagnostics: null);
 }
 internal static void VerifySemantics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     SemanticEditDescription[] expectedSemanticEdits,
     EditAndContinueCapabilities?capabilities = null)
 {
     VerifySemantics(
         new[] { editScript },
         new[] { new DocumentAnalysisResultsDescription(activeStatements, semanticEdits: expectedSemanticEdits) },
         capabilities: capabilities);
 }
 internal static void VerifySemanticDiagnostics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     EditAndContinueCapabilities?capabilities = null,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     VerifySemantics(
         new[] { editScript },
         new[] { new DocumentAnalysisResultsDescription(activeStatements: activeStatements, diagnostics: expectedDiagnostics) },
         capabilities: capabilities);
 }
Example #14
0
 internal static void VerifyUnchangedDocument(
     string source,
     ActiveStatementsDescription description)
 {
     CSharpEditAndContinueTestHelpers.Instance.VerifyUnchangedDocument(
         ActiveStatementsDescription.ClearTags(source),
         description.OldSpans,
         description.OldTrackingSpans,
         description.NewSpans,
         description.OldRegions,
         description.NewRegions);
 }
Example #15
0
 internal static void VerifySemantics(
     this EditScript<SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     IEnumerable<string> additionalOldSources,
     IEnumerable<string> additionalNewSources,
     SemanticEditDescription[] expectedSemanticEdits,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     CSharpEditAndContinueTestHelpers.Instance.VerifySemantics(
         editScript,
         activeStatements,
         additionalOldSources,
         additionalNewSources,
         expectedSemanticEdits,
         expectedDiagnostics);
 }
Example #16
0
 internal static void VerifySemantics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements,
     IEnumerable <string> additionalOldSources,
     IEnumerable <string> additionalNewSources,
     SemanticEditDescription[] expectedSemanticEdits,
     params RudeEditDiagnosticDescription[] expectedDiagnostics)
 {
     CSharpEditAndContinueTestHelpers.Instance.VerifySemantics(
         editScript,
         activeStatements,
         additionalOldSources,
         additionalNewSources,
         expectedSemanticEdits,
         expectedDiagnostics);
 }
Example #17
0
 internal static void VerifySemantics(
     this EditScript <SyntaxNode> editScript,
     ActiveStatementsDescription activeStatements        = null,
     TargetFramework[] targetFrameworks                  = null,
     IEnumerable <string> additionalOldSources           = null,
     IEnumerable <string> additionalNewSources           = null,
     SemanticEditDescription[] expectedSemanticEdits     = null,
     DiagnosticDescription expectedDeclarationError      = null,
     RudeEditDiagnosticDescription[] expectedDiagnostics = null)
 {
     foreach (var targetFramework in targetFrameworks ?? new[] { TargetFramework.NetStandard20, TargetFramework.NetCoreApp30 })
     {
         new CSharpEditAndContinueTestHelpers(targetFramework).VerifySemantics(
             editScript,
             activeStatements,
             additionalOldSources,
             additionalNewSources,
             expectedSemanticEdits,
             expectedDeclarationError,
             expectedDiagnostics);
     }
 }
Example #18
0
 private static SyntaxTree ParseSource(string source)
 => CSharpEditAndContinueTestHelpers.Instance.ParseText(ActiveStatementsDescription.ClearTags(source));
Example #19
0
 private static SyntaxTree ParseSource(string source, ParseOptions options = null)
 {
     return(SyntaxFactory.ParseSyntaxTree(ActiveStatementsDescription.ClearTags(source), options: options));
 }