Skip to content
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

Merged
merged 16 commits into from
Aug 26, 2024

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Copy link
Contributor

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?


[ExportWorkspaceService(typeof(IAnalyzerAssemblyLoaderProvider)), Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class DefaultAnalyzerAssemblyLoaderService(
[ImportMany] IEnumerable<IAnalyzerAssemblyResolver> externalResolvers)
: AbstractAnalyzerAssemblyLoaderProvider(externalResolvers.ToImmutableArray());
Copy link
Member Author

Choose a reason for hiding this comment

The 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 AbstractAnalyzerAssemblyLoaderProvider to pick up the logic from that.

This file was deleted.

Loading