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

Address review feedback

上级 10696f7f
...@@ -341,7 +341,10 @@ public SuppressionInfo GetSuppressionInfo(Compilation compilation) ...@@ -341,7 +341,10 @@ public SuppressionInfo GetSuppressionInfo(Compilation compilation)
AttributeData attribute; AttributeData attribute;
var suppressMessageState = new SuppressMessageAttributeState(compilation); var suppressMessageState = new SuppressMessageAttributeState(compilation);
if (!suppressMessageState.IsDiagnosticSuppressed(this, getSemanticModel: tree => compilation.GetSemanticModel(tree), out attribute)) if (!suppressMessageState.IsDiagnosticSuppressed(
this,
getSemanticModel: (compilation, tree) => compilation.GetSemanticModel(tree),
out attribute))
{ {
attribute = null; attribute = null;
} }
......
...@@ -660,7 +660,10 @@ public async Task<ImmutableArray<Diagnostic>> GetDiagnosticsAsync(Compilation co ...@@ -660,7 +660,10 @@ public async Task<ImmutableArray<Diagnostic>> GetDiagnosticsAsync(Compilation co
} }
private SemanticModel GetOrCreateSemanticModel(SyntaxTree tree) private SemanticModel GetOrCreateSemanticModel(SyntaxTree tree)
=> CurrentCompilationData.GetOrCreateCachedSemanticModel(tree, AnalyzerExecutor.Compilation, AnalyzerExecutor.CancellationToken); => GetOrCreateSemanticModel(AnalyzerExecutor.Compilation, tree);
private SemanticModel GetOrCreateSemanticModel(Compilation compilation, SyntaxTree tree)
=> CurrentCompilationData.GetOrCreateCachedSemanticModel(tree, compilation, AnalyzerExecutor.CancellationToken);
public void ApplyProgrammaticSuppressions(DiagnosticBag reportedDiagnostics, Compilation compilation) public void ApplyProgrammaticSuppressions(DiagnosticBag reportedDiagnostics, Compilation compilation)
{ {
...@@ -828,7 +831,7 @@ private ImmutableArray<Diagnostic> FilterDiagnosticsSuppressedInSourceOrByAnalyz ...@@ -828,7 +831,7 @@ private ImmutableArray<Diagnostic> FilterDiagnosticsSuppressedInSourceOrByAnalyz
ImmutableArray<Diagnostic> diagnostics, ImmutableArray<Diagnostic> diagnostics,
Compilation compilation, Compilation compilation,
SuppressMessageAttributeState suppressMessageState, SuppressMessageAttributeState suppressMessageState,
Func<SyntaxTree, SemanticModel> getSemanticModel) Func<Compilation, SyntaxTree, SemanticModel> getSemanticModel)
{ {
if (diagnostics.IsEmpty) if (diagnostics.IsEmpty)
{ {
......
...@@ -1156,7 +1156,7 @@ private static IEnumerable<Diagnostic> GetEffectiveDiagnosticsImpl(ImmutableArra ...@@ -1156,7 +1156,7 @@ private static IEnumerable<Diagnostic> GetEffectiveDiagnosticsImpl(ImmutableArra
} }
var suppressMessageState = new SuppressMessageAttributeState(compilation); var suppressMessageState = new SuppressMessageAttributeState(compilation);
var semanticModelsByTree = new ConcurrentDictionary<SyntaxTree, SemanticModel>(); var semanticModelsByTree = new Dictionary<SyntaxTree, SemanticModel>();
foreach (var diagnostic in diagnostics) foreach (var diagnostic in diagnostics)
{ {
if (diagnostic != null) if (diagnostic != null)
...@@ -1169,11 +1169,12 @@ private static IEnumerable<Diagnostic> GetEffectiveDiagnosticsImpl(ImmutableArra ...@@ -1169,11 +1169,12 @@ private static IEnumerable<Diagnostic> GetEffectiveDiagnosticsImpl(ImmutableArra
} }
} }
SemanticModel getSemanticModel(SyntaxTree tree) SemanticModel getSemanticModel(Compilation compilation, SyntaxTree tree)
{ {
if (!semanticModelsByTree.TryGetValue(tree, out var model)) if (!semanticModelsByTree.TryGetValue(tree, out var model))
{ {
model = semanticModelsByTree.GetOrAdd(tree, compilation.GetSemanticModel(tree)); model = compilation.GetSemanticModel(tree);
semanticModelsByTree.Add(tree, model);
} }
return model; return model;
......
...@@ -99,7 +99,7 @@ internal SuppressMessageAttributeState(Compilation compilation) ...@@ -99,7 +99,7 @@ internal SuppressMessageAttributeState(Compilation compilation)
_localSuppressionsBySymbol = new ConcurrentDictionary<ISymbol, ImmutableDictionary<string, SuppressMessageInfo>>(); _localSuppressionsBySymbol = new ConcurrentDictionary<ISymbol, ImmutableDictionary<string, SuppressMessageInfo>>();
} }
public Diagnostic ApplySourceSuppressions(Diagnostic diagnostic, Func<SyntaxTree, SemanticModel> getSemanticModel, ISymbol symbolOpt = null) public Diagnostic ApplySourceSuppressions(Diagnostic diagnostic, Func<Compilation, SyntaxTree, SemanticModel> getSemanticModel, ISymbol symbolOpt = null)
{ {
if (diagnostic.IsSuppressed) if (diagnostic.IsSuppressed)
{ {
...@@ -117,7 +117,7 @@ public Diagnostic ApplySourceSuppressions(Diagnostic diagnostic, Func<SyntaxTree ...@@ -117,7 +117,7 @@ public Diagnostic ApplySourceSuppressions(Diagnostic diagnostic, Func<SyntaxTree
return diagnostic; return diagnostic;
} }
public bool IsDiagnosticSuppressed(Diagnostic diagnostic, Func<SyntaxTree, SemanticModel> getSemanticModel, out AttributeData suppressingAttribute) public bool IsDiagnosticSuppressed(Diagnostic diagnostic, Func<Compilation, SyntaxTree, SemanticModel> getSemanticModel, out AttributeData suppressingAttribute)
{ {
SuppressMessageInfo info; SuppressMessageInfo info;
if (IsDiagnosticSuppressed(diagnostic, getSemanticModel, out info)) if (IsDiagnosticSuppressed(diagnostic, getSemanticModel, out info))
...@@ -130,10 +130,10 @@ public bool IsDiagnosticSuppressed(Diagnostic diagnostic, Func<SyntaxTree, Seman ...@@ -130,10 +130,10 @@ public bool IsDiagnosticSuppressed(Diagnostic diagnostic, Func<SyntaxTree, Seman
return false; return false;
} }
private bool IsDiagnosticSuppressed(Diagnostic diagnostic, Func<SyntaxTree, SemanticModel> getSemanticModel, out SuppressMessageInfo info) private bool IsDiagnosticSuppressed(Diagnostic diagnostic, Func<Compilation, SyntaxTree, SemanticModel> getSemanticModel, out SuppressMessageInfo info)
=> IsDiagnosticSuppressed(diagnostic.Id, diagnostic.Location, getSemanticModel, out info); => IsDiagnosticSuppressed(diagnostic.Id, diagnostic.Location, getSemanticModel, out info);
private bool IsDiagnosticSuppressed(string id, Location location, Func<SyntaxTree, SemanticModel> getSemanticModel, out SuppressMessageInfo info) private bool IsDiagnosticSuppressed(string id, Location location, Func<Compilation, SyntaxTree, SemanticModel> getSemanticModel, out SuppressMessageInfo info)
{ {
Debug.Assert(id != null); Debug.Assert(id != null);
Debug.Assert(location != null); Debug.Assert(location != null);
...@@ -148,7 +148,7 @@ private bool IsDiagnosticSuppressed(string id, Location location, Func<SyntaxTre ...@@ -148,7 +148,7 @@ private bool IsDiagnosticSuppressed(string id, Location location, Func<SyntaxTre
// Walk up the syntax tree checking for suppression by any declared symbols encountered // Walk up the syntax tree checking for suppression by any declared symbols encountered
if (location.IsInSource) if (location.IsInSource)
{ {
var model = getSemanticModel(location.SourceTree); var model = getSemanticModel(_compilation, location.SourceTree);
bool inImmediatelyContainingSymbol = true; bool inImmediatelyContainingSymbol = true;
for (var node = location.SourceTree.GetRoot().FindNode(location.SourceSpan, getInnermostNodeForTie: true); for (var node = location.SourceTree.GetRoot().FindNode(location.SourceSpan, getInnermostNodeForTie: true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册