Skip to content

Commit

Permalink
Revert "Remove IActiveStatementSpanTracker from the MEF catalog" (#45239
Browse files Browse the repository at this point in the history
)

This reverts commit 31a883f.
  • Loading branch information
chsienki authored Jun 17, 2020
1 parent d702fa6 commit d04ebc2
Show file tree
Hide file tree
Showing 22 changed files with 269 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CSharpEditAndContinueAnalyzerTests
{
private static readonly IExportProviderFactory s_exportProviderFactoryWithTestActiveStatementSpanTracker =
ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic
.WithPart(typeof(TestActiveStatementSpanTrackerFactory)));
.WithPart(typeof(TestActiveStatementSpanTracker)));

#region Helpers

Expand Down Expand Up @@ -266,6 +266,7 @@ public static void Main()
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());
var oldSolution = workspace.CurrentSolution;
Expand All @@ -286,8 +287,7 @@ public static void Main()
var oldStatementSyntax = oldSyntaxRoot.FindNode(oldStatementTextSpan);

var baseActiveStatements = ImmutableArray.Create(ActiveStatementsDescription.CreateActiveStatement(ActiveStatementFlags.IsLeafFrame, oldStatementSpan, DocumentId.CreateNewId(ProjectId.CreateNewId())));
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, newDocument, CancellationToken.None);

Expand Down Expand Up @@ -324,6 +324,7 @@ public static void Main()
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());
var oldSolution = workspace.CurrentSolution;
Expand All @@ -333,8 +334,7 @@ public static void Main()
var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));

var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, newSolution.GetDocument(documentId), CancellationToken.None);

Expand All @@ -355,13 +355,13 @@ public static void Main()
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());
var oldProject = workspace.CurrentSolution.Projects.Single();
var oldDocument = oldProject.Documents.Single();
var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, oldDocument, CancellationToken.None);

Expand Down Expand Up @@ -391,6 +391,7 @@ public static void Main()
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());

Expand All @@ -402,8 +403,7 @@ public static void Main()
var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));

var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, newSolution.GetDocument(documentId), CancellationToken.None);

Expand All @@ -424,6 +424,7 @@ public static void Main()
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();
var experimentalFeatures = new Dictionary<string, string>(); // no experimental features to enable
var experimental = TestOptions.Regular.WithFeatures(experimentalFeatures);

Expand All @@ -436,8 +437,7 @@ public static void Main()
var documentId = oldDocument.Id;

var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, oldDocument, CancellationToken.None);

Expand Down Expand Up @@ -473,6 +473,7 @@ public static void Main()
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

var featuresToEnable = new Dictionary<string, string>() { { feature, "enabled" } };
var experimental = TestOptions.Regular.WithFeatures(featuresToEnable);
Expand All @@ -488,8 +489,7 @@ public static void Main()
var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));

var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, newSolution.GetDocument(documentId), CancellationToken.None);

Expand All @@ -513,6 +513,7 @@ public static void Main()
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());

Expand All @@ -522,8 +523,7 @@ public static void Main()
var documentId = oldDocument.Id;

var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, oldDocument, CancellationToken.None);

Expand Down Expand Up @@ -555,6 +555,7 @@ public static void Main()
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());

Expand All @@ -566,8 +567,7 @@ public static void Main()
var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));

var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, newSolution.GetDocument(documentId), CancellationToken.None);

Expand Down Expand Up @@ -599,6 +599,7 @@ public static void Main(Bar x)
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());

Expand All @@ -610,8 +611,7 @@ public static void Main(Bar x)
var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));

var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

var result = await analyzer.AnalyzeDocumentAsync(oldDocument, baseActiveStatements, newSolution.GetDocument(documentId), CancellationToken.None);

Expand Down Expand Up @@ -642,6 +642,7 @@ public class D
}
}
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());
// fork the solution to introduce a change
Expand All @@ -663,8 +664,7 @@ public class D

var result = new List<DocumentAnalysisResults>();
var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

foreach (var changedDocumentId in changedDocuments)
{
Expand Down Expand Up @@ -692,6 +692,7 @@ public static void Main()
";
var source2 = @"
";
var analyzer = new CSharpEditAndContinueAnalyzer();

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());

Expand All @@ -713,8 +714,7 @@ public static void Main()

var result = new List<DocumentAnalysisResults>();
var baseActiveStatements = ImmutableArray.Create<ActiveStatement>();
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTracker>());

foreach (var changedDocumentId in changedDocuments)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.EditAndContinue
{
internal sealed class CSharpEditAndContinueTestHelpers : EditAndContinueTestHelpers
{
private readonly CSharpEditAndContinueAnalyzer _analyzer = new CSharpEditAndContinueAnalyzer(new TestActiveStatementSpanTracker());

private readonly ImmutableArray<MetadataReference> _fxReferences;

internal static CSharpEditAndContinueTestHelpers CreateInstance()
internal static CSharpEditAndContinueTestHelpers Instance
=> new CSharpEditAndContinueTestHelpers(TargetFramework.Mscorlib46Extended);

internal static CSharpEditAndContinueTestHelpers CreateInstance40()
internal static CSharpEditAndContinueTestHelpers Instance40
=> new CSharpEditAndContinueTestHelpers(TargetFramework.Mscorlib40AndSystemCore);

private static readonly CSharpEditAndContinueAnalyzer s_analyzer = new CSharpEditAndContinueAnalyzer();

public CSharpEditAndContinueTestHelpers(TargetFramework targetFramework)
=> _fxReferences = TargetFrameworkUtil.GetReferences(targetFramework);

public override AbstractEditAndContinueAnalyzer Analyzer => _analyzer;
public override AbstractEditAndContinueAnalyzer Analyzer => s_analyzer;

public override Compilation CreateLibraryCompilation(string name, IEnumerable<SyntaxTree> trees)
=> CSharpCompilation.Create("New", trees, _fxReferences, TestOptions.UnsafeReleaseDll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
using Microsoft.CodeAnalysis.EditAndContinue.UnitTests;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.EditAndContinue;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.EditAndContinue.UnitTests
{
[UseExportProvider]
public abstract class EditingTestBase : CSharpTestBase
{
internal static CSharpEditAndContinueAnalyzer CreateAnalyzer()
{
return new CSharpEditAndContinueAnalyzer(new TestActiveStatementSpanTracker());
}
internal static readonly CSharpEditAndContinueAnalyzer Analyzer = new CSharpEditAndContinueAnalyzer();

internal enum MethodKind
{
Expand All @@ -46,7 +45,7 @@ internal static SemanticEditDescription SemanticEdit(SemanticEditKind kind, Func
=> new SemanticEditDescription(kind, symbolProvider, null, preserveLocalVariables);

private static SyntaxTree ParseSource(string source)
=> CSharpEditAndContinueTestHelpers.CreateInstance().ParseText(ActiveStatementsDescription.ClearTags(source));
=> CSharpEditAndContinueTestHelpers.Instance.ParseText(ActiveStatementsDescription.ClearTags(source));

internal static EditScript<SyntaxNode> GetTopEdits(string src1, string src2)
{
Expand Down Expand Up @@ -75,7 +74,7 @@ internal static Match<SyntaxNode> GetMethodMatch(string src1, string src2, Metho
var m2 = MakeMethodBody(src2, kind);

var diagnostics = new List<RudeEditDiagnostic>();
var match = CreateAnalyzer().GetTestAccessor().ComputeBodyMatch(m1, m2, Array.Empty<AbstractEditAndContinueAnalyzer.ActiveNode>(), diagnostics, out var oldHasStateMachineSuspensionPoint, out var newHasStateMachineSuspensionPoint);
var match = Analyzer.GetTestAccessor().ComputeBodyMatch(m1, m2, Array.Empty<AbstractEditAndContinueAnalyzer.ActiveNode>(), diagnostics, out var oldHasStateMachineSuspensionPoint, out var newHasStateMachineSuspensionPoint);
var needsSyntaxMap = oldHasStateMachineSuspensionPoint && newHasStateMachineSuspensionPoint;

Assert.Equal(kind != MethodKind.Regular && kind != MethodKind.ConstructorWithParameters, needsSyntaxMap);
Expand All @@ -91,7 +90,7 @@ internal static Match<SyntaxNode> GetMethodMatch(string src1, string src2, Metho
internal static IEnumerable<KeyValuePair<SyntaxNode, SyntaxNode>> GetMethodMatches(string src1, string src2, MethodKind kind = MethodKind.Regular)
{
var methodMatch = GetMethodMatch(src1, src2, kind);
return EditAndContinueTestHelpers.GetMethodMatches(CreateAnalyzer(), methodMatch);
return EditAndContinueTestHelpers.GetMethodMatches(Analyzer, methodMatch);
}

public static MatchingPairs ToMatchingPairs(Match<SyntaxNode> match)
Expand Down Expand Up @@ -144,7 +143,7 @@ internal static void VerifyPreserveLocalVariables(EditScript<SyntaxNode> edits,
var body2 = ((MethodDeclarationSyntax)SyntaxFactory.SyntaxTree(decl2).GetRoot()).Body;

var diagnostics = new List<RudeEditDiagnostic>();
var match = CreateAnalyzer().GetTestAccessor().ComputeBodyMatch(body1, body2, Array.Empty<AbstractEditAndContinueAnalyzer.ActiveNode>(), diagnostics, out var oldHasStateMachineSuspensionPoint, out var newHasStateMachineSuspensionPoint);
var match = Analyzer.GetTestAccessor().ComputeBodyMatch(body1, body2, Array.Empty<AbstractEditAndContinueAnalyzer.ActiveNode>(), diagnostics, out var oldHasStateMachineSuspensionPoint, out var newHasStateMachineSuspensionPoint);
var needsSyntaxMap = oldHasStateMachineSuspensionPoint && newHasStateMachineSuspensionPoint;

// Active methods are detected to preserve local variables for variable mapping and
Expand Down
Loading

0 comments on commit d04ebc2

Please sign in to comment.