未验证 提交 cbd28c60 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #35814 from sharwell/sync-analyzer

🧹 Remove the use of asynchronous APIs in analyzer
...@@ -37,9 +37,8 @@ public override void Initialize(AnalysisContext context) ...@@ -37,9 +37,8 @@ public override void Initialize(AnalysisContext context)
private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context) private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
{ {
var diagnostics = RenameTrackingTaggerProvider.GetDiagnosticsAsync(context.Tree, DiagnosticDescriptor, context.CancellationToken).WaitAndGetResult_CanCallOnBackground(context.CancellationToken); var diagnostic = RenameTrackingTaggerProvider.TryGetDiagnostic(context.Tree, DiagnosticDescriptor, context.CancellationToken);
if (diagnostic is object)
foreach (var diagnostic in diagnostics)
{ {
context.ReportDiagnostic(diagnostic); context.ReportDiagnostic(diagnostic);
} }
......
...@@ -276,7 +276,7 @@ public bool CanInvokeRename(out TrackingSession trackingSession, bool isSmartTag ...@@ -276,7 +276,7 @@ public bool CanInvokeRename(out TrackingSession trackingSession, bool isSmartTag
trackingSession.CanInvokeRename(syntaxFactsService, languageHeuristicsService, isSmartTagCheck, waitForResult, cancellationToken); trackingSession.CanInvokeRename(syntaxFactsService, languageHeuristicsService, isSmartTagCheck, waitForResult, cancellationToken);
} }
internal async Task<IEnumerable<Diagnostic>> GetDiagnostic(SyntaxTree tree, DiagnosticDescriptor diagnosticDescriptor, CancellationToken cancellationToken) internal Diagnostic TryGetDiagnostic(SyntaxTree tree, DiagnosticDescriptor diagnosticDescriptor, CancellationToken cancellationToken)
{ {
try try
{ {
...@@ -287,9 +287,9 @@ internal async Task<IEnumerable<Diagnostic>> GetDiagnostic(SyntaxTree tree, Diag ...@@ -287,9 +287,9 @@ internal async Task<IEnumerable<Diagnostic>> GetDiagnostic(SyntaxTree tree, Diag
// method. If it does, we may give an incorrect response, but the diagnostics // method. If it does, we may give an incorrect response, but the diagnostics
// engine will know that the document changed and not display the lightbulb anyway. // engine will know that the document changed and not display the lightbulb anyway.
if (Buffer.AsTextContainer().CurrentText != await tree.GetTextAsync(cancellationToken).ConfigureAwait(false)) if (Buffer.AsTextContainer().CurrentText != tree.GetText(cancellationToken))
{ {
return SpecializedCollections.EmptyEnumerable<Diagnostic>(); return null;
} }
if (CanInvokeRename(out var trackingSession, waitForResult: true, cancellationToken: cancellationToken)) if (CanInvokeRename(out var trackingSession, waitForResult: true, cancellationToken: cancellationToken))
...@@ -306,10 +306,10 @@ internal async Task<IEnumerable<Diagnostic>> GetDiagnostic(SyntaxTree tree, Diag ...@@ -306,10 +306,10 @@ internal async Task<IEnumerable<Diagnostic>> GetDiagnostic(SyntaxTree tree, Diag
tree.GetLocation(textSpan), tree.GetLocation(textSpan),
properties); properties);
return SpecializedCollections.SingletonEnumerable(diagnostic); return diagnostic;
} }
return SpecializedCollections.EmptyEnumerable<Diagnostic>(); return null;
} }
catch (Exception e) when (FatalError.ReportUnlessCanceled(e)) catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{ {
......
...@@ -110,7 +110,7 @@ internal static bool ResetRenameTrackingStateWorker(Workspace workspace, Documen ...@@ -110,7 +110,7 @@ internal static bool ResetRenameTrackingStateWorker(Workspace workspace, Documen
return false; return false;
} }
internal static async Task<IEnumerable<Diagnostic>> GetDiagnosticsAsync(SyntaxTree tree, DiagnosticDescriptor diagnosticDescriptor, CancellationToken cancellationToken) internal static Diagnostic TryGetDiagnostic(SyntaxTree tree, DiagnosticDescriptor diagnosticDescriptor, CancellationToken cancellationToken)
{ {
try try
{ {
...@@ -121,11 +121,11 @@ internal static async Task<IEnumerable<Diagnostic>> GetDiagnosticsAsync(SyntaxTr ...@@ -121,11 +121,11 @@ internal static async Task<IEnumerable<Diagnostic>> GetDiagnosticsAsync(SyntaxTr
var textBuffer = text.Container.TryGetTextBuffer(); var textBuffer = text.Container.TryGetTextBuffer();
if (textBuffer != null && textBuffer.Properties.TryGetProperty(typeof(StateMachine), out StateMachine stateMachine)) if (textBuffer != null && textBuffer.Properties.TryGetProperty(typeof(StateMachine), out StateMachine stateMachine))
{ {
return await stateMachine.GetDiagnostic(tree, diagnosticDescriptor, cancellationToken).ConfigureAwait(false); return stateMachine.TryGetDiagnostic(tree, diagnosticDescriptor, cancellationToken);
} }
} }
return SpecializedCollections.EmptyEnumerable<Diagnostic>(); return null;
} }
catch (Exception e) when (FatalError.ReportUnlessCanceled(e)) catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册