public ImmutableArray <StateSet> CreateBuildOnlyProjectStateSet(Project project)
            {
                var projectStateSets = project.SupportsCompilation ?
                                       GetOrUpdateProjectStateSets(project) :
                                       ProjectAnalyzerStateSets.Default;
                var hostStateSets = GetOrCreateHostStateSets(project.Language, projectStateSets);

                if (!project.SupportsCompilation)
                {
                    // languages which don't use our compilation model but diagnostic framework,
                    // all their analyzer should be host analyzers. return all host analyzers
                    // for the language
                    return(hostStateSets.OrderedStateSets);
                }

                var hostStateSetMap = hostStateSets.StateSetMap;

                // create project analyzer reference identity map
                var projectAnalyzerReferenceIds = project.AnalyzerReferences.Select(r => r.Id).ToSet();

                // create build only stateSet array
                var stateSets = ImmutableArray.CreateBuilder <StateSet>();

                // include compiler analyzer in build only state, if available
                StateSet?compilerStateSet = null;
                var      compilerAnalyzer = _hostAnalyzers.GetCompilerDiagnosticAnalyzer(project.Language);

                if (compilerAnalyzer != null && hostStateSetMap.TryGetValue(compilerAnalyzer, out compilerStateSet))
                {
                    stateSets.Add(compilerStateSet);
                }

                // now add all project analyzers
                stateSets.AddRange(projectStateSets.StateSetMap.Values);

                // now add analyzers that exist in both host and project
                var hostAnalyzersById = _hostAnalyzers.GetOrCreateHostDiagnosticAnalyzersPerReference(project.Language);

                foreach (var(identity, analyzers) in hostAnalyzersById)
                {
                    if (!projectAnalyzerReferenceIds.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 analyzers)
                    {
                        if (hostStateSetMap.TryGetValue(analyzer, out var stateSet) && stateSet != compilerStateSet)
                        {
                            stateSets.Add(stateSet);
                        }
                    }
                }

                return(stateSets.ToImmutable());
            }
Example #2
0
                static HostAnalyzerStateSets CreateLanguageSpecificAnalyzerMap(string language, HostDiagnosticAnalyzers hostAnalyzers)
                {
                    var analyzersPerReference = hostAnalyzers.GetOrCreateHostDiagnosticAnalyzersPerReference(language);

                    var analyzerMap = CreateStateSetMap(language, analyzersPerReference.Values, includeFileContentLoadAnalyzer: true);

                    VerifyUniqueStateNames(analyzerMap.Values);

                    return(new HostAnalyzerStateSets(analyzerMap));
                }
Example #3
0
                static HostAnalyzerStateSets CreateLanguageSpecificAnalyzerMap(HostAnalyzerStateSetKey arg, HostDiagnosticAnalyzers hostAnalyzers)
                {
                    var language = arg.Language;
                    var analyzersPerReference = hostAnalyzers.GetOrCreateHostDiagnosticAnalyzersPerReference(language);

                    var analyzerMap = CreateStateSetMap(language, analyzersPerReference.Values, includeWorkspacePlaceholderAnalyzers: true);

                    VerifyUniqueStateNames(analyzerMap.Values);

                    return(new HostAnalyzerStateSets(analyzerMap));
                }