提交 6a46e379 编写于 作者: S Sam Harwell

Perform a lightweight syntax check before getting document options

上级 cb579f24
......@@ -5,6 +5,7 @@
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.LanguageServices;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.ValidateFormatString
{
......@@ -79,22 +80,25 @@ public override void Initialize(AnalysisContext context)
});
}
[PerformanceSensitive(
"https://github.com/dotnet/roslyn/issues/23583",
Constraint = nameof(AnalyzerHelper.GetDocumentOptionSetAsync) + " is expensive and should be avoided if a syntax-based fast path exists.")]
private void AnalyzeNode(SyntaxNodeAnalysisContext context, INamedTypeSymbol formatProviderType)
{
var optionSet = context.Options.GetDocumentOptionSetAsync(
context.Node.SyntaxTree, context.CancellationToken).GetAwaiter().GetResult();
var syntaxFacts = GetSyntaxFactsService();
var expression = syntaxFacts.GetExpressionOfInvocationExpression(context.Node);
if (optionSet.GetOption(
ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls,
context.SemanticModel.Language) == false)
if (!IsValidFormatMethod(syntaxFacts, expression))
{
return;
}
var syntaxFacts = GetSyntaxFactsService();
var expression = syntaxFacts.GetExpressionOfInvocationExpression(context.Node);
var optionSet = context.Options.GetDocumentOptionSetAsync(
context.Node.SyntaxTree, context.CancellationToken).GetAwaiter().GetResult();
if (!IsValidFormatMethod(syntaxFacts, expression))
if (optionSet.GetOption(
ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls,
context.SemanticModel.Language) == false)
{
return;
}
......@@ -394,4 +398,4 @@ private static string RemoveEscapedBrackets(string formatString)
return true;
}
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册