Skip to content

Commit 896da76

Browse files
committed
fix interpolated components graphed as text control
1 parent 908792f commit 896da76

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/Discord.Net.ComponentDesigner.Generator/Graph/CXGraph.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ GraphInitializationContext context
252252
var current = nodes[i];
253253

254254
if (
255+
!IsInterpolatedComponent(current, context) &&
255256
TextControlElement.TryCreate(
256257
context,
257258
nodes,
@@ -305,6 +306,22 @@ GraphInitializationContext context
305306

306307
foreach (var diagnostic in diagnostics)
307308
context.Diagnostics.Add(diagnostic);
309+
310+
static bool IsInterpolatedComponent(
311+
ICXNode node,
312+
GraphInitializationContext context
313+
) => node switch
314+
{
315+
CXValue.Interpolation { InterpolationIndex: var index } => ComponentBuilderKind.IsValidComponentBuilderType(
316+
context.CX.InterpolationInfos[index].Symbol,
317+
context.Compilation
318+
),
319+
CXToken { InterpolationIndex: { } index } => ComponentBuilderKind.IsValidComponentBuilderType(
320+
context.CX.InterpolationInfos[index].Symbol,
321+
context.Compilation
322+
),
323+
_ => false
324+
};
308325
}
309326

310327
private static IEnumerable<GraphNode> CreateNodes(
@@ -381,7 +398,7 @@ GraphInitializationContext context
381398
}
382399

383400
if (
384-
element.OpeningTag.Identifier is CXIdentifier.Interpolated ||
401+
element.OpeningTag.Identifier is CXIdentifier.Interpolated ||
385402
!ComponentNode.TryGetNode(element.Identifier, out var componentNode)
386403
)
387404
{

src/Discord.Net.ComponentDesigner.Generator/Utils/TypeUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static bool IsInTypeTree(this ITypeSymbol symbol, ITypeSymbol? other)
2020
{
2121
if (other is null) return false;
2222

23-
if (symbol.TypeKind is TypeKind.Class)
23+
if (symbol.TypeKind is TypeKind.Class && other.TypeKind is TypeKind.Class)
2424
{
2525
var current = symbol;
2626

@@ -35,7 +35,7 @@ public static bool IsInTypeTree(this ITypeSymbol symbol, ITypeSymbol? other)
3535
}
3636

3737
return other.Equals(symbol, SymbolEqualityComparer.Default) ||
38-
other.AllInterfaces.Contains(symbol, SymbolEqualityComparer.Default);
38+
symbol.AllInterfaces.Contains(other, SymbolEqualityComparer.Default);
3939
}
4040

4141
public static bool TryGetEnumerableType(this ITypeSymbol? symbol, out ITypeSymbol inner)

tests/ComponentTests/MediaGalleryTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@ namespace UnitTests.ComponentTests;
88

99
public sealed class MediaGalleryTests(ITestOutputHelper output) : BaseComponentTest(output)
1010
{
11+
[Fact]
12+
public void InterpolatedGallery()
13+
{
14+
Graph(
15+
"""
16+
<text>Foo</text>
17+
{new MediaGalleryBuilder(attachments.Select(x => new MediaGalleryItemProperties(new(x))))}
18+
""",
19+
pretext: "IReadOnlyList<string> attachments = null!;"
20+
);
21+
{
22+
Node<TextDisplayComponentNode>();
23+
Node<InterleavedComponentNode>();
24+
25+
Validate(hasErrors: false);
26+
27+
Renders(
28+
"""
29+
new global::Discord.TextDisplayBuilder(
30+
content: "Foo"
31+
),
32+
designer.GetValue<global::Discord.MediaGalleryBuilder>(0)
33+
"""
34+
);
35+
}
36+
}
37+
1138
[Fact]
1239
public void EmptyGallery()
1340
{

0 commit comments

Comments
 (0)