提交 23a72b2d 编写于 作者: C Cyrus Najmabadi

Remove default hashing/equality

上级 5c7b1d55
......@@ -15,15 +15,20 @@ public static partial class SymbolFinder
/// Callback object we pass to the OOP server to hear about the result
/// of the FindReferencesEngine as it executes there.
/// </summary>
internal sealed class FindReferencesServerCallback
internal sealed class FindReferencesServerCallback : IEqualityComparer<SerializableSymbolAndProjectId>
{
private readonly Solution _solution;
private readonly IStreamingFindReferencesProgress _progress;
private readonly CancellationToken _cancellationToken;
private readonly object _gate = new object();
private readonly Dictionary<SerializableSymbolAndProjectId, SymbolAndProjectId> _definitionMap =
new Dictionary<SerializableSymbolAndProjectId, SymbolAndProjectId>();
/// <summary>
/// Note: for purposes of Equality/Hashing, all that we use is the underlying SymbolKey. That's because FAR
/// only cares if it is looking at the same symbol, it don't care if the symbol came from a different
/// project or not.
/// </summary>
private readonly Dictionary<SerializableSymbolAndProjectId, SymbolAndProjectId> _definitionMap;
public FindReferencesServerCallback(
Solution solution,
......@@ -33,6 +38,7 @@ internal sealed class FindReferencesServerCallback
_solution = solution;
_progress = progress;
_cancellationToken = cancellationToken;
_definitionMap = new Dictionary<SerializableSymbolAndProjectId, SymbolAndProjectId>(this);
}
public Task AddItemsAsync(int count) => _progress.ProgressTracker.AddItemsAsync(count);
......@@ -85,6 +91,12 @@ public async Task OnDefinitionFoundAsync(SerializableSymbolAndProjectId definiti
await _progress.OnReferenceFoundAsync(symbolAndProjectId, referenceLocation).ConfigureAwait(false);
}
bool IEqualityComparer<SerializableSymbolAndProjectId>.Equals(SerializableSymbolAndProjectId x, SerializableSymbolAndProjectId y)
=> y.SymbolKeyData.Equals(x.SymbolKeyData);
int IEqualityComparer<SerializableSymbolAndProjectId>.GetHashCode(SerializableSymbolAndProjectId obj)
=> obj.SymbolKeyData.GetHashCode();
}
}
}
......@@ -37,27 +37,11 @@ public FindReferencesSearchOptions Rehydrate()
}
}
/// <summary>
/// Note: for purposes of Equality/Hashing, all that we use is the underlying SymbolKey. That's because nearly all
/// IDE features only care if they're looking at the same symbol, they don't care if the symbol came from a
/// different project or not. i.e. a feature like FAR wants to bucket all references to the 'same' originating
/// symbol even if one reference is to a re-targeted version of that symbol. As such, we do not include the
/// ProjectId when computing the result.
/// </summary>
internal class SerializableSymbolAndProjectId : IEquatable<SerializableSymbolAndProjectId>
internal class SerializableSymbolAndProjectId
{
public string SymbolKeyData;
public ProjectId ProjectId;
public override int GetHashCode()
=> SymbolKeyData.GetHashCode();
public override bool Equals(object obj)
=> Equals(obj as SerializableSymbolAndProjectId);
public bool Equals(SerializableSymbolAndProjectId other)
=> other != null && SymbolKeyData.Equals(other.SymbolKeyData);
public static SerializableSymbolAndProjectId Dehydrate(
IAliasSymbol alias, Document document, CancellationToken cancellationToken)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册