Skip to content

Conversation

quinchs
Copy link
Member

@quinchs quinchs commented Sep 6, 2025

Summary

This PR adds a 'html' like way to design and build components, specifically v2 components, providing design-time error analysis based off of the constraints of the Discord API.

Currently, the support is pretty basic, only allowing discords defined components, but in the future this could be expanded apon to create stateful and custom components.

Blockers

Performance

The custom XML parser is a one-and-done full parser, and could be greatly improved with incremental parsing, given the source tree from the C# generator. This would greatly speed up the parsing of the CXML.

As of right now, after the parse step, the entire component node tree is regenerated, which again could benefit from incremental mutations

Testing

There are no tests for any of this, and that smells, some good tests for parsing, diagnostic reporting, and so on are needed.

Future prospects

As mentioned earlier, the possibilities with this feature can extend out to a full dom-like renderer and state manager, making stateful cards super trivial to implement:

public class Counter : CXmlComponent
{
    public int Count { get; set; }
    
    public override IMessageComponentBuilder Render()
    {
        return cx(
            $"""
            <text>
                You've clicked {Count} times!
            </text>
            <row>
                <button customId="clickme" onClick={HandleClick}/>
            </row>
            """
        );
    }

    public void HandleClick(IDiscordInteraction interaction)
    {
        Count += 1;
    }
}

The possibilities are quite literally endless with this.

Custom IDE language plugin

It would also be trivial to implement a custom LSP for the components, and provide both VS, VSC, and jetbrains plugins to support them in the StringSyntax attribute used for the basic highlighting in the CXML strings

Copy link

github-actions bot commented Sep 6, 2025

Test Results

0 files   -   1  0 suites   - 1   0s ⏱️ ±0s
0 tests  - 230  0 ✅  - 230  0 💤 ±0  0 ❌ ±0 
0 runs   - 237  0 ✅  - 237  0 💤 ±0  0 ❌ ±0 

Results for commit 600d813. ± Comparison against base commit 927c905.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant