-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1120 from sharwell/export-provider
Create export provider asynchronously
- Loading branch information
Showing
4 changed files
with
60 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...oft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/ExportProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.VisualStudio.Composition; | ||
|
||
namespace Microsoft.CodeAnalysis.Testing | ||
{ | ||
internal static class ExportProviderFactory | ||
{ | ||
private static readonly object s_lock = new(); | ||
private static Task<IExportProviderFactory>? s_exportProviderFactory; | ||
|
||
public static Task<IExportProviderFactory> GetOrCreateExportProviderFactoryAsync() | ||
{ | ||
if (s_exportProviderFactory is { } exportProviderFactory) | ||
{ | ||
return exportProviderFactory; | ||
} | ||
|
||
lock (s_lock) | ||
{ | ||
s_exportProviderFactory ??= Task.Run(CreateExportProviderFactorySlowAsync); | ||
return s_exportProviderFactory; | ||
} | ||
|
||
static async Task<IExportProviderFactory> CreateExportProviderFactorySlowAsync() | ||
{ | ||
var discovery = new AttributedPartDiscovery(Resolver.DefaultInstance, isNonPublicSupported: true); | ||
var parts = await discovery.CreatePartsAsync(MefHostServices.DefaultAssemblies).ConfigureAwait(false); | ||
var catalog = ComposableCatalog.Create(Resolver.DefaultInstance).AddParts(parts).WithDocumentTextDifferencingService(); | ||
|
||
var configuration = CompositionConfiguration.Create(catalog); | ||
var runtimeComposition = RuntimeComposition.CreateRuntimeComposition(configuration); | ||
return runtimeComposition.CreateExportProviderFactory(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters