提交 038add87 编写于 作者: H Heejae Chang

changed the way report duplicates

上级 b1ceada2
......@@ -201,7 +201,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests
Dim descriptorsMap = diagnosticService.GetDiagnosticDescriptors(project)
' two references in the map
Assert.Equal(2, descriptorsMap.Count)
Assert.Equal(1, descriptorsMap.Count)
Dim names = New HashSet(Of String)
names.UnionWith(descriptorsMap.Keys)
......
......@@ -64,7 +64,6 @@ protected DiagnosticAnalyzerService(ImmutableArray<AnalyzerReference> workspaceA
{
var map = _hostAnalyzerManager.CreateAnalyzerReferencesMap(projectOpt);
var nameCollisionMap = new Dictionary<string, int>();
var builder = ImmutableDictionary.CreateBuilder<string, ImmutableArray<DiagnosticDescriptor>>();
foreach (var kv in descriptorsPerReference)
......@@ -73,33 +72,30 @@ protected DiagnosticAnalyzerService(ImmutableArray<AnalyzerReference> workspaceA
var descriptors = kv.Value;
AnalyzerReference reference;
if (map.TryGetValue(id, out reference) && reference != null)
if (!map.TryGetValue(id, out reference) || reference == null)
{
var displayName = GetDisplayName(nameCollisionMap, reference);
builder.Add(displayName, descriptors);
continue;
}
var displayName = GetDisplayName(reference);
// if there are duplicates, merge descriptors
ImmutableArray<DiagnosticDescriptor> existing;
if (builder.TryGetValue(displayName, out existing))
{
builder[displayName] = existing.AddRange(descriptors);
continue;
}
builder.Add(displayName, descriptors);
}
return builder.ToImmutable();
}
private static string GetDisplayName(Dictionary<string, int> nameCollisionMap, AnalyzerReference reference)
private static string GetDisplayName(AnalyzerReference reference)
{
var name = reference.Display ?? FeaturesResources.Unknown;
var count = GetNameCollisionCount(nameCollisionMap, name);
return count == 0 ? name : $"{name} [#{count}]";
}
private static int GetNameCollisionCount(Dictionary<string, int> nameCollisionMap, string name)
{
int count = 0;
if (nameCollisionMap.TryGetValue(name, out count))
{
count++;
}
nameCollisionMap[name] = count;
return count;
return reference.Display ?? FeaturesResources.Unknown;
}
public ImmutableArray<DiagnosticDescriptor> GetDiagnosticDescriptors(DiagnosticAnalyzer analyzer)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册