Skip to content

Commit

Permalink
Merge pull request #65813 from sharwell/analysis-scope
Browse files Browse the repository at this point in the history
Link compiler analysis scope to solution-specific override
  • Loading branch information
sharwell authored Dec 6, 2022
2 parents 54a5024 + 05f29ce commit ec4bbb9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static bool IsAnalyzerEnabledForProject(DiagnosticAnalyzer analyzer, Proj

if (analyzer.IsCompilerAnalyzer())
{
return globalOptions.GetOption(SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption, project.Language) != CompilerDiagnosticsScope.None;
return globalOptions.GetBackgroundCompilerAnalysisScope(project.Language) != CompilerDiagnosticsScope.None;
}

// Check if user has disabled analyzer execution for this project or via options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private async Task AnalyzeDocumentForKindAsync(TextDocument document, AnalysisKi
var compilationWithAnalyzers = await GetOrCreateCompilationWithAnalyzersAsync(document.Project, stateSets, cancellationToken).ConfigureAwait(false);
var version = await GetDiagnosticVersionAsync(document.Project, cancellationToken).ConfigureAwait(false);
var backgroundAnalysisScope = GlobalOptions.GetBackgroundAnalysisScope(document.Project.Language);
var compilerDiagnosticsScope = GlobalOptions.GetOption(SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption, document.Project.Language);
var compilerDiagnosticsScope = GlobalOptions.GetBackgroundCompilerAnalysisScope(document.Project.Language);

// TODO: Switch to a more reliable service to determine visible documents.
// DocumentTrackingService is known be unreliable at times.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ public static BackgroundAnalysisScope GetBackgroundAnalysisScope(this IGlobalOpt
globalOptions.GetOption(BackgroundAnalysisScopeOption, language);
}

/// <summary>
/// <para>Gets the effective background compiler analysis scope for the current solution.</para>
///
/// <para>Gets the solution-specific analysis scope set through
/// <see cref="SolutionBackgroundAnalysisScopeOption"/>, or the default compiler analysis scope if no
/// solution-specific scope is set.</para>
/// </summary>
public static CompilerDiagnosticsScope GetBackgroundCompilerAnalysisScope(this IGlobalOptionService globalOptions, string language)
{
if (LowMemoryForcedMinimalBackgroundAnalysis)
{
return CompilerDiagnosticsScope.VisibleFilesAndFilesWithPreviouslyReportedDiagnostics;
}

return globalOptions.GetOption(SolutionBackgroundAnalysisScopeOption) switch
{
BackgroundAnalysisScope.ActiveFile => CompilerDiagnosticsScope.VisibleFilesAndFilesWithPreviouslyReportedDiagnostics,
BackgroundAnalysisScope.OpenFiles => CompilerDiagnosticsScope.OpenFiles,
BackgroundAnalysisScope.FullSolution => CompilerDiagnosticsScope.FullSolution,
BackgroundAnalysisScope.None => CompilerDiagnosticsScope.None,
_ => globalOptions.GetOption(CompilerDiagnosticsScopeOption, language),
};
}

/// <summary>
/// Returns true if full solution analysis is enabled for the given
/// <paramref name="analyzer"/> through options for the given <paramref name="language"/>.
Expand All @@ -73,7 +97,7 @@ public static bool IsFullSolutionAnalysisEnabled(this DiagnosticAnalyzer analyze
{
if (analyzer.IsCompilerAnalyzer())
{
return globalOptions.GetOption(CompilerDiagnosticsScopeOption, language) == CompilerDiagnosticsScope.FullSolution;
return GetBackgroundCompilerAnalysisScope(globalOptions, language) == CompilerDiagnosticsScope.FullSolution;
}

return GetBackgroundAnalysisScope(globalOptions, language) == BackgroundAnalysisScope.FullSolution;
Expand Down Expand Up @@ -121,7 +145,7 @@ public static bool IsFullSolutionAnalysisEnabled(
out bool compilerFullSolutionAnalysisEnabled,
out bool analyzersFullSolutionAnalysisEnabled)
{
compilerFullSolutionAnalysisEnabled = globalOptions.GetOption(CompilerDiagnosticsScopeOption, language) == CompilerDiagnosticsScope.FullSolution;
compilerFullSolutionAnalysisEnabled = GetBackgroundCompilerAnalysisScope(globalOptions, language) == CompilerDiagnosticsScope.FullSolution;
analyzersFullSolutionAnalysisEnabled = GetBackgroundAnalysisScope(globalOptions, language) == BackgroundAnalysisScope.FullSolution;
return compilerFullSolutionAnalysisEnabled || analyzersFullSolutionAnalysisEnabled;
}
Expand All @@ -135,7 +159,7 @@ public static bool IsAnalysisDisabled(
this IGlobalOptionService globalOptions,
string language)
{
var compilerDiagnosticsDisabled = globalOptions.GetOption(CompilerDiagnosticsScopeOption, language) == CompilerDiagnosticsScope.None;
var compilerDiagnosticsDisabled = GetBackgroundCompilerAnalysisScope(globalOptions, language) == CompilerDiagnosticsScope.None;
var analyzersDisabled = GetBackgroundAnalysisScope(globalOptions, language) == BackgroundAnalysisScope.None;
return compilerDiagnosticsDisabled && analyzersDisabled;
}
Expand Down

0 comments on commit ec4bbb9

Please sign in to comment.