diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/HostDiagnosticAnalyzerProvider.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/HostDiagnosticAnalyzerProvider.cs
index 87a81f4de7dec..a7f193fe160d9 100644
--- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/HostDiagnosticAnalyzerProvider.cs
+++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/HostDiagnosticAnalyzerProvider.cs
@@ -8,44 +8,17 @@
using Microsoft.CodeAnalysis.Workspaces.ProjectSystem;
namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace;
-internal sealed class HostDiagnosticAnalyzerProvider : IHostDiagnosticAnalyzerProvider
-{
-
- private readonly ImmutableArray<(AnalyzerFileReference reference, string extensionId)> _analyzerReferences;
- public HostDiagnosticAnalyzerProvider(string? razorSourceGenerator)
- {
- if (razorSourceGenerator == null || !File.Exists(razorSourceGenerator))
- {
- _analyzerReferences = [];
- }
- else
- {
- _analyzerReferences = [(
- new AnalyzerFileReference(razorSourceGenerator, new SimpleAnalyzerAssemblyLoader()),
- ProjectSystemProject.RazorVsixExtensionId
- )];
- }
- }
-
- public ImmutableArray<(AnalyzerFileReference reference, string extensionId)> GetAnalyzerReferencesInExtensions()
- {
- return _analyzerReferences;
- }
+internal sealed class HostDiagnosticAnalyzerProvider(string? razorSourceGenerator) : IHostDiagnosticAnalyzerProvider
+{
+ public ImmutableArray<(AnalyzerFileReference reference, string extensionId)> GetAnalyzerReferencesInExtensions() => [];
- private sealed class SimpleAnalyzerAssemblyLoader : IAnalyzerAssemblyLoader
+ public ImmutableArray<(string path, string extensionId)> GetRazorAssembliesInExtensions()
{
- public void AddDependencyLocation(string fullPath)
- {
- // This method is used to add a path that should be probed for analyzer dependencies.
- // In this simple implementation, we do nothing.
- }
-
- public Assembly LoadFromPath(string fullPath)
+ if (File.Exists(razorSourceGenerator))
{
- // This method is used to load an analyzer assembly from the specified path.
- // In this simple implementation, we use Assembly.LoadFrom to load the assembly.
- return Assembly.LoadFrom(fullPath);
+ return [(razorSourceGenerator, ProjectSystemProject.RazorVsixExtensionId)];
}
+ return [];
}
}
diff --git a/src/VisualStudio/Core/Def/Diagnostics/VisualStudioDiagnosticAnalyzerProvider.cs b/src/VisualStudio/Core/Def/Diagnostics/VisualStudioDiagnosticAnalyzerProvider.cs
index 95a248768a7b3..dd4f125902eb2 100644
--- a/src/VisualStudio/Core/Def/Diagnostics/VisualStudioDiagnosticAnalyzerProvider.cs
+++ b/src/VisualStudio/Core/Def/Diagnostics/VisualStudioDiagnosticAnalyzerProvider.cs
@@ -22,6 +22,8 @@ internal sealed partial class VisualStudioDiagnosticAnalyzerProvider : IHostDiag
{
private const string AnalyzerContentTypeName = "Microsoft.VisualStudio.Analyzer";
+ internal const string RazorContentTypeName = "Microsoft.VisualStudio.RazorAssembly";
+
///
/// Loader for VSIX-based analyzers.
///
@@ -31,6 +33,7 @@ internal sealed partial class VisualStudioDiagnosticAnalyzerProvider : IHostDiag
private readonly Type _typeIExtensionContent;
private readonly Lazy> _lazyAnalyzerReferences;
+ private readonly Lazy> _lazyRazorReferences;
// internal for testing
internal VisualStudioDiagnosticAnalyzerProvider(object extensionManager, Type typeIExtensionContent)
@@ -40,24 +43,28 @@ internal VisualStudioDiagnosticAnalyzerProvider(object extensionManager, Type ty
_extensionManager = extensionManager;
_typeIExtensionContent = typeIExtensionContent;
- _lazyAnalyzerReferences = new Lazy>(GetAnalyzerReferencesImpl);
+ _lazyAnalyzerReferences = new Lazy>(() => GetExtensionContent(AnalyzerContentTypeName).SelectAsArray(c => (new AnalyzerFileReference(c.path, AnalyzerAssemblyLoader), c.extensionId)));
+ _lazyRazorReferences = new Lazy>(() => GetExtensionContent(RazorContentTypeName));
}
public ImmutableArray<(AnalyzerFileReference reference, string extensionId)> GetAnalyzerReferencesInExtensions()
=> _lazyAnalyzerReferences.Value;
- private ImmutableArray<(AnalyzerFileReference reference, string extensionId)> GetAnalyzerReferencesImpl()
+ public ImmutableArray<(string path, string extensionId)> GetRazorAssembliesInExtensions()
+ => _lazyRazorReferences.Value;
+
+ private ImmutableArray<(string path, string extensionId)> GetExtensionContent(string contentTypeName)
{
try
{
// dynamic is weird. it can't see internal type with public interface even if callee is
// implementation of the public interface in internal type. so we can't use dynamic here
- var _ = PooledDictionary.GetInstance(out var analyzePaths);
+ var _ = PooledDictionary.GetInstance(out var analyzePaths);
- // var enabledExtensions = extensionManager.GetEnabledExtensions(AnalyzerContentTypeName);
+ // var enabledExtensions = extensionManager.GetEnabledExtensions(contentTypeName);
var extensionManagerType = _extensionManager.GetType();
var extensionManager_GetEnabledExtensionsMethod = extensionManagerType.GetRuntimeMethod("GetEnabledExtensions", [typeof(string)]);
- var enabledExtensions = (IEnumerable