提交 07bb25ba 编写于 作者: M Manish Vasani 提交者: GitHub

Remove deprecated internal APIs for Document and Project diagnostic analyzer (#12220)

TS has moved to newly added APIs, so remove the old APIs.
Fixes #11501
上级 ed1335cb
......@@ -13,34 +13,9 @@ namespace Microsoft.CodeAnalysis.Diagnostics
/// </summary>
internal abstract class DocumentDiagnosticAnalyzer : DiagnosticAnalyzer
{
// REVIEW: why DocumentDiagnosticAnalyzer doesn't have span based analysis?
// TODO: Make abstract once TypeScript and F# move over to the overloads above
public async virtual Task<ImmutableArray<Diagnostic>> AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
{
var builder = ArrayBuilder<Diagnostic>.GetInstance();
await AnalyzeSyntaxAsync(document, builder.Add, cancellationToken).ConfigureAwait(false);
return builder.ToImmutableAndFree();
}
// TODO: Make abstract once TypeScript and F# move over to the overloads above
public async virtual Task<ImmutableArray<Diagnostic>> AnalyzeSemanticsAsync(Document document, CancellationToken cancellationToken)
{
var builder = ArrayBuilder<Diagnostic>.GetInstance();
await AnalyzeSemanticsAsync(document, builder.Add, cancellationToken).ConfigureAwait(false);
return builder.ToImmutableAndFree();
}
public abstract Task<ImmutableArray<Diagnostic>> AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken);
// TODO: Remove once TypeScript and F# move over to the overloads above
public virtual Task AnalyzeSyntaxAsync(Document document, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
throw ExceptionUtilities.Unreachable;
}
// TODO: Remove once TypeScript and F# move over to the overloads above
public virtual Task AnalyzeSemanticsAsync(Document document, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
throw ExceptionUtilities.Unreachable;
}
public abstract Task<ImmutableArray<Diagnostic>> AnalyzeSemanticsAsync(Document document, CancellationToken cancellationToken);
/// <summary>
/// it is not allowed one to implement both DocumentDiagnosticAnalzyer and DiagnosticAnalyzer
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
......@@ -11,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics
/// </summary>
internal abstract class ProjectDiagnosticAnalyzer : DiagnosticAnalyzer
{
public abstract Task AnalyzeProjectAsync(Project project, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken);
public abstract Task<ImmutableArray<Diagnostic>> AnalyzeProjectAsync(Project project, CancellationToken cancellationToken);
/// <summary>
/// it is not allowed one to implement both ProjectDiagnosticAnalzyer and DiagnosticAnalyzer
......
......@@ -325,23 +325,24 @@ public IEnumerable<DiagnosticData> ConvertToLocalDiagnostics(Document targetDocu
private async Task<IEnumerable<Diagnostic>> ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(
Project project, ProjectDiagnosticAnalyzer analyzer, Compilation compilationOpt, CancellationToken cancellationToken)
{
using (var pooledObject = SharedPools.Default<List<Diagnostic>>().GetPooledObject())
{
var diagnostics = pooledObject.Object;
cancellationToken.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
try
{
await analyzer.AnalyzeProjectAsync(project, diagnostics.Add, cancellationToken).ConfigureAwait(false);
try
{
var diagnostics = await analyzer.AnalyzeProjectAsync(project, cancellationToken).ConfigureAwait(false);
// REVIEW: V1 doesn't convert diagnostics to effective diagnostics. not sure why.
return compilationOpt == null ? diagnostics.ToImmutableArrayOrEmpty() : CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, compilationOpt);
}
catch (Exception e) when (!IsCanceled(e, cancellationToken))
// Apply filtering from compilation options (source suppressions, ruleset, etc.)
if (compilationOpt != null)
{
OnAnalyzerException(analyzer, project.Id, compilationOpt, e);
return ImmutableArray<Diagnostic>.Empty;
diagnostics = CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, compilationOpt).ToImmutableArrayOrEmpty();
}
return diagnostics;
}
catch (Exception e) when (!IsCanceled(e, cancellationToken))
{
OnAnalyzerException(analyzer, project.Id, compilationOpt, e);
return ImmutableArray<Diagnostic>.Empty;
}
}
......
......@@ -323,8 +323,8 @@
<Compile Include="Completion\CompletionRules.cs" />
<Compile Include="Diagnostics\Analyzers\RudeEditUserDiagnosticAnalyzer.cs" />
<Compile Include="Diagnostics\Analyzers\UnboundIdentifiersDiagnosticAnalyzerBase.cs" />
<Compile Include="Diagnostics\Analyzers\IDocumentDiagnosticAnalyzer.cs" />
<Compile Include="Diagnostics\Analyzers\IProjectDiagnosticAnalyzer.cs" />
<Compile Include="Diagnostics\Analyzers\DocumentDiagnosticAnalyzer.cs" />
<Compile Include="Diagnostics\Analyzers\ProjectDiagnosticAnalyzer.cs" />
<Compile Include="Diagnostics\Analyzers\RemoveUnnecessaryCastDiagnosticAnalyzerBase.cs" />
<Compile Include="Diagnostics\Analyzers\RemoveUnnecessaryImportsDiagnosticAnalyzerBase.cs" />
<Compile Include="Diagnostics\Analyzers\SimplifyTypeNamesDiagnosticAnalyzerBase.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册