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); }
internal static void VerifySemantics( this EditScript<SyntaxNode> editScript, ActiveStatementsDescription activeStatements, SemanticEditDescription[] expectedSemanticEdits, params RudeEditDiagnosticDescription[] expectedDiagnostics) { VerifySemantics(editScript, activeStatements, null, null, expectedSemanticEdits, expectedDiagnostics); }
internal static void VerifyRudeDiagnostics( this EditScript <SyntaxNode> editScript, ActiveStatementsDescription description, params RudeEditDiagnosticDescription[] expectedDiagnostics ) { VerifySemanticDiagnostics(editScript, description, expectedDiagnostics); }
internal static void VerifySemantics( this EditScript <SyntaxNode> editScript, ActiveStatementsDescription activeStatements, SemanticEditDescription[] expectedSemanticEdits) { VerifySemantics( new[] { editScript }, new[] { new DocumentAnalysisResultsDescription(activeStatements, semanticEdits: expectedSemanticEdits) }); }
internal static void VerifySemanticDiagnostics( this EditScript <SyntaxNode> editScript, ActiveStatementsDescription activeStatements, params RudeEditDiagnosticDescription[] expectedDiagnostics) { VerifySemantics( new[] { editScript }, new[] { new DocumentAnalysisResultsDescription(activeStatements: activeStatements, diagnostics: expectedDiagnostics) }); }
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); }
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); }
internal static void VerifyUnchangedDocument( string source, ActiveStatementsDescription description) { CSharpEditAndContinueTestHelpers.Instance.VerifyUnchangedDocument( ActiveStatementsDescription.ClearTags(source), description.OldSpans, description.OldTrackingSpans, description.NewSpans, description.OldRegions, description.NewRegions); }
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); }
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); }
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); } }
private static SyntaxTree ParseSource(string source) => CSharpEditAndContinueTestHelpers.Instance.ParseText(ActiveStatementsDescription.ClearTags(source));
private static SyntaxTree ParseSource(string source, ParseOptions options = null) { return(SyntaxFactory.ParseSyntaxTree(ActiveStatementsDescription.ClearTags(source), options: options)); }