Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #739 from DustinCampbell/fix-unit-tests-in-nested-…
…classes Fix running unit tests defined in nested classes
- Loading branch information
Showing
2 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/OmniSharp.Abstractions/Extensions/ISymbolExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.CodeAnalysis; | ||
namespace OmniSharp.Extensions | ||
{ | ||
public static class ISymbolExtensions | ||
{ | ||
private readonly static CachedStringBuilder s_cachedBuilder; | ||
|
||
public static string GetMetadataName(this ISymbol symbol) | ||
{ | ||
if (symbol == null) | ||
{ | ||
throw new ArgumentNullException(nameof(symbol)); | ||
} | ||
|
||
var symbols = new Stack<ISymbol>(); | ||
|
||
while (symbol != null) | ||
{ | ||
if (symbol.Kind == SymbolKind.Assembly || | ||
symbol.Kind == SymbolKind.NetModule) | ||
{ | ||
break; | ||
} | ||
|
||
if ((symbol as INamespaceSymbol)?.IsGlobalNamespace == true) | ||
{ | ||
break; | ||
} | ||
|
||
symbols.Push(symbol); | ||
symbol = symbol.ContainingSymbol; | ||
} | ||
|
||
var builder = s_cachedBuilder.Acquire(); | ||
try | ||
{ | ||
ISymbol current = null, previous = null; | ||
|
||
while (symbols.Count > 0) | ||
{ | ||
current = symbols.Pop(); | ||
|
||
if (previous != null) | ||
{ | ||
if (previous.Kind == SymbolKind.NamedType && | ||
current.Kind == SymbolKind.NamedType) | ||
{ | ||
builder.Append('+'); | ||
} | ||
else | ||
{ | ||
builder.Append('.'); | ||
} | ||
} | ||
|
||
builder.Append(current.MetadataName); | ||
|
||
previous = current; | ||
} | ||
|
||
return builder.ToString(); | ||
} | ||
finally | ||
{ | ||
s_cachedBuilder.Release(builder); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters