提交 ca5b0d9e 编写于 作者: M Manish Vasani

Address PR feedback

上级 67ad810c
...@@ -19,8 +19,6 @@ namespace Microsoft.CodeAnalysis.Diagnostics ...@@ -19,8 +19,6 @@ namespace Microsoft.CodeAnalysis.Diagnostics
/// </summary> /// </summary>
internal partial class AnalyzerManager 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.). // This cache stores the analyzer execution context per-analyzer (i.e. registered actions, supported descriptors, etc.).
private readonly ImmutableDictionary<DiagnosticAnalyzer, AnalyzerExecutionContext> _analyzerExecutionContextMap; private readonly ImmutableDictionary<DiagnosticAnalyzer, AnalyzerExecutionContext> _analyzerExecutionContextMap;
......
...@@ -60,17 +60,15 @@ internal virtual (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderA ...@@ -60,17 +60,15 @@ internal virtual (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderA
document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span); document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span);
} }
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider)) var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider);
{ var diagnostics = await testDriver.GetAllDiagnosticsAsync(provider, document, span);
var diagnostics = await testDriver.GetAllDiagnosticsAsync(provider, document, span); AssertNoAnalyzerExceptionDiagnostics(diagnostics);
AssertNoAnalyzerExceptionDiagnostics(diagnostics);
var fixer = providerAndFixer.Item2; var fixer = providerAndFixer.Item2;
var ids = new HashSet<string>(fixer.FixableDiagnosticIds); var ids = new HashSet<string>(fixer.FixableDiagnosticIds);
var dxs = diagnostics.Where(d => ids.Contains(d.Id)).ToList(); var dxs = diagnostics.Where(d => ids.Contains(d.Id)).ToList();
return await GetDiagnosticAndFixesAsync( return await GetDiagnosticAndFixesAsync(
dxs, provider, fixer, testDriver, document, span, annotation, parameters.fixAllActionEquivalenceKey); dxs, provider, fixer, testDriver, document, span, annotation, parameters.fixAllActionEquivalenceKey);
}
} }
protected async Task TestDiagnosticSeverityAndCountAsync( protected async Task TestDiagnosticSeverityAndCountAsync(
......
...@@ -71,18 +71,16 @@ private ImmutableArray<Diagnostic> FilterDiagnostics(IEnumerable<Diagnostic> dia ...@@ -71,18 +71,16 @@ private ImmutableArray<Diagnostic> FilterDiagnostics(IEnumerable<Diagnostic> dia
document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span); document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span);
} }
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider, includeSuppressedDiagnostics: IncludeSuppressedDiagnostics)) var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider, includeSuppressedDiagnostics: IncludeSuppressedDiagnostics);
{ var fixer = providerAndFixer.Item2;
var fixer = providerAndFixer.Item2; var diagnostics = (await testDriver.GetAllDiagnosticsAsync(provider, document, span))
var diagnostics = (await testDriver.GetAllDiagnosticsAsync(provider, document, span)) .Where(d => fixer.CanBeSuppressedOrUnsuppressed(d));
.Where(d => fixer.CanBeSuppressedOrUnsuppressed(d));
var filteredDiagnostics = FilterDiagnostics(diagnostics); var filteredDiagnostics = FilterDiagnostics(diagnostics);
var wrapperCodeFixer = new WrapperCodeFixProvider(fixer, filteredDiagnostics.Select(d => d.Id)); var wrapperCodeFixer = new WrapperCodeFixProvider(fixer, filteredDiagnostics.Select(d => d.Id));
return await GetDiagnosticAndFixesAsync( return await GetDiagnosticAndFixesAsync(
filteredDiagnostics, provider, wrapperCodeFixer, testDriver, document, span, annotation, parameters.fixAllActionEquivalenceKey); filteredDiagnostics, provider, wrapperCodeFixer, testDriver, document, span, annotation, parameters.fixAllActionEquivalenceKey);
}
} }
} }
} }
...@@ -12,18 +12,14 @@ public static class DiagnosticProviderTestUtilities ...@@ -12,18 +12,14 @@ public static class DiagnosticProviderTestUtilities
{ {
public static async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Document document, TextSpan span, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) public static async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Document document, TextSpan span, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false)
{ {
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics)) var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics);
{ return await testDriver.GetAllDiagnosticsAsync(workspaceAnalyzerOpt, document, span);
return await testDriver.GetAllDiagnosticsAsync(workspaceAnalyzerOpt, document, span);
}
} }
public static async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Project project, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) public static async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Project project, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false)
{ {
using (var testDriver = new TestDiagnosticAnalyzerDriver(project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics)) var testDriver = new TestDiagnosticAnalyzerDriver(project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics);
{ return await testDriver.GetAllDiagnosticsAsync(workspaceAnalyzerOpt, project);
return await testDriver.GetAllDiagnosticsAsync(workspaceAnalyzerOpt, project);
}
} }
public static async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Solution solution, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) public static async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Solution solution, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false)
...@@ -40,18 +36,14 @@ public static async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(Diagnos ...@@ -40,18 +36,14 @@ public static async Task<IEnumerable<Diagnostic>> GetAllDiagnosticsAsync(Diagnos
public static async Task<IEnumerable<Diagnostic>> GetDocumentDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Document document, TextSpan span, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) public static async Task<IEnumerable<Diagnostic>> GetDocumentDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Document document, TextSpan span, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false)
{ {
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics)) var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics);
{ return await testDriver.GetDocumentDiagnosticsAsync(workspaceAnalyzerOpt, document, span);
return await testDriver.GetDocumentDiagnosticsAsync(workspaceAnalyzerOpt, document, span);
}
} }
public static async Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Project project, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false) public static async Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(DiagnosticAnalyzer workspaceAnalyzerOpt, Project project, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException = null, bool logAnalyzerExceptionAsDiagnostics = false, bool includeSuppressedDiagnostics = false)
{ {
using (var testDriver = new TestDiagnosticAnalyzerDriver(project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics)) var testDriver = new TestDiagnosticAnalyzerDriver(project, workspaceAnalyzerOpt, onAnalyzerException, logAnalyzerExceptionAsDiagnostics, includeSuppressedDiagnostics);
{ return await testDriver.GetProjectDiagnosticsAsync(workspaceAnalyzerOpt, project);
return await testDriver.GetProjectDiagnosticsAsync(workspaceAnalyzerOpt, project);
}
} }
} }
} }
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
namespace Microsoft.CodeAnalysis.UnitTests.Diagnostics namespace Microsoft.CodeAnalysis.UnitTests.Diagnostics
{ {
public class TestDiagnosticAnalyzerDriver : IDisposable public class TestDiagnosticAnalyzerDriver
{ {
private readonly ImmutableArray<DiagnosticAnalyzer> _workspaceAnalyzers; private readonly ImmutableArray<DiagnosticAnalyzer> _workspaceAnalyzers;
private readonly TestDiagnosticAnalyzerService _diagnosticAnalyzerService; private readonly TestDiagnosticAnalyzerService _diagnosticAnalyzerService;
...@@ -113,9 +113,5 @@ public Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(DiagnosticAnalyz ...@@ -113,9 +113,5 @@ public Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(DiagnosticAnalyz
{ {
return GetDiagnosticsAsync(workspaceAnalyzerOpt, null, default(TextSpan), project, getDocumentDiagnostics: false, getProjectDiagnostics: true); return GetDiagnosticsAsync(workspaceAnalyzerOpt, null, default(TextSpan), project, getDocumentDiagnostics: false, getProjectDiagnostics: true);
} }
public void Dispose()
{
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册