Skip to content

Commit

Permalink
- Fix #314 containing types not properly displayed for nested types
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Jan 30, 2024
1 parent 71aa5dd commit 980aa20
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions Codist/Semantics/SymbolFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ public StackPanel ShowSignature(ISymbol symbol) {
if (showContainer) {
b.Append(ThemeHelper.GetImage(cs.GetImageId()).WrapMargin(WpfHelper.GlyphMargin));
}
if ((ct = cs.GetUnderlyingSymbol().ContainingType) != null) {
ShowContainingTypes(ct, b);
}

if (showContainer) {
b.AddSymbol(cs, false, this).Append(" ");
Expand Down Expand Up @@ -158,17 +155,13 @@ public StackPanel ShowSignature(ISymbol symbol) {
b = new ThemedTipText { FontSize = ThemeHelper.ToolTipFontSize, FontFamily = ThemeHelper.ToolTipFont }
.Append(ThemeHelper.GetImage(IconIds.Return).WrapMargin(WpfHelper.GlyphMargin))
.Append(GetRefType(s), Keyword);
if ((ct = rt.GetUnderlyingSymbol().ContainingType) != null
&& rt.Kind != SymbolKind.TypeParameter) {
ShowContainingTypes(ct, b);
}
b.AddSymbol(rt, false, this)
.Append(rt.IsAwaitable() ? $" ({R.T_Awaitable})" : String.Empty);
p.Add(b);
}
#endregion

#region Generic type parameters
#region Generic type constraints
switch (s.Kind) {
case SymbolKind.NamedType:
t = (INamedTypeSymbol)symbol;
Expand Down Expand Up @@ -209,7 +202,8 @@ TextBlock ShowSymbolSignature(ISymbol symbol) {
Foreground = PlainText,
FontFamily = ThemeHelper.ToolTipFont,
FontSize = ThemeHelper.ToolTipFontSize
}.AddSymbol(symbol, true, this);
};
Format(signature.Inlines, symbol, null, true, true);
TextEditorWrapper.CreateFor(signature);
signature.Inlines.FirstInline.FontSize = ThemeHelper.ToolTipFontSize * 1.2;

Expand Down Expand Up @@ -269,17 +263,18 @@ TextBlock ShowSymbolSignature(ISymbol symbol) {
return signature;
}

void ShowContainingTypes(INamedTypeSymbol type, TextBlock signature) {
var n = ImmutableArray.CreateBuilder<INamedTypeSymbol>();
void ShowContainingTypes(INamedTypeSymbol type, InlineCollection text) {
var n = new Stack<INamedTypeSymbol>();
do {
n.Add(type);
n.Push(type);
if (n.Count > 50) {
MessageWindow.Error(String.Join(Environment.NewLine, n.Select(i => i.Name)), "Too many containing types");
break;
}
} while ((type = type.ContainingType) != null);
for (int i = n.Count - 1; i >= 0; i--) {
signature.AddSymbol(n[i], false, this).Append(".");
while (n.Count != 0) {
FormatTypeName(text, n.Pop(), null, false);
text.Add(".");
}
}

Expand Down Expand Up @@ -693,7 +688,7 @@ static string GetRefType(ISymbol symbol) {
return null;
}

internal void Format(InlineCollection text, ISymbol symbol, string alias, bool bold) {
internal void Format(InlineCollection text, ISymbol symbol, string alias, bool bold, bool excludeContainingTypes = false) {
switch (symbol.Kind) {
case SymbolKind.ArrayType:
FormatArrayType(text, (IArrayTypeSymbol)symbol, alias, bold);
Expand All @@ -707,6 +702,9 @@ internal void Format(InlineCollection text, ISymbol symbol, string alias, bool b
FormatMethodName(text, symbol, alias, bold);
return;
case SymbolKind.NamedType:
if (excludeContainingTypes == false && symbol.ContainingType != null) {
ShowContainingTypes(symbol.ContainingType, text);
}
FormatTypeName(text, symbol, alias, bold);
return;
case SymbolKind.Namespace:
Expand Down

0 comments on commit 980aa20

Please sign in to comment.