private static bool ShouldRunAnalyzerForStateType(DiagnosticAnalyzer analyzer, StateType stateTypeId, ImmutableHashSet <string> diagnosticIds = null, Func <DiagnosticAnalyzer, ImmutableArray <DiagnosticDescriptor> > getDescriptors = null) { // PERF: Don't query descriptors for compiler analyzer, always execute it for all state types. if (analyzer.IsCompilerAnalyzer()) { return(true); } if (diagnosticIds != null && getDescriptors(analyzer).All(d => !diagnosticIds.Contains(d.Id))) { return(false); } switch (stateTypeId) { case StateType.Syntax: return(analyzer.SupportsSyntaxDiagnosticAnalysis()); case StateType.Document: return(analyzer.SupportsSemanticDiagnosticAnalysis()); case StateType.Project: return(analyzer.SupportsProjectDiagnosticAnalysis()); default: throw ExceptionUtilities.Unreachable; } }
private static bool ShouldRunAnalyzerForStateType(DiagnosticAnalyzerDriver driver, DiagnosticAnalyzer analyzer, StateType stateTypeId, out bool supportsSemanticInSpan, ImmutableHashSet <string> diagnosticIds = null, Func <DiagnosticAnalyzer, ImmutableArray <DiagnosticDescriptor> > getDescriptor = null) { Debug.Assert(!driver.IsAnalyzerSuppressed(analyzer)); supportsSemanticInSpan = false; if (diagnosticIds != null && getDescriptor(analyzer).All(d => !diagnosticIds.Contains(d.Id))) { return(false); } switch (stateTypeId) { case StateType.Syntax: return(analyzer.SupportsSyntaxDiagnosticAnalysis(driver)); case StateType.Document: return(analyzer.SupportsSemanticDiagnosticAnalysis(driver, out supportsSemanticInSpan)); case StateType.Project: return(analyzer.SupportsProjectDiagnosticAnalysis(driver)); default: throw ExceptionUtilities.Unreachable; } }
public async Task <IEnumerable <Diagnostic> > GetProjectDiagnosticsAsync(DiagnosticAnalyzer analyzer, Action <Project, DiagnosticAnalyzer, CancellationToken> forceAnalyzeAllDocuments) { Contract.ThrowIfNull(_project); Contract.ThrowIfFalse(_document == null); Contract.ThrowIfFalse(analyzer.SupportsProjectDiagnosticAnalysis(this)); using (var diagnostics = SharedPools.Default <List <Diagnostic> >().GetPooledObject()) { if (_project.SupportsCompilation) { await this.GetCompilationDiagnosticsAsync(analyzer, diagnostics.Object, forceAnalyzeAllDocuments).ConfigureAwait(false); } await this.GetProjectDiagnosticsWorkerAsync(analyzer, diagnostics.Object).ConfigureAwait(false); return(diagnostics.Object.ToImmutableArray()); } }
private static bool ShouldRunAnalyzerForStateType(DiagnosticAnalyzer analyzer, StateType stateTypeId, ImmutableHashSet<string> diagnosticIds = null, Func<DiagnosticAnalyzer, ImmutableArray<DiagnosticDescriptor>> getDescriptors = null) { if (diagnosticIds != null && getDescriptors(analyzer).All(d => !diagnosticIds.Contains(d.Id))) { return false; } switch (stateTypeId) { case StateType.Syntax: return analyzer.SupportsSyntaxDiagnosticAnalysis(); case StateType.Document: return analyzer.SupportsSemanticDiagnosticAnalysis(); case StateType.Project: return analyzer.SupportsProjectDiagnosticAnalysis(); default: throw ExceptionUtilities.Unreachable; } }
private static bool ShouldRunProviderForStateType(StateType stateTypeId, DiagnosticAnalyzer provider, DiagnosticAnalyzerDriver driver, out bool supportsSemanticInSpan, ImmutableHashSet<string> diagnosticIds = null, Func<DiagnosticAnalyzer, ImmutableArray<DiagnosticDescriptor>> getDescriptor = null) { Debug.Assert(!IsAnalyzerSuppressed(provider, driver.Project.CompilationOptions, driver)); supportsSemanticInSpan = false; if (diagnosticIds != null && getDescriptor(provider).All(d => !diagnosticIds.Contains(d.Id))) { return false; } switch (stateTypeId) { case StateType.Syntax: return provider.SupportsSyntaxDiagnosticAnalysis(driver); case StateType.Document: return provider.SupportsSemanticDiagnosticAnalysis(driver, out supportsSemanticInSpan); case StateType.Project: return provider.SupportsProjectDiagnosticAnalysis(driver); default: throw ExceptionUtilities.Unreachable; } }
public async Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(DiagnosticAnalyzer analyzer, Action<Project, DiagnosticAnalyzer, CancellationToken> forceAnalyzeAllDocuments) { Contract.ThrowIfNull(_project); Contract.ThrowIfFalse(_document == null); Contract.ThrowIfFalse(analyzer.SupportsProjectDiagnosticAnalysis(this)); using (var diagnostics = SharedPools.Default<List<Diagnostic>>().GetPooledObject()) { if (_project.SupportsCompilation) { await this.GetCompilationDiagnosticsAsync(analyzer, diagnostics.Object, forceAnalyzeAllDocuments).ConfigureAwait(false); } await this.GetProjectDiagnosticsWorkerAsync(analyzer, diagnostics.Object).ConfigureAwait(false); return diagnostics.Object.ToImmutableArray(); } }