提交 3cd50f0c 编写于 作者: H Heejae Chang

made argsId to be shared between engine v1 and v2

上级 c632be8e
// 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.Linq;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Diagnostics.EngineV1
{
......@@ -82,33 +79,5 @@ public VersionArgument(VersionStamp textVersion, VersionStamp dataVersion, Versi
this.ProjectVersion = projectVersion;
}
}
public class HostAnalyzerKey : ArgumentKey
{
private readonly string _analyzerPackageName;
public HostAnalyzerKey(DiagnosticAnalyzer analyzer, StateType stateType, object key, string analyzerPackageName) :
base(analyzer, stateType, key)
{
_analyzerPackageName = analyzerPackageName;
}
public override string BuildTool
{
get
{
return _analyzerPackageName;
}
}
}
public class ArgumentKey : LiveDiagnosticUpdateArgsId
{
public ArgumentKey(DiagnosticAnalyzer analyzer, StateType stateType, object key) : base(analyzer, key, (int)stateType)
{
}
public StateType StateType => (StateType)Kind;
}
}
}
......@@ -823,7 +823,7 @@ private static ImmutableArray<DiagnosticData> GetDiagnosticData(ILookup<Document
StateType type, object key, StateSet stateSet, SolutionArgument solution, ImmutableArray<DiagnosticData> diagnostics, Action<DiagnosticsUpdatedArgs> raiseEvents)
{
// get right arg id for the given analyzer
var id = CreateArgumentKey(type, key, stateSet);
var id = new LiveDiagnosticUpdateArgsId(stateSet.Analyzer, key, (int)type, stateSet.ErrorSourceName);
raiseEvents(DiagnosticsUpdatedArgs.DiagnosticsCreated(id, Workspace, solution.Solution, solution.ProjectId, solution.DocumentId, diagnostics));
}
......@@ -837,7 +837,7 @@ private static ImmutableArray<DiagnosticData> GetDiagnosticData(ILookup<Document
StateType type, object key, StateSet stateSet, SolutionArgument solution, Action<DiagnosticsUpdatedArgs> raiseEvents)
{
// get right arg id for the given analyzer
var id = CreateArgumentKey(type, key, stateSet);
var id = new LiveDiagnosticUpdateArgsId(stateSet.Analyzer, key, (int)type, stateSet.ErrorSourceName);
raiseEvents(DiagnosticsUpdatedArgs.DiagnosticsRemoved(id, Workspace, solution.Solution, solution.ProjectId, solution.DocumentId));
}
......@@ -867,13 +867,6 @@ private void RaiseProjectDiagnosticsRemoved(Project project, IEnumerable<StateSe
}
}
private static ArgumentKey CreateArgumentKey(StateType type, object key, StateSet stateSet)
{
return stateSet.ErrorSourceName != null
? new HostAnalyzerKey(stateSet.Analyzer, type, key, stateSet.ErrorSourceName)
: new ArgumentKey(stateSet.Analyzer, type, key);
}
private ImmutableArray<DiagnosticData> UpdateDocumentDiagnostics(
AnalysisData existingData, ImmutableArray<TextSpan> range, ImmutableArray<DiagnosticData> memberDiagnostics,
SyntaxTree tree, SyntaxNode member, int memberId)
......
......@@ -295,7 +295,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(Ca
return ImmutableArray<DiagnosticData>.Empty;
}
var key = Id as ArgumentKey;
var key = Id as LiveDiagnosticUpdateArgsId;
if (key == null)
{
return ImmutableArray<DiagnosticData>.Empty;
......@@ -316,7 +316,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(Ca
return ImmutableArray<DiagnosticData>.Empty;
}
var state = stateSet.GetState(key.StateType);
var state = stateSet.GetState((StateType)key.Kind);
if (state == null)
{
return ImmutableArray<DiagnosticData>.Empty;
......@@ -584,7 +584,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(Ca
return ImmutableArray<DiagnosticData>.Empty;
}
var key = Id as ArgumentKey;
var key = Id as LiveDiagnosticUpdateArgsId;
if (key == null)
{
return ImmutableArray<DiagnosticData>.Empty;
......@@ -597,7 +597,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(Ca
return ImmutableArray<DiagnosticData>.Empty;
}
if (key.StateType != StateType.Project)
if (key.Kind != (int)StateType.Project)
{
return await GetSpecificDiagnosticsAsync(documentOrProject, key, cancellationToken).ConfigureAwait(false);
}
......@@ -605,9 +605,9 @@ public async Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(Ca
return await GetSpecificDiagnosticsAsync(GetProject(documentOrProject), key, cancellationToken).ConfigureAwait(false);
}
private async Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(object documentOrProject, ArgumentKey key, CancellationToken cancellationToken)
private async Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(object documentOrProject, LiveDiagnosticUpdateArgsId key, CancellationToken cancellationToken)
{
var versions = await GetVersionsAsync(documentOrProject, key.StateType, cancellationToken).ConfigureAwait(false);
var versions = await GetVersionsAsync(documentOrProject, (StateType)key.Kind, cancellationToken).ConfigureAwait(false);
var project = GetProject(documentOrProject);
var stateSet = this.StateManager.GetOrCreateStateSet(project, key.Analyzer);
......@@ -617,10 +617,10 @@ private async Task<ImmutableArray<DiagnosticData>> GetSpecificDiagnosticsAsync(o
}
var analyzers = Owner._stateManager.GetOrCreateAnalyzers(project);
var driver = await GetDiagnosticAnalyzerDriverAsync(documentOrProject, analyzers, key.StateType, cancellationToken).ConfigureAwait(false);
var driver = await GetDiagnosticAnalyzerDriverAsync(documentOrProject, analyzers, (StateType)key.Kind, cancellationToken).ConfigureAwait(false);
var analysisData = await GetDiagnosticAnalysisDataAsync(driver, stateSet, key.StateType, versions).ConfigureAwait(false);
if (key.StateType != StateType.Project)
var analysisData = await GetDiagnosticAnalysisDataAsync(driver, stateSet, (StateType)key.Kind, versions).ConfigureAwait(false);
if (key.Kind != (int)StateType.Project)
{
return analysisData.Items;
}
......
......@@ -6,15 +6,27 @@ namespace Microsoft.CodeAnalysis.Diagnostics
{
internal class LiveDiagnosticUpdateArgsId : AnalyzerUpdateArgsId
{
private readonly string _analyzerPackageName;
public readonly object Key;
public readonly int Kind;
public LiveDiagnosticUpdateArgsId(DiagnosticAnalyzer analyzer, object key, int kind) : base(analyzer)
public LiveDiagnosticUpdateArgsId(DiagnosticAnalyzer analyzer, object key, int kind) :
this(analyzer, key, kind, analyzerPackageName: null)
{
}
public LiveDiagnosticUpdateArgsId(DiagnosticAnalyzer analyzer, object key, int kind, string analyzerPackageName) :
base(analyzer)
{
Key = key;
Kind = kind;
_analyzerPackageName = analyzerPackageName;
}
public override string BuildTool => _analyzerPackageName ?? base.BuildTool;
public override bool Equals(object obj)
{
var other = obj as LiveDiagnosticUpdateArgsId;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册