提交 f5dbc0a9 编写于 作者: H Heejae Chang

avoid loading dlls not needed

上级 bda4d971
......@@ -78,7 +78,7 @@ internal class VisualStudioDiagnosticAnalyzerExecutor : ICodeAnalysisDiagnosticA
}
var optionAsset = GetOptionsAsset(solution, project.Language, cancellationToken);
var hostChecksums = GetHostAnalyzerReferences(snapshotService, _analyzerService.GetHostAnalyzerReferences(), cancellationToken);
var hostChecksums = GetHostAnalyzerReferences(snapshotService, project.Language, _analyzerService.GetHostAnalyzerReferences(), cancellationToken);
var argument = new DiagnosticArguments(
analyzerDriver.AnalysisOptions.ReportSuppressedDiagnostics,
......@@ -158,12 +158,22 @@ private void ReportAnalyzerExceptions(Project project, ImmutableDictionary<Diagn
}
}
private ImmutableArray<byte[]> GetHostAnalyzerReferences(ISolutionSynchronizationService snapshotService, IEnumerable<AnalyzerReference> references, CancellationToken cancellationToken)
private ImmutableArray<byte[]> GetHostAnalyzerReferences(
ISolutionSynchronizationService snapshotService, string language, IEnumerable<AnalyzerReference> references, CancellationToken cancellationToken)
{
// TODO: cache this to somewhere
var builder = ImmutableArray.CreateBuilder<byte[]>();
foreach (var reference in references)
{
var analyzers = reference.GetAnalyzers(language);
if (analyzers.Length == 0)
{
// skip reference that doesn't contain any analyzers for the given language
// we do this so that we don't load analyzer dlls that MEF exported from vsix
// not related to this solution
continue;
}
var asset = snapshotService.GetGlobalAsset(reference, cancellationToken);
builder.Add(asset.Checksum.ToArray());
}
......
......@@ -3,6 +3,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Serialization;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Execution
......@@ -48,4 +50,47 @@ private static Checksum CreateChecksumFromStreamWriter(string kind, Action<Objec
}
}
}
/// <summary>
/// workspace analyzer specific asset.
///
/// we need this to prevent dlls from other languages such as typescript, f#, xaml and etc
/// from loading at OOP start up.
///
/// unlike project analyzer, analyzer that got installed from vsix doesn't do shadow copying
/// so we don't need to load assembly to find out actual filepath.
///
/// this also will be temporary solution for RC since we will move to MVID for checksum soon
/// </summary>
internal sealed class WorkspaceAnalyzerReferenceAsset : CustomAsset
{
private readonly AnalyzerReference _reference;
private readonly Serializer _serializer;
public WorkspaceAnalyzerReferenceAsset(AnalyzerReference reference, Serializer serializer) :
base(CreateChecksum(reference), WellKnownSynchronizationKinds.AnalyzerReference)
{
_reference = reference;
_serializer = serializer;
}
public override Task WriteObjectToAsync(ObjectWriter writer, CancellationToken cancellationToken)
{
_serializer.SerializeAnalyzerReference(_reference, writer, cancellationToken);
return SpecializedTasks.EmptyTask;
}
private static Checksum CreateChecksum(AnalyzerReference reference)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var objectWriter = new ObjectWriter(stream))
{
objectWriter.WriteString(WellKnownSynchronizationKinds.AnalyzerReference);
objectWriter.WriteString(reference.FullPath);
return Checksum.Create(stream);
}
}
}
}
......@@ -23,16 +23,14 @@ public CustomAsset Build(OptionSet options, string language, CancellationToken c
{
cancellationToken.ThrowIfCancellationRequested();
return new SimpleCustomAsset(WellKnownSynchronizationKinds.OptionSet,
(writer, cancellationTokenOnStreamWriting) =>
return new SimpleCustomAsset(WellKnownSynchronizationKinds.OptionSet,
(writer, cancellationTokenOnStreamWriting) =>
_serializer.SerializeOptionSet(options, language, writer, cancellationTokenOnStreamWriting));
}
public CustomAsset Build(AnalyzerReference reference, CancellationToken cancellationToken)
{
return new SimpleCustomAsset(WellKnownSynchronizationKinds.AnalyzerReference,
(writer, cancellationTokenOnStreamWriting) =>
_serializer.SerializeAnalyzerReference(reference, writer, cancellationTokenOnStreamWriting));
return new WorkspaceAnalyzerReferenceAsset(reference, _serializer);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册