-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify and unify assembly loader provider #74895
Changes from 1 commit
65aaa15
cab006f
9bef508
655c0f8
9b75362
561c5cd
e6b292d
574bde8
bbf4ff9
f0fab02
d72580b
65e1db9
9da0b5e
a610785
b8a923f
bf31f0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,49 @@ | |
// 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; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.IO; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
|
||
namespace Microsoft.CodeAnalysis.Host; | ||
|
||
internal interface IAnalyzerAssemblyLoaderProvider : IWorkspaceService | ||
{ | ||
IAnalyzerAssemblyLoaderInternal GetShadowCopyLoader(); | ||
} | ||
|
||
/// <summary> | ||
/// Abstract implementation of an analyzer assembly loader that can be used by VS/VSCode to provide a <see | ||
/// cref="IAnalyzerAssemblyLoader"/> with an appropriate path. | ||
/// </summary> | ||
internal abstract class AbstractAnalyzerAssemblyLoaderProvider : IAnalyzerAssemblyLoaderProvider | ||
{ | ||
private readonly Lazy<IAnalyzerAssemblyLoaderInternal> _shadowCopyLoader; | ||
|
||
public AbstractAnalyzerAssemblyLoaderProvider(ImmutableArray<IAnalyzerAssemblyResolver> externalResolvers) | ||
{ | ||
// We use a lazy here in case creating the loader requires MEF imports in the derived constructor. | ||
_shadowCopyLoader = new(() => CreateShadowCopyLoader(externalResolvers)); | ||
} | ||
|
||
public IAnalyzerAssemblyLoaderInternal GetShadowCopyLoader() | ||
=> _shadowCopyLoader.Value; | ||
|
||
protected virtual IAnalyzerAssemblyLoaderInternal CreateShadowCopyLoader(ImmutableArray<IAnalyzerAssemblyResolver> externalResolvers) | ||
=> DefaultAnalyzerAssemblyLoader.CreateNonLockingLoader( | ||
GetDefaultShadowCopyPath(), | ||
externalResolvers: externalResolvers); | ||
|
||
public static string GetDefaultShadowCopyPath() | ||
=> Path.Combine(Path.GetTempPath(), "Roslyn", "AnalyzerAssemblyLoader"); | ||
} | ||
|
||
[ExportWorkspaceService(typeof(IAnalyzerAssemblyLoaderProvider)), Shared] | ||
[method: ImportingConstructor] | ||
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
internal sealed class DefaultAnalyzerAssemblyLoaderService( | ||
[ImportMany] IEnumerable<IAnalyzerAssemblyResolver> externalResolvers) | ||
: AbstractAnalyzerAssemblyLoaderProvider(externalResolvers.ToImmutableArray()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this default impl is what everything (except VSCode) uses. It is slightly different from the original logic in that it now just subclasses |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused by this comment. _workspaceKind is still factoring into the path passed into WrapLoader, no?