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

Address review feedback

上级 10696f7f
......@@ -341,7 +341,10 @@ public SuppressionInfo GetSuppressionInfo(Compilation compilation)
AttributeData attribute;
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;
}
......
......@@ -660,7 +660,10 @@ public async Task<ImmutableArray<Diagnostic>> GetDiagnosticsAsync(Compilation co
}
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)
{
......@@ -828,7 +831,7 @@ private ImmutableArray<Diagnostic> FilterDiagnosticsSuppressedInSourceOrByAnalyz
ImmutableArray<Diagnostic> diagnostics,
Compilation compilation,
SuppressMessageAttributeState suppressMessageState,
Func<SyntaxTree, SemanticModel> getSemanticModel)
Func<Compilation, SyntaxTree, SemanticModel> getSemanticModel)
{
if (diagnostics.IsEmpty)
{
......
......@@ -1156,7 +1156,7 @@ private static IEnumerable<Diagnostic> GetEffectiveDiagnosticsImpl(ImmutableArra
}
var suppressMessageState = new SuppressMessageAttributeState(compilation);
var semanticModelsByTree = new ConcurrentDictionary<SyntaxTree, SemanticModel>();
var semanticModelsByTree = new Dictionary<SyntaxTree, SemanticModel>();
foreach (var diagnostic in diagnostics)
{
if (diagnostic != null)
......@@ -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))
{
model = semanticModelsByTree.GetOrAdd(tree, compilation.GetSemanticModel(tree));
model = compilation.GetSemanticModel(tree);
semanticModelsByTree.Add(tree, model);
}
return model;
......
......@@ -99,7 +99,7 @@ internal SuppressMessageAttributeState(Compilation compilation)
_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)
{
......@@ -117,7 +117,7 @@ public Diagnostic ApplySourceSuppressions(Diagnostic diagnostic, Func<SyntaxTree
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;
if (IsDiagnosticSuppressed(diagnostic, getSemanticModel, out info))
......@@ -130,10 +130,10 @@ public bool IsDiagnosticSuppressed(Diagnostic diagnostic, Func<SyntaxTree, Seman
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);
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(location != null);
......@@ -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
if (location.IsInSource)
{
var model = getSemanticModel(location.SourceTree);
var model = getSemanticModel(_compilation, location.SourceTree);
bool inImmediatelyContainingSymbol = 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.
先完成此消息的编辑!
想要评论请 注册