Skip to content

Commit

Permalink
! Made FindReferrers for generic bound type members work in VS 2019
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Sep 15, 2021
1 parent 5f8d8ed commit 7aa6311
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Codist/Helpers/CodeAnalysisHelper.Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ public static ISymbol GetAliasTarget(this ISymbol symbol) {
return symbol.Kind == SymbolKind.Alias ? (symbol as IAliasSymbol).Target : symbol;
}

public static IEnumerable<INamedTypeSymbol> GetContainingTypes(this ISymbol symbol) {
var t = symbol.ContainingType;
while (t != null) {
yield return t;
t = t.ContainingType;
}
}

public static ITypeSymbol ResolveElementType(this ITypeSymbol t) {
switch (t.Kind) {
case SymbolKind.ArrayType: return ResolveElementType(((IArrayTypeSymbol)t).ElementType);
Expand Down
12 changes: 6 additions & 6 deletions Codist/Helpers/CodeAnalysisHelper.SymbolFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,19 +425,19 @@ public static KeyValuePair<ISymbol, int>[] FindReferencingSymbols(this SyntaxNod
Predicate<SymbolUsageKind> usageFilter = null;
switch (symbol.Kind) {
case SymbolKind.NamedType:
if ((symbol as INamedTypeSymbol).IsBoundedGenericType()) {
// hack: In VS 2017 with Rosyln 2.10, we don't need this,
// but in VS 2019, we have to do that, otherwise we will get nothing.
// The same to SymbolKind.Method.
if ((symbol as INamedTypeSymbol).IsBoundedGenericType()
|| symbol.GetContainingTypes().Any(t => t.IsBoundedGenericType())) {
sign = symbol.ToDisplayString();
// hack: in VS 2017 with Rosyln 2.10, we don't need this,
// but in VS 2019, we have to do that, otherwise we will get nothing
symbol = symbol.OriginalDefinition;
}
break;
case SymbolKind.Method:
var m = symbol as IMethodSymbol;
if (m.IsBoundedGenericMethod()) {
if (m.IsBoundedGenericMethod() || m.GetContainingTypes().Any(t => t.IsBoundedGenericType())) {
sign = symbol.ToDisplayString();
// hack: in VS 2017 with Rosyln 2.10, we don't need this,
// but in VS 2019, we have to do that, otherwise we will get nothing
symbol = symbol.OriginalDefinition;
}
else if (m.IsExtensionMethod) {
Expand Down

0 comments on commit 7aa6311

Please sign in to comment.