提交 9d3d34ed 编写于 作者: H Heejae Chang 提交者: GitHub

Merge pull request #15795 from heejaechang/removeOptions

clean up code that no longer needed
......@@ -1939,9 +1939,9 @@ class MyClass
' Get cached project diagnostics.
Dim diagnostics = diagnosticService.GetCachedDiagnosticsAsync(workspace, project.Id).WaitAndGetResult(CancellationToken.None)
' different behavior between v1 and v2. in v2. in v2, solution crawler never creates non-local hidden diagnostics.
' in v2, solution crawler never creates non-local hidden diagnostics.
' v2 still creates those for LB and explicit queries such as FixAll.
Dim expectedCount = If(workspace.Options.GetOption(InternalDiagnosticsOptions.UseDiagnosticEngineV2), 0, 1)
Dim expectedCount = 0
Assert.Equal(expectedCount, diagnostics.Count())
' Get diagnostics explicitly
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics.EngineV2;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Options;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Diagnostics
{
[ExportIncrementalAnalyzerProvider(
highPriorityForActiveFile: true, name: WellKnownSolutionCrawlerAnalyzers.Diagnostic,
highPriorityForActiveFile: true, name: WellKnownSolutionCrawlerAnalyzers.Diagnostic,
workspaceKinds: new string[] { WorkspaceKind.Host, WorkspaceKind.Interactive, WorkspaceKind.AnyCodeRoslynWorkspace })]
internal partial class DiagnosticAnalyzerService : IIncrementalAnalyzerProvider
{
......@@ -58,182 +51,13 @@ private BaseDiagnosticIncrementalAnalyzer CreateIncrementalAnalyzerCallback(Work
{
// subscribe to active context changed event for new workspace
workspace.DocumentActiveContextChanged += OnDocumentActiveContextChanged;
return new IncrementalAnalyzerDelegatee(this, workspace, _hostAnalyzerManager, _hostDiagnosticUpdateSource);
return new DiagnosticIncrementalAnalyzer(this, LogAggregator.GetNextId(), workspace, _hostAnalyzerManager, _hostDiagnosticUpdateSource);
}
private void OnDocumentActiveContextChanged(object sender, DocumentActiveContextChangedEventArgs e)
{
Reanalyze(e.Solution.Workspace, documentIds: SpecializedCollections.SingletonEnumerable(e.NewActiveContextDocumentId), highPriority: true);
}
// internal for testing
internal class IncrementalAnalyzerDelegatee : BaseDiagnosticIncrementalAnalyzer
{
// v2 diagnostic engine - for now v1
private readonly EngineV2.DiagnosticIncrementalAnalyzer _engineV2;
public IncrementalAnalyzerDelegatee(DiagnosticAnalyzerService owner, Workspace workspace, HostAnalyzerManager hostAnalyzerManager, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
: base(owner, workspace, hostAnalyzerManager, hostDiagnosticUpdateSource)
{
var v2CorrelationId = LogAggregator.GetNextId();
_engineV2 = new EngineV2.DiagnosticIncrementalAnalyzer(owner, v2CorrelationId, workspace, hostAnalyzerManager, hostDiagnosticUpdateSource);
}
#region IIncrementalAnalyzer
public override Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
return Analyzer.AnalyzeSyntaxAsync(document, reasons, cancellationToken);
}
public override Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
return Analyzer.AnalyzeDocumentAsync(document, bodyOpt, reasons, cancellationToken);
}
public override Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
return Analyzer.AnalyzeProjectAsync(project, semanticsChanged, reasons, cancellationToken);
}
public override Task DocumentOpenAsync(Document document, CancellationToken cancellationToken)
{
return Analyzer.DocumentOpenAsync(document, cancellationToken);
}
public override Task DocumentCloseAsync(Document document, CancellationToken cancellationToken)
{
return Analyzer.DocumentCloseAsync(document, cancellationToken);
}
public override Task DocumentResetAsync(Document document, CancellationToken cancellationToken)
{
return Analyzer.DocumentResetAsync(document, cancellationToken);
}
public override Task NewSolutionSnapshotAsync(Solution solution, CancellationToken cancellationToken)
{
return Analyzer.NewSolutionSnapshotAsync(solution, cancellationToken);
}
public override void RemoveDocument(DocumentId documentId)
{
Analyzer.RemoveDocument(documentId);
}
public override void RemoveProject(ProjectId projectId)
{
Analyzer.RemoveProject(projectId);
}
public override bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs e)
{
return e.Option.Feature == nameof(SimplificationOptions) ||
e.Option.Feature == nameof(CodeStyleOptions) ||
e.Option == ServiceFeatureOnOffOptions.ClosedFileDiagnostic ||
e.Option == RuntimeOptions.FullSolutionAnalysis ||
e.Option == InternalDiagnosticsOptions.UseDiagnosticEngineV2 ||
Analyzer.NeedsReanalysisOnOptionChanged(sender, e);
}
#endregion
#region delegating methods from diagnostic analyzer service to each implementation of the engine
public override Task<ImmutableArray<DiagnosticData>> GetCachedDiagnosticsAsync(Solution solution, ProjectId projectId = null, DocumentId documentId = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Analyzer.GetCachedDiagnosticsAsync(solution, projectId, documentId, includeSuppressedDiagnostics, cancellationToken);
}
public override Task<ImmutableArray<DiagnosticData>> GetSpecificCachedDiagnosticsAsync(Solution solution, object id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Analyzer.GetSpecificCachedDiagnosticsAsync(solution, id, includeSuppressedDiagnostics, cancellationToken);
}
public override Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Solution solution, ProjectId projectId = null, DocumentId documentId = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Analyzer.GetDiagnosticsAsync(solution, projectId, documentId, includeSuppressedDiagnostics, cancellationToken);
}
public override Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(Solution solution, object id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Analyzer.GetSpecificDiagnosticsAsync(solution, id, includeSuppressedDiagnostics, cancellationToken);
}
public override Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId = null, DocumentId documentId = null, ImmutableHashSet<string> diagnosticIds = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Analyzer.GetDiagnosticsForIdsAsync(solution, projectId, documentId, diagnosticIds, includeSuppressedDiagnostics, cancellationToken);
}
public override Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(Solution solution, ProjectId projectId = null, ImmutableHashSet<string> diagnosticIds = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Analyzer.GetProjectDiagnosticsForIdsAsync(solution, projectId, diagnosticIds, includeSuppressedDiagnostics, cancellationToken);
}
public override Task<bool> TryAppendDiagnosticsForSpanAsync(Document document, TextSpan range, List<DiagnosticData> diagnostics, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Analyzer.TryAppendDiagnosticsForSpanAsync(document, range, diagnostics, includeSuppressedDiagnostics, cancellationToken);
}
public override Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsync(Document document, TextSpan range, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
{
return Analyzer.GetDiagnosticsForSpanAsync(document, range, includeSuppressedDiagnostics, cancellationToken);
}
public override bool ContainsDiagnostics(Workspace workspace, ProjectId projectId)
{
return Analyzer.ContainsDiagnostics(workspace, projectId);
}
#endregion
#region build synchronization
public override Task SynchronizeWithBuildAsync(Workspace workspace, ImmutableDictionary<ProjectId, ImmutableArray<DiagnosticData>> diagnostics)
{
return Analyzer.SynchronizeWithBuildAsync(workspace, diagnostics);
}
#endregion
public override void Shutdown()
{
Analyzer.Shutdown();
}
public override void LogAnalyzerCountSummary()
{
Analyzer.LogAnalyzerCountSummary();
}
public void TurnOff(bool useV2)
{
// Uncomment the below when we add a v3 engine.
//var turnedOffAnalyzer = GetAnalyzer(!useV2);
//foreach (var project in Workspace.CurrentSolution.Projects)
//{
// foreach (var document in project.Documents)
// {
// turnedOffAnalyzer.RemoveDocument(document.Id);
// }
// turnedOffAnalyzer.RemoveProject(project.Id);
//}
}
// internal for testing
internal BaseDiagnosticIncrementalAnalyzer Analyzer
{
get
{
var option = Workspace.Options.GetOption(InternalDiagnosticsOptions.UseDiagnosticEngineV2);
return GetAnalyzer(option);
}
}
private BaseDiagnosticIncrementalAnalyzer GetAnalyzer(bool useV2)
{
// v1 engine has been removed, always use v2 engine (until v3 engine is added).
//return useV2 ? (BaseDiagnosticIncrementalAnalyzer)_engineV2 : _engineV1;
return (BaseDiagnosticIncrementalAnalyzer)_engineV2;
}
}
}
}
......@@ -6,8 +6,12 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Options;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Workspaces.Diagnostics;
using Roslyn.Utilities;
......@@ -56,6 +60,14 @@ public override bool ContainsDiagnostics(Workspace workspace, ProjectId projectI
return false;
}
public override bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs e)
{
return e.Option.Feature == nameof(SimplificationOptions) ||
e.Option.Feature == nameof(CodeStyleOptions) ||
e.Option == ServiceFeatureOnOffOptions.ClosedFileDiagnostic ||
e.Option == RuntimeOptions.FullSolutionAnalysis;
}
private bool SupportAnalysisKind(DiagnosticAnalyzer analyzer, string language, AnalysisKind kind)
{
// compiler diagnostic analyzer always support all kinds
......
......@@ -111,12 +111,12 @@ private ImmutableArray<DiagnosticData> GetDiagnostics(DiagnosticAnalysisResult r
private bool PreferBuildErrors(Workspace workspace)
{
return workspace.Options.GetOption(InternalDiagnosticsOptions.BuildErrorIsTheGod) || workspace.Options.GetOption(InternalDiagnosticsOptions.PreferBuildErrorsOverLiveErrors);
return workspace.Options.GetOption(InternalDiagnosticsOptions.PreferBuildErrorsOverLiveErrors);
}
private bool PreferLiveErrorsOnOpenedFiles(Workspace workspace)
{
return !workspace.Options.GetOption(InternalDiagnosticsOptions.BuildErrorIsTheGod) && workspace.Options.GetOption(InternalDiagnosticsOptions.PreferLiveErrorsOnOpenedFiles);
return workspace.Options.GetOption(InternalDiagnosticsOptions.PreferLiveErrorsOnOpenedFiles);
}
private ImmutableArray<DiagnosticData> MergeDiagnostics(ImmutableArray<DiagnosticData> newDiagnostics, ImmutableArray<DiagnosticData> existingDiagnostics)
......
......@@ -12,11 +12,8 @@ internal class InternalDiagnosticsOptionsProvider : IOptionProvider
{
public ImmutableArray<IOption> Options { get; } = ImmutableArray.Create<IOption>(
InternalDiagnosticsOptions.BlueSquiggleForBuildDiagnostic,
InternalDiagnosticsOptions.UseDiagnosticEngineV2,
InternalDiagnosticsOptions.CompilationEndCodeFix,
InternalDiagnosticsOptions.UseCompilationEndCodeFixHeuristic,
InternalDiagnosticsOptions.BuildErrorIsTheGod,
InternalDiagnosticsOptions.ClearLiveErrorsForProjectBuilt,
InternalDiagnosticsOptions.PreferLiveErrorsOnOpenedFiles,
InternalDiagnosticsOptions.PreferBuildErrorsOverLiveErrors);
}
......
......@@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Diagnostics.EngineV2;
using Microsoft.CodeAnalysis.Internal.Log;
using Roslyn.Utilities;
......@@ -250,7 +250,7 @@ public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId,
foreach (var analyzer in analyzers)
{
var diagIncrementalAnalyzer = analyzer as DiagnosticAnalyzerService.IncrementalAnalyzerDelegatee;
var diagIncrementalAnalyzer = analyzer as DiagnosticIncrementalAnalyzer;
if (diagIncrementalAnalyzer != null)
{
diagIncrementalAnalyzer.LogAnalyzerCountSummary();
......
......@@ -111,18 +111,6 @@ public void Shutdown()
_lowPriorityProcessor.Shutdown();
}
// TODO: delete this once prototyping is done
public void ChangeDiagnosticsEngine(bool useV2Engine)
{
var diagnosticAnalyzer = Analyzers.FirstOrDefault(a => a is BaseDiagnosticIncrementalAnalyzer) as DiagnosticAnalyzerService.IncrementalAnalyzerDelegatee;
if (diagnosticAnalyzer == null)
{
return;
}
diagnosticAnalyzer.TurnOff(useV2Engine);
}
public ImmutableArray<IIncrementalAnalyzer> Analyzers => _normalPriorityProcessor.Analyzers;
private Solution CurrentSolution => _registration.CurrentSolution;
......
......@@ -149,12 +149,6 @@ private void OnOptionChanged(object sender, OptionChangedEventArgs e)
return;
}
// Changing the UseV2Engine option is a no-op as we have a single engine now.
if (e.Option == Diagnostics.InternalDiagnosticsOptions.UseDiagnosticEngineV2)
{
_documentAndProjectWorkerProcessor.ChangeDiagnosticsEngine((bool)e.Value);
}
ReanalyzeOnOptionChange(sender, e);
}
......
......@@ -206,7 +206,7 @@ internal void OnSolutionBuild(object sender, UIContextChangedEventArgs e)
var diagnosticService = _diagnosticService as DiagnosticAnalyzerService;
if (diagnosticService != null)
{
await CleanupAllLiveErrorsIfNeededAsync(diagnosticService, inprogressState.Solution, inprogressState).ConfigureAwait(false);
await CleanupAllLiveErrors(diagnosticService, inprogressState.GetProjectsWithoutErrors(inprogressState.Solution)).ConfigureAwait(false);
await SyncBuildErrorsAndReportAsync(diagnosticService, inprogressState.Solution, inprogressState.GetLiveDiagnosticsPerProject(liveDiagnosticChecker)).ConfigureAwait(false);
}
......@@ -215,24 +215,6 @@ internal void OnSolutionBuild(object sender, UIContextChangedEventArgs e)
}).CompletesAsyncOperation(asyncToken);
}
private async System.Threading.Tasks.Task CleanupAllLiveErrorsIfNeededAsync(DiagnosticAnalyzerService diagnosticService, Solution solution, InprogressState state)
{
if (_workspace.Options.GetOption(InternalDiagnosticsOptions.BuildErrorIsTheGod))
{
await CleanupAllLiveErrors(diagnosticService, solution.ProjectIds).ConfigureAwait(false);
return;
}
if (_workspace.Options.GetOption(InternalDiagnosticsOptions.ClearLiveErrorsForProjectBuilt))
{
await CleanupAllLiveErrors(diagnosticService, state.GetProjectsBuilt(solution)).ConfigureAwait(false);
return;
}
await CleanupAllLiveErrors(diagnosticService, state.GetProjectsWithoutErrors(solution)).ConfigureAwait(false);
return;
}
private System.Threading.Tasks.Task CleanupAllLiveErrors(DiagnosticAnalyzerService diagnosticService, IEnumerable<ProjectId> projects)
{
var map = projects.ToImmutableDictionary(p => p, _ => ImmutableArray<DiagnosticData>.Empty);
......
......@@ -11,21 +11,12 @@ internal static class InternalDiagnosticsOptions
public static readonly Option<bool> BlueSquiggleForBuildDiagnostic = new Option<bool>(nameof(InternalDiagnosticsOptions), "Blue Squiggle For Build Diagnostic", defaultValue: false,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "Blue Squiggle For Build Diagnostic"));
public static readonly Option<bool> UseDiagnosticEngineV2 = new Option<bool>(nameof(InternalDiagnosticsOptions), "Use Diagnostic Engine V2", defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "Use Diagnostic Engine V2"));
public static readonly Option<bool> CompilationEndCodeFix = new Option<bool>(nameof(InternalDiagnosticsOptions), "Enable Compilation End Code Fix", defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "Enable Compilation End Code Fix"));
public static readonly Option<bool> UseCompilationEndCodeFixHeuristic = new Option<bool>(nameof(InternalDiagnosticsOptions), "Enable Compilation End Code Fix With Heuristic", defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "Enable Compilation End Code Fix With Heuristic"));
public static readonly Option<bool> BuildErrorIsTheGod = new Option<bool>(nameof(InternalDiagnosticsOptions), "Make build errors to take over everything", defaultValue: false,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "Make build errors to take over everything"));
public static readonly Option<bool> ClearLiveErrorsForProjectBuilt = new Option<bool>(nameof(InternalDiagnosticsOptions), "Clear all live errors of projects that got built", defaultValue: false,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "Clear all live errors of projects that got built"));
public static readonly Option<bool> PreferLiveErrorsOnOpenedFiles = new Option<bool>(nameof(InternalDiagnosticsOptions), "Live errors will be preferred over errors from build on opened files from same analyzer", defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "Live errors will be preferred over errors from build on opened files from same analyzer"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册