private static ImmutableDictionary <DiagnosticAnalyzer, StateSet> CreateAnalyzerMap( HostAnalyzerManager analyzerManager, string language, IEnumerable <ImmutableArray <DiagnosticAnalyzer> > analyzerCollection) { var compilerAnalyzer = analyzerManager.GetCompilerDiagnosticAnalyzer(language); var builder = ImmutableDictionary.CreateBuilder <DiagnosticAnalyzer, StateSet>(); foreach (var analyzers in analyzerCollection) { foreach (var analyzer in analyzers) { // TODO: // #1, all de -duplication should move to HostAnalyzerManager // #2, not sure whether de-duplication of analyzer itself makes sense. this can only happen // if user deliberately put same analyzer twice. if (builder.ContainsKey(analyzer)) { continue; } var buildToolName = analyzer == compilerAnalyzer ? PredefinedBuildTools.Live : GetBuildToolName(analyzerManager, language, analyzer); builder.Add(analyzer, new StateSet(language, analyzer, buildToolName)); } } return(builder.ToImmutable()); }
/// <summary> /// Return <see cref="StateSet"/>s that are added as the given <see cref="Project"/>'s AnalyzerReferences. /// This will never create new <see cref="StateSet"/> but will return ones already created. /// </summary> public ImmutableArray <StateSet> CreateBuildOnlyProjectStateSet(Project project) { // create project analyzer reference identity map var referenceIdentities = project.AnalyzerReferences.Select(r => _analyzerManager.GetAnalyzerReferenceIdentity(r)).ToSet(); // now create analyzer to host stateset map var hostStateSetMap = _hostStates.GetOrCreateStateSets(project.Language).ToDictionary(s => s.Analyzer, s => s); // create build only stateSet array var stateSets = ImmutableArray.CreateBuilder <StateSet>(); // we always include compiler analyzer in build only state var compilerAnalyzer = _analyzerManager.GetCompilerDiagnosticAnalyzer(project.Language); if (compilerAnalyzer == null) { // only way to get here is if MEF is corrupted. FailFast.OnFatalException(new Exception("How can this happen?")); } StateSet compilerStateSet; if (hostStateSetMap.TryGetValue(compilerAnalyzer, out compilerStateSet)) { stateSets.Add(compilerStateSet); } // now add all project analyzers stateSets.AddRange(_projectStates.GetOrUpdateStateSets(project)); // now add analyzers that exist in both host and project var analyzerMap = _analyzerManager.GetHostDiagnosticAnalyzersPerReference(project.Language); foreach (var kv in analyzerMap) { var identity = kv.Key; if (!referenceIdentities.Contains(identity)) { // it is from host analyzer package rather than project analyzer reference // which build doesn't have continue; } // if same analyzer exists both in host (vsix) and in analyzer reference, // we include it in build only analyzer. foreach (var analyzer in kv.Value) { StateSet stateSet; if (hostStateSetMap.TryGetValue(analyzer, out stateSet) && stateSet != compilerStateSet) { stateSets.Add(stateSet); } } } return(stateSets.ToImmutable()); }
public DiagnosticAnalyzerMap(HostAnalyzerManager analyzerManager, string language, ImmutableDictionary<DiagnosticAnalyzer, StateSet> analyzerMap) { // hold directly on to compiler analyzer _compilerAnalyzer = analyzerManager.GetCompilerDiagnosticAnalyzer(language); // in test case, we might not have the compiler analyzer. if (_compilerAnalyzer == null) { _map = analyzerMap; return; } _compilerStateSet = analyzerMap[_compilerAnalyzer]; // hold rest of analyzers _map = analyzerMap.Remove(_compilerAnalyzer); }
public DiagnosticAnalyzerMap(HostAnalyzerManager analyzerManager, string language, ImmutableDictionary <DiagnosticAnalyzer, StateSet> analyzerMap) { // hold directly on to compiler analyzer _compilerAnalyzer = analyzerManager.GetCompilerDiagnosticAnalyzer(language); // in test case, we might not have the compiler analyzer. if (_compilerAnalyzer == null) { _map = analyzerMap; return; } _compilerStateSet = analyzerMap[_compilerAnalyzer]; // hold rest of analyzers _map = analyzerMap.Remove(_compilerAnalyzer); }
public DiagnosticAnalyzerMap(HostAnalyzerManager analyzerManager, string language, ImmutableDictionary <DiagnosticAnalyzer, StateSet> analyzerMap) { _map = analyzerMap; var compilerAnalyzer = analyzerManager.GetCompilerDiagnosticAnalyzer(language); // in test case, we might not have the compiler analyzer. if (compilerAnalyzer != null) { // hold onto stateSet for compiler analyzer _compilerStateSet = analyzerMap[compilerAnalyzer]; } // order statesets // order will be in this order // BuiltIn Compiler Analyzer (C#/VB) < Regular DiagnosticAnalyzers < Document/ProjectDiagnosticAnalyzers _orderedSet = _map.Values.OrderBy(PriorityComparison).ToImmutableArray(); }
/// <summary> /// Return <see cref="StateSet"/>s that are added as the given <see cref="Project"/>'s AnalyzerReferences. /// This will never create new <see cref="StateSet"/> but will return ones already created. /// </summary> public ImmutableArray <StateSet> CreateBuildOnlyProjectStateSet(Project project) { var referenceIdentities = project.AnalyzerReferences.Select(r => _analyzerManager.GetAnalyzerReferenceIdentity(r)).ToSet(); var stateSetMap = GetStateSets(project).ToDictionary(s => s.Analyzer, s => s); var stateSets = ImmutableArray.CreateBuilder <StateSet>(); // we always include compiler analyzer in build only state var compilerAnalyzer = _analyzerManager.GetCompilerDiagnosticAnalyzer(project.Language); StateSet compilerStateSet; if (stateSetMap.TryGetValue(compilerAnalyzer, out compilerStateSet)) { stateSets.Add(compilerStateSet); } var analyzerMap = _analyzerManager.GetHostDiagnosticAnalyzersPerReference(project.Language); foreach (var kv in analyzerMap) { var identity = kv.Key; if (!referenceIdentities.Contains(identity)) { // it is from host analyzer package rather than project analyzer reference // which build doesn't have continue; } // if same analyzer exists both in host (vsix) and in analyzer reference, // we include it in build only analyzer. foreach (var analyzer in kv.Value) { StateSet stateSet; if (stateSetMap.TryGetValue(analyzer, out stateSet) && stateSet != compilerStateSet) { stateSets.Add(stateSet); } } } return(stateSets.ToImmutable()); }
private static ImmutableDictionary<DiagnosticAnalyzer, StateSet> CreateAnalyzerMap( HostAnalyzerManager analyzerManager, string language, IEnumerable<ImmutableArray<DiagnosticAnalyzer>> analyzerCollection) { var compilerAnalyzer = analyzerManager.GetCompilerDiagnosticAnalyzer(language); var builder = ImmutableDictionary.CreateBuilder<DiagnosticAnalyzer, StateSet>(); foreach (var analyzers in analyzerCollection) { foreach (var analyzer in analyzers) { // TODO: // #1, all de -duplication should move to HostAnalyzerManager // #2, not sure whether de-duplication of analyzer itself makes sense. this can only happen // if user deliberately put same analyzer twice. if (builder.ContainsKey(analyzer)) { continue; } var buildToolName = analyzer == compilerAnalyzer ? PredefinedBuildTools.Live : GetBuildToolName(analyzerManager, language, analyzer); builder.Add(analyzer, new StateSet(language, analyzer, buildToolName)); } } return builder.ToImmutable(); }