Skip to content

Commit 72f2498

Browse files
Updated error list implemenation
1 parent 878f46e commit 72f2498

File tree

3 files changed

+77
-33
lines changed

3 files changed

+77
-33
lines changed

src/toolkit/Community.VisualStudio.Toolkit.Shared/ErrorList/ErrorListItem.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.VisualStudio.Shell.Interop;
1+
using System.Collections.Generic;
2+
using Microsoft.VisualStudio.Shell.Interop;
23

34
namespace Community.VisualStudio.Toolkit
45
{
@@ -61,5 +62,40 @@ public class ErrorListItem
6162
/// Column used to display the build tool that generated the error (e.g. "FxCop").
6263
/// </summary>
6364
public string? BuildTool { get; set; }
65+
66+
/// <inheritdoc/>
67+
public override bool Equals(object obj)
68+
{
69+
return obj is ErrorListItem item &&
70+
ProjectName == item.ProjectName &&
71+
FileName == item.FileName &&
72+
Line == item.Line &&
73+
Column == item.Column &&
74+
Message == item.Message &&
75+
ErrorCode == item.ErrorCode &&
76+
ErrorCodeToolTip == item.ErrorCodeToolTip &&
77+
ErrorCategory == item.ErrorCategory &&
78+
Severity == item.Severity &&
79+
HelpLink == item.HelpLink &&
80+
BuildTool == item.BuildTool;
81+
}
82+
83+
/// <inheritdoc/>
84+
public override int GetHashCode()
85+
{
86+
int hashCode = 1638003424;
87+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(ProjectName!);
88+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(FileName!);
89+
hashCode = hashCode * -1521134295 + Line.GetHashCode();
90+
hashCode = hashCode * -1521134295 + Column.GetHashCode();
91+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Message!);
92+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(ErrorCode!);
93+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(ErrorCodeToolTip!);
94+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(ErrorCategory!);
95+
hashCode = hashCode * -1521134295 + Severity.GetHashCode();
96+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(HelpLink!);
97+
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(BuildTool!);
98+
return hashCode;
99+
}
64100
}
65101
}

src/toolkit/Community.VisualStudio.Toolkit.Shared/ErrorList/TableDataSource.cs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ public class TableDataSource : ITableDataSource
1616
/// <summary>
1717
/// Creates a new instance
1818
/// </summary>
19-
/// <param name="identifier">A unique string. It's often the name of the extension itself.</param>
20-
/// <param name="displayName">A unique string. It's often the name of the extension itself.</param>
21-
public TableDataSource(string identifier, string displayName)
19+
/// <param name="name">A unique string. It's often the name of the extension itself.</param>
20+
public TableDataSource(string name)
2221
{
2322
ThreadHelper.ThrowIfNotOnUIThread();
24-
Identifier = identifier;
25-
DisplayName = displayName;
23+
Identifier = name;
24+
DisplayName = name;
2625
Initialize();
2726
}
2827

@@ -41,17 +40,17 @@ public TableDataSource(string identifier, string displayName)
4140
/// </summary>
4241
public virtual IReadOnlyCollection<string> Columns { get; } = new[]
4342
{
44-
StandardTableColumnDefinitions.DetailsExpander,
45-
StandardTableColumnDefinitions.ErrorCategory,
46-
StandardTableColumnDefinitions.ErrorSeverity,
47-
StandardTableColumnDefinitions.ErrorCode,
48-
StandardTableColumnDefinitions.ErrorSource,
49-
StandardTableColumnDefinitions.BuildTool,
50-
StandardTableColumnDefinitions.Text,
51-
StandardTableColumnDefinitions.DocumentName,
52-
StandardTableColumnDefinitions.Line,
53-
StandardTableColumnDefinitions.Column
54-
};
43+
StandardTableColumnDefinitions.DetailsExpander,
44+
StandardTableColumnDefinitions.ErrorCategory,
45+
StandardTableColumnDefinitions.ErrorSeverity,
46+
StandardTableColumnDefinitions.ErrorCode,
47+
StandardTableColumnDefinitions.ErrorSource,
48+
StandardTableColumnDefinitions.BuildTool,
49+
StandardTableColumnDefinitions.Text,
50+
StandardTableColumnDefinitions.DocumentName,
51+
StandardTableColumnDefinitions.Line,
52+
StandardTableColumnDefinitions.Column
53+
};
5554

5655
/// <inheritdoc/>
5756
public string SourceTypeIdentifier => StandardTableDataSources.ErrorTableDataSource;
@@ -127,24 +126,32 @@ private void UpdateAllSinks()
127126
/// <summary>
128127
/// Adds errors to the applicable snapshots.
129128
/// </summary>
130-
/// <param name="projectName"></param>
131-
/// <param name="errors"></param>
132-
public void AddErrors(string projectName, IEnumerable<ErrorListItem> errors)
129+
public void AddErrors(IEnumerable<ErrorListItem> errors)
133130
{
134131
if (errors == null || !errors.Any())
135132
{
136133
return;
137134
}
138135

136+
string? projectName = errors.FirstOrDefault(e => !string.IsNullOrEmpty(e.ProjectName))?.ProjectName ?? "";
137+
139138
IEnumerable<ErrorListItem> cleanErrors = errors.Where(e => e != null && !string.IsNullOrEmpty(e.FileName));
140139

141140
lock (_snapshots)
142141
{
143-
foreach (IGrouping<string?, ErrorListItem>? error in cleanErrors.GroupBy(e => e.FileName))
142+
foreach (IGrouping<string?, ErrorListItem>? fileErrorMap in cleanErrors.GroupBy(e => e.FileName))
144143
{
145-
if (error.Key != null)
144+
if (fileErrorMap.Key != null)
146145
{
147-
_snapshots[error.Key] = new TableEntriesSnapshot(projectName, error.Key, error);
146+
if (_snapshots.ContainsKey(fileErrorMap.Key))
147+
{
148+
IEnumerable<ErrorListItem> values = cleanErrors.Where(e => e.FileName == fileErrorMap.Key);
149+
_snapshots[fileErrorMap.Key].Update(values);
150+
}
151+
else
152+
{
153+
_snapshots[fileErrorMap.Key] = new TableEntriesSnapshot(projectName, fileErrorMap.Key, fileErrorMap);
154+
}
148155
}
149156
}
150157
}

src/toolkit/Community.VisualStudio.Toolkit.Shared/ErrorList/TableEntriesSnapshot.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace Community.VisualStudio.Toolkit
66
{
77
internal class TableEntriesSnapshot : TableEntriesSnapshotBase
88
{
9-
private readonly int _versionNumber = 1;
10-
private readonly IList<ErrorListItem> _errors;
9+
private int _versionNumber = 1;
10+
private readonly List<ErrorListItem> _errors;
1111

1212
public TableEntriesSnapshot(string projectName, string filePath, IEnumerable<ErrorListItem> errors)
1313
{
@@ -16,18 +16,19 @@ public TableEntriesSnapshot(string projectName, string filePath, IEnumerable<Err
1616
_errors = errors.ToList();
1717
}
1818

19-
public string ProjectName { get; private set; }
19+
public string ProjectName { get; }
2020

21-
public string FilePath { get; private set; }
21+
public string FilePath { get; }
2222

23-
public override int Count
24-
{
25-
get { return _errors.Count; }
26-
}
23+
public override int Count => _errors.Count;
24+
25+
public override int VersionNumber => _versionNumber;
2726

28-
public override int VersionNumber
27+
public void Update(IEnumerable<ErrorListItem> errors)
2928
{
30-
get { return _versionNumber; }
29+
_errors.AddRange(errors.Except(_errors));
30+
_errors.RemoveAll(e => !errors.Contains(e));
31+
_versionNumber++;
3132
}
3233

3334
public override bool TryGetValue(int index, string columnName, out object? content)

0 commit comments

Comments
 (0)