6
6
using System . Collections . Concurrent ;
7
7
using System . Collections . Generic ;
8
8
using System . Collections . Immutable ;
9
+ using System . ComponentModel ;
9
10
using System . IO ;
10
11
using System . Linq ;
11
12
using System . Reflection ;
@@ -32,25 +33,8 @@ namespace Microsoft.CodeAnalysis.Testing
32
33
public abstract class AnalyzerTest < TVerifier >
33
34
where TVerifier : IVerifier , new ( )
34
35
{
35
- private static readonly Lazy < IExportProviderFactory > ExportProviderFactory ;
36
36
private static readonly ConditionalWeakTable < Diagnostic , object > NonLocalDiagnostics = new ConditionalWeakTable < Diagnostic , object > ( ) ;
37
37
38
- static AnalyzerTest ( )
39
- {
40
- ExportProviderFactory = new Lazy < IExportProviderFactory > (
41
- ( ) =>
42
- {
43
- var discovery = new AttributedPartDiscovery ( Resolver . DefaultInstance , isNonPublicSupported : true ) ;
44
- var parts = Task . Run ( ( ) => discovery . CreatePartsAsync ( MefHostServices . DefaultAssemblies ) ) . GetAwaiter ( ) . GetResult ( ) ;
45
- var catalog = ComposableCatalog . Create ( Resolver . DefaultInstance ) . AddParts ( parts ) . WithDocumentTextDifferencingService ( ) ;
46
-
47
- var configuration = CompositionConfiguration . Create ( catalog ) ;
48
- var runtimeComposition = RuntimeComposition . CreateRuntimeComposition ( configuration ) ;
49
- return runtimeComposition . CreateExportProviderFactory ( ) ;
50
- } ,
51
- LazyThreadSafetyMode . ExecutionAndPublication ) ;
52
- }
53
-
54
38
/// <summary>
55
39
/// Gets the default verifier for the test.
56
40
/// </summary>
@@ -1587,7 +1571,7 @@ protected virtual async Task<Solution> CreateSolutionAsync(ProjectId projectId,
1587
1571
var parseOptions = CreateParseOptions ( )
1588
1572
. WithDocumentationMode ( projectState . DocumentationMode ) ;
1589
1573
1590
- var workspace = CreateWorkspace ( ) ;
1574
+ var workspace = await CreateWorkspaceAsync ( ) . ConfigureAwait ( false ) ;
1591
1575
foreach ( var transform in OptionsTransforms )
1592
1576
{
1593
1577
workspace . Options = transform ( workspace . Options ) ;
@@ -1660,16 +1644,27 @@ protected virtual Project ApplyCompilationOptions(Project project)
1660
1644
return solution . GetProject ( project . Id ) ;
1661
1645
}
1662
1646
1647
+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
1648
+ [ Obsolete ( $ "Use { nameof ( CreateWorkspaceAsync ) } instead. https://github.com/dotnet/roslyn-sdk/pull/1120", error : true ) ]
1663
1649
public Workspace CreateWorkspace ( )
1650
+ => throw new NotSupportedException ( ) ;
1651
+
1652
+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
1653
+ [ Obsolete ( $ "Use { nameof ( CreateWorkspaceImplAsync ) } instead. https://github.com/dotnet/roslyn-sdk/pull/1120", error : true ) ]
1654
+ protected virtual Workspace CreateWorkspaceImpl ( )
1655
+ => throw new NotSupportedException ( ) ;
1656
+
1657
+ public async Task < Workspace > CreateWorkspaceAsync ( )
1664
1658
{
1665
- var workspace = CreateWorkspaceImpl ( ) ;
1659
+ var workspace = await CreateWorkspaceImplAsync ( ) . ConfigureAwait ( false ) ;
1666
1660
_workspaces . Add ( workspace ) ;
1667
1661
return workspace ;
1668
1662
}
1669
1663
1670
- protected virtual Workspace CreateWorkspaceImpl ( )
1664
+ protected virtual async Task < Workspace > CreateWorkspaceImplAsync ( )
1671
1665
{
1672
- var exportProvider = ExportProviderFactory . Value . CreateExportProvider ( ) ;
1666
+ var exportProviderFactory = await ExportProviderFactory . GetOrCreateExportProviderFactoryAsync ( ) . ConfigureAwait ( false ) ;
1667
+ var exportProvider = exportProviderFactory . CreateExportProvider ( ) ;
1673
1668
var host = MefHostServices . Create ( exportProvider . AsCompositionContext ( ) ) ;
1674
1669
return new AdhocWorkspace ( host ) ;
1675
1670
}
0 commit comments