Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@ private ProjectAnalyzerInfo GetOrCreateProjectAnalyzerInfo(Project project)
private ProjectAnalyzerInfo CreateProjectAnalyzerInfo(Project project)
{
if (project.AnalyzerReferences.Count == 0)
{
return ProjectAnalyzerInfo.Default;
}

var solutionAnalyzers = project.Solution.SolutionState.Analyzers;
var analyzersPerReference = solutionAnalyzers.CreateProjectDiagnosticAnalyzersPerReference(project.State);
if (analyzersPerReference.Count == 0)
{
return ProjectAnalyzerInfo.Default;
}

var (newHostAnalyzers, newAllAnalyzers) = PartitionAnalyzers(
[.. analyzersPerReference.Values], hostAnalyzerCollection: [], includeWorkspacePlaceholderAnalyzers: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ bool ShouldIncludeAnalyzer(Project project, DiagnosticAnalyzer analyzer)
}
}

public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(
public Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(
Project project, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
{
var analyzers = GetDiagnosticAnalyzers(project, diagnosticIds, shouldIncludeAnalyzer);

return await ProduceProjectDiagnosticsAsync(
return ProduceProjectDiagnosticsAsync(
project, analyzers, diagnosticIds,
// Ensure we compute and return diagnostics for both the normal docs and the additional docs in this
// project if no specific document id was requested.
Expand All @@ -158,23 +158,23 @@ public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(
includeNonLocalDocumentDiagnostics,
// return diagnostics specific to one project or document
includeProjectNonLocalResult: documentId == null,
cancellationToken).ConfigureAwait(false);
cancellationToken);
}

public async Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(
public Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(
Project project, ImmutableHashSet<string>? diagnosticIds,
Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer,
bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
{
var analyzers = GetDiagnosticAnalyzers(project, diagnosticIds, shouldIncludeAnalyzer);

return await ProduceProjectDiagnosticsAsync(
return ProduceProjectDiagnosticsAsync(
project, analyzers, diagnosticIds,
documentIds: [],
includeLocalDocumentDiagnostics: false,
includeNonLocalDocumentDiagnostics: includeNonLocalDocumentDiagnostics,
includeProjectNonLocalResult: true,
cancellationToken).ConfigureAwait(false);
cancellationToken);
}

public TestAccessor GetTestAccessor()
Expand All @@ -187,6 +187,6 @@ public ImmutableArray<DiagnosticAnalyzer> GetAnalyzers(Project project)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view with whitespace off.

public Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeProjectInProcessAsync(
Project project, CompilationWithAnalyzersPair compilationWithAnalyzers, bool logPerformanceInfo, bool getTelemetryInfo, CancellationToken cancellationToken)
=> service.AnalyzeProjectInProcessAsync(project, compilationWithAnalyzers, logPerformanceInfo, getTelemetryInfo, cancellationToken);
=> service.AnalyzeInProcessAsync(documentAnalysisScope: null, project, compilationWithAnalyzers, logPerformanceInfo, getTelemetryInfo, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,30 @@ private static readonly ConditionalWeakTable<
return true;
};

// in IDE, we always set concurrentAnalysis == false otherwise, we can get into thread starvation due to
// async being used with synchronous blocking concurrency.
var projectCompilation = !filteredProjectAnalyzers.Any()
? null
: compilation.WithAnalyzers(filteredProjectAnalyzers, new CompilationWithAnalyzersOptions(
options: project.State.ProjectAnalyzerOptions,
onAnalyzerException: null,
analyzerExceptionFilter: exceptionFilter,
concurrentAnalysis: false,
logAnalyzerExecutionTime: true,
reportSuppressedDiagnostics: true));

var hostCompilation = !filteredHostAnalyzers.Any()
? null
: compilation.WithAnalyzers(filteredHostAnalyzers, new CompilationWithAnalyzersOptions(
options: project.HostAnalyzerOptions,
onAnalyzerException: null,
analyzerExceptionFilter: exceptionFilter,
concurrentAnalysis: false,
logAnalyzerExecutionTime: true,
reportSuppressedDiagnostics: true));

// Create driver that holds onto compilation and associated analyzers
return new CompilationWithAnalyzersPair(projectCompilation, hostCompilation);
return new(
CreateCompilationWithAnalyzers(compilation, filteredProjectAnalyzers, project.State.ProjectAnalyzerOptions, exceptionFilter),
CreateCompilationWithAnalyzers(compilation, filteredHostAnalyzers, project.HostAnalyzerOptions, exceptionFilter));
}

static CompilationWithAnalyzers? CreateCompilationWithAnalyzers(
Compilation compilation,
ImmutableArray<DiagnosticAnalyzer> analyzers,
AnalyzerOptions? options,
Func<Exception, bool> exceptionFilter)
{
if (analyzers.Length == 0)
return null;

return compilation.WithAnalyzers(analyzers, new CompilationWithAnalyzersOptions(
options: options,
onAnalyzerException: null,
analyzerExceptionFilter: exceptionFilter,
// in IDE, we always set concurrentAnalysis == false otherwise, we can get into thread starvation due to
// async being used with synchronous blocking concurrency.
concurrentAnalysis: false,
logAnalyzerExecutionTime: true,
reportSuppressedDiagnostics: true));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Co
|| compilationWithAnalyzers?.HostAnalyzers.Length > 0)
{
// calculate regular diagnostic analyzers diagnostics
var resultMap = await this.AnalyzeProjectInProcessAsync(
project, compilationWithAnalyzers, logPerformanceInfo: false, getTelemetryInfo: true, cancellationToken).ConfigureAwait(false);
var resultMap = await this.AnalyzeInProcessAsync(
documentAnalysisScope: null, project, compilationWithAnalyzers, logPerformanceInfo: false, getTelemetryInfo: true, cancellationToken).ConfigureAwait(false);

result = resultMap.AnalysisResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ namespace Microsoft.CodeAnalysis.Diagnostics;

internal sealed partial class DiagnosticAnalyzerService
{
private Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeDocumentInProcessAsync(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inlined these methods.

DocumentAnalysisScope documentAnalysisScope,
CompilationWithAnalyzersPair compilationWithAnalyzers,
bool logPerformanceInfo,
bool getTelemetryInfo,
CancellationToken cancellationToken)
=> AnalyzeInProcessAsync(documentAnalysisScope, documentAnalysisScope.TextDocument.Project, compilationWithAnalyzers, logPerformanceInfo, getTelemetryInfo, cancellationToken);

private Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeProjectInProcessAsync(
Project project,
CompilationWithAnalyzersPair compilationWithAnalyzers,
bool logPerformanceInfo,
bool getTelemetryInfo,
CancellationToken cancellationToken)
=> AnalyzeInProcessAsync(documentAnalysisScope: null, project, compilationWithAnalyzers, logPerformanceInfo, getTelemetryInfo, cancellationToken);

private async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeInProcessAsync(
DocumentAnalysisScope? documentAnalysisScope,
Project project,
Expand Down
Loading
Loading