diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.cs index 3598e818cb9be3f52ff5d2f1b768361ff7dd28d9..9bdeda8dd3a84f132fe74a43b8b0d7b0b69c7e2e 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.cs @@ -19,8 +19,6 @@ namespace Microsoft.CodeAnalysis.Diagnostics /// internal partial class AnalyzerManager { - private readonly object _gate = new object(); - // This cache stores the analyzer execution context per-analyzer (i.e. registered actions, supported descriptors, etc.). private readonly ImmutableDictionary _analyzerExecutionContextMap; diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs b/src/EditorFeatures/TestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs index 74f29be47c8332367e7356a9fe1bf2a0178e0597..961478d6b0f7b243db72ef8baf5db42fce92937c 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs @@ -60,17 +60,15 @@ internal virtual (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderA document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span); } - using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider)) - { - var diagnostics = await testDriver.GetAllDiagnosticsAsync(provider, document, span); - AssertNoAnalyzerExceptionDiagnostics(diagnostics); + var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider); + var diagnostics = await testDriver.GetAllDiagnosticsAsync(provider, document, span); + AssertNoAnalyzerExceptionDiagnostics(diagnostics); - var fixer = providerAndFixer.Item2; - var ids = new HashSet(fixer.FixableDiagnosticIds); - var dxs = diagnostics.Where(d => ids.Contains(d.Id)).ToList(); - return await GetDiagnosticAndFixesAsync( - dxs, provider, fixer, testDriver, document, span, annotation, parameters.fixAllActionEquivalenceKey); - } + var fixer = providerAndFixer.Item2; + var ids = new HashSet(fixer.FixableDiagnosticIds); + var dxs = diagnostics.Where(d => ids.Contains(d.Id)).ToList(); + return await GetDiagnosticAndFixesAsync( + dxs, provider, fixer, testDriver, document, span, annotation, parameters.fixAllActionEquivalenceKey); } protected async Task TestDiagnosticSeverityAndCountAsync( diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/AbstractSuppressionDiagnosticTest.cs b/src/EditorFeatures/TestUtilities/Diagnostics/AbstractSuppressionDiagnosticTest.cs index 3e1afb916f9914b43e74742e7fa73803d562c4cf..65004e640b645c3395a28b4b2e830376583907d7 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/AbstractSuppressionDiagnosticTest.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/AbstractSuppressionDiagnosticTest.cs @@ -71,18 +71,16 @@ private ImmutableArray FilterDiagnostics(IEnumerable dia document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span); } - using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider, includeSuppressedDiagnostics: IncludeSuppressedDiagnostics)) - { - var fixer = providerAndFixer.Item2; - var diagnostics = (await testDriver.GetAllDiagnosticsAsync(provider, document, span)) - .Where(d => fixer.CanBeSuppressedOrUnsuppressed(d)); + var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider, includeSuppressedDiagnostics: IncludeSuppressedDiagnostics); + var fixer = providerAndFixer.Item2; + var diagnostics = (await testDriver.GetAllDiagnosticsAsync(provider, document, span)) + .Where(d => fixer.CanBeSuppressedOrUnsuppressed(d)); - var filteredDiagnostics = FilterDiagnostics(diagnostics); + var filteredDiagnostics = FilterDiagnostics(diagnostics); - var wrapperCodeFixer = new WrapperCodeFixProvider(fixer, filteredDiagnostics.Select(d => d.Id)); - return await GetDiagnosticAndFixesAsync( - filteredDiagnostics, provider, wrapperCodeFixer, testDriver, document, span, annotation, parameters.fixAllActionEquivalenceKey); - } + var wrapperCodeFixer = new WrapperCodeFixProvider(fixer, filteredDiagnostics.Select(d => d.Id)); + return await GetDiagnosticAndFixesAsync( + filteredDiagnostics, provider, wrapperCodeFixer, testDriver, document, span, annotation, parameters.fixAllActionEquivalenceKey); } } } diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/DiagnosticProviderTestUtilities.cs b/src/EditorFeatures/TestUtilities/Diagnostics/DiagnosticProviderTestUtilities.cs index 8623b43312781c2766f2a26a286737a21f3e77e8..7f385fca2dd18db48a1e2bef6e4f97ef76c8dbd2 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/DiagnosticProviderTestUtilities.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/DiagnosticProviderTestUtilities.cs @@ -12,18 +12,14 @@ public static class DiagnosticProviderTestUtilities { public static async Task> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Document document, TextSpan span, Action onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) { - using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics)) - { - return await testDriver.GetAllDiagnosticsAsync(workspaceAnalyzerOpt, document, span); - } + var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics); + return await testDriver.GetAllDiagnosticsAsync(workspaceAnalyzerOpt, document, span); } public static async Task> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Project project, Action onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) { - using (var testDriver = new TestDiagnosticAnalyzerDriver(project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics)) - { - return await testDriver.GetAllDiagnosticsAsync(workspaceAnalyzerOpt, project); - } + var testDriver = new TestDiagnosticAnalyzerDriver(project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics); + return await testDriver.GetAllDiagnosticsAsync(workspaceAnalyzerOpt, project); } public static async Task> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Solution solution, Action onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) @@ -40,18 +36,14 @@ public static async Task> GetAllDiagnosticsAsync(Diagnos public static async Task> GetDocumentDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Document document, TextSpan span, Action onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) { - using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics)) - { - return await testDriver.GetDocumentDiagnosticsAsync(workspaceAnalyzerOpt, document, span); - } + var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics); + return await testDriver.GetDocumentDiagnosticsAsync(workspaceAnalyzerOpt, document, span); } public static async Task> GetProjectDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Project project, Action onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) { - using (var testDriver = new TestDiagnosticAnalyzerDriver(project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics)) - { - return await testDriver.GetProjectDiagnosticsAsync(workspaceAnalyzerOpt, project); - } + var testDriver = new TestDiagnosticAnalyzerDriver(project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics); + return await testDriver.GetProjectDiagnosticsAsync(workspaceAnalyzerOpt, project); } } } diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/TestDiagnosticAnalyzerDriver.cs b/src/EditorFeatures/TestUtilities/Diagnostics/TestDiagnosticAnalyzerDriver.cs index 476d6babe94abb04767d1e1d472277a1e02af16a..b04337867dbd4ccab8a6314f0bc07574a9f22b8b 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/TestDiagnosticAnalyzerDriver.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/TestDiagnosticAnalyzerDriver.cs @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.UnitTests.Diagnostics { - public class TestDiagnosticAnalyzerDriver : IDisposable + public class TestDiagnosticAnalyzerDriver { private readonly ImmutableArray _workspaceAnalyzers; private readonly TestDiagnosticAnalyzerService _diagnosticAnalyzerService; @@ -113,9 +113,5 @@ public Task> GetProjectDiagnosticsAsync(DiagnosticAnalyz { return GetDiagnosticsAsync(workspaceAnalyzerOpt, null, default(TextSpan), project, getDocumentDiagnostics: false, getProjectDiagnostics: true); } - - public void Dispose() - { - } } }