Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial groundwork for command builders (#19) #20

Open
wants to merge 97 commits into
base: main
Choose a base branch
from

Conversation

VelvetToroyashi
Copy link
Contributor

@VelvetToroyashi VelvetToroyashi commented Nov 25, 2022

This PR tracks the work of the described architectural changes described in #19.

This PR will close #19 and #2.

  • Add invocation delegate to CommandNode
  • Add attributes and conditions to CommandNode and GroupNode
  • Rewrite CommandTreeBuilder to generate delegates
  • Ensure current tests pass
  • Add extension methods to expose builders in a convenient manner
  • Add unit tests
  • Add entrypoint for CommandTreeBuilder that allows for adding runtime-defined commands
  • Add support in Remora.Discord.Commands for new changes (requires this PR to be merged first)

@VelvetToroyashi VelvetToroyashi marked this pull request as draft November 25, 2022 20:46
@VelvetToroyashi
Copy link
Contributor Author

VelvetToroyashi commented Nov 26, 2022

As it stands right now, all the supporting code (e.g. CommandNode and GroupNode, parameter shapes, and builders have been implemented).

Remora.Commands/Builders/CommandBuilder.cs Outdated Show resolved Hide resolved
Remora.Commands/Builders/CommandBuilder.cs Outdated Show resolved Hide resolved
Remora.Commands/Builders/CommandBuilder.cs Outdated Show resolved Hide resolved
@Nihlus
Copy link
Member

Nihlus commented Oct 29, 2023

You've still got some unresolved comments on this PR.

@VelvetToroyashi
Copy link
Contributor Author

I can look into this later tonight, if not tomorrow. Hopefully this will be finalized by the end of the week, but if there's anything else that needs to be changed, I'm open to another round of review afterward!

This fixes an issue where methods were not chainable because the return type was the abstract class instead of TSelf. The cast to TSelf is safe by virtue of being an abstract class, so this will always be a derived class.
This commit changes command merging to respect immutability; this comes at the cost of significantly more allocations which should be GC'd.
This commit fixes the merging algorithm by bringing it more in line with what ToChildNodes does. It also fixes an issue where top-level commands were not added to the root node.
This commit removes `IParameterShape#ParameterIndex`

The rationale behind this is that the parameter was only added in the first place to ensure that parameters were parsed in order, however this is moot as the order of the command parameters is determined by the order they're added/created in, anyway, and thus ordering them is just unneccesary overhead.

BREAKING-CHANGE: ParameterIndex was part of the public-facing API and has since been removed. Consumers should store an index when iterating over the command parameters, or use `.IndexOf(T)` on the collection.
@VelvetToroyashi
Copy link
Contributor Author

Oops, just realized why the build was failing in CI.

cc @Nihlus I believe I've resolved all the issues with this PR now.

Remora.Commands/Builders/AbstractCommandBuilder.cs Outdated Show resolved Hide resolved
/// </summary>
/// <param name="attribute">The attriubte to add.</param>
/// <returns>The builder to chain calls with.</returns>
public CommandParameterBuilder AddAttribute(Attribute attribute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to have an overload that takes a generic parameter here with a new() constraint - also lets us do compile-time checking for conditions that don't take any parameters (i.e, where TAttribute : ConditionAttribute and so on)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what kind of checks this would entail

Remora.Commands/Builders/CommandParameterBuilder.cs Outdated Show resolved Hide resolved
Remora.Commands/Builders/CommandParameterBuilder.cs Outdated Show resolved Hide resolved
Remora.Commands/Builders/GroupBuilder.cs Outdated Show resolved Hide resolved
Remora.Commands/Builders/GroupBuilder.cs Outdated Show resolved Hide resolved
Remora.Commands/Remora.Commands.csproj Show resolved Hide resolved
}

if (this.Min is null or 0)
else if (this.Min is null or 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially redundant else - check.

@Nihlus
Copy link
Member

Nihlus commented Apr 2, 2024

Please rebase this onto the latest commit so you get all the required ReSharper inspection checks.

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

Successfully merging this pull request may close these issues.

Consolidation of abstracting away from Type reliance
5 participants