Skip to content

Commit

Permalink
Remove IActiveStatementSpanTracker from the MEF catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jun 10, 2020
1 parent 728187a commit 31a883f
Show file tree
Hide file tree
Showing 22 changed files with 299 additions and 269 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(TestActiveStatementSpanTracker)));
.WithPart(typeof(TestActiveStatementSpanTrackerFactory)));

#region Helpers

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

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());
var oldSolution = workspace.CurrentSolution;
Expand All @@ -287,7 +286,8 @@ 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<IActiveStatementSpanTracker>());
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);

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

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

using var workspace = TestWorkspace.CreateCSharp(source1, exportProvider: s_exportProviderFactoryWithTestActiveStatementSpanTracker.CreateExportProvider());
var oldSolution = workspace.CurrentSolution;
Expand All @@ -334,7 +333,8 @@ 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<IActiveStatementSpanTracker>());
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);

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<IActiveStatementSpanTracker>());
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);

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

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

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

Expand All @@ -403,7 +402,8 @@ 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<IActiveStatementSpanTracker>());
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);

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

Expand All @@ -424,7 +424,6 @@ 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 @@ -437,7 +436,8 @@ public static void Main()
var documentId = oldDocument.Id;

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

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

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

var featuresToEnable = new Dictionary<string, string>() { { feature, "enabled" } };
var experimental = TestOptions.Regular.WithFeatures(featuresToEnable);
Expand All @@ -489,7 +488,8 @@ 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<IActiveStatementSpanTracker>());
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);

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

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

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

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

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

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

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

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

Expand All @@ -567,7 +566,8 @@ 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<IActiveStatementSpanTracker>());
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);

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

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

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

Expand All @@ -611,7 +610,8 @@ 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<IActiveStatementSpanTracker>());
var spanTracker = Assert.IsType<TestActiveStatementSpanTracker>(workspace.Services.GetRequiredService<IActiveStatementSpanTrackerFactory>().GetOrCreateActiveStatementSpanTracker());
var analyzer = new CSharpEditAndContinueAnalyzer(spanTracker);

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

Expand Down Expand Up @@ -642,7 +642,6 @@ 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 @@ -664,7 +663,8 @@ public class D

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

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

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

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

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

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 Instance
internal static CSharpEditAndContinueTestHelpers CreateInstance()
=> new CSharpEditAndContinueTestHelpers(TargetFramework.Mscorlib46Extended);

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

private static readonly CSharpEditAndContinueAnalyzer s_analyzer = new CSharpEditAndContinueAnalyzer();

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

public override AbstractEditAndContinueAnalyzer Analyzer => s_analyzer;
public override AbstractEditAndContinueAnalyzer Analyzer => _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,16 +11,17 @@
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 readonly CSharpEditAndContinueAnalyzer Analyzer = new CSharpEditAndContinueAnalyzer();
internal static CSharpEditAndContinueAnalyzer CreateAnalyzer()
{
return new CSharpEditAndContinueAnalyzer(new TestActiveStatementSpanTracker());
}

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

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

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

var diagnostics = new List<RudeEditDiagnostic>();
var match = Analyzer.GetTestAccessor().ComputeBodyMatch(m1, m2, Array.Empty<AbstractEditAndContinueAnalyzer.ActiveNode>(), diagnostics, out var oldHasStateMachineSuspensionPoint, out var newHasStateMachineSuspensionPoint);
var match = CreateAnalyzer().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 @@ -90,7 +91,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(Analyzer, methodMatch);
return EditAndContinueTestHelpers.GetMethodMatches(CreateAnalyzer(), methodMatch);
}

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

var diagnostics = new List<RudeEditDiagnostic>();
var match = Analyzer.GetTestAccessor().ComputeBodyMatch(body1, body2, Array.Empty<AbstractEditAndContinueAnalyzer.ActiveNode>(), diagnostics, out var oldHasStateMachineSuspensionPoint, out var newHasStateMachineSuspensionPoint);
var match = CreateAnalyzer().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 31a883f

Please sign in to comment.