perchance fix suggestions not showing when the literal is valid
Some checks failed
/ deploy (push) Has been cancelled
/ test (push) Has been cancelled

This commit is contained in:
kento2 2026-08-30 12:10:14 +02:00
parent 21c1bf72c6
commit c22f707556
4 changed files with 20 additions and 12 deletions

View file

@ -2,7 +2,6 @@ package site.lab0x13.scrow.commands;
import site.lab0x13.scrow.commands.model.CommandContext; import site.lab0x13.scrow.commands.model.CommandContext;
import site.lab0x13.scrow.commands.model.literal.LiteralMeta; import site.lab0x13.scrow.commands.model.literal.LiteralMeta;
import site.lab0x13.scrow.commands.model.literal.MessageStyle;
import site.lab0x13.scrow.commands.model.literal.RootLiteral; import site.lab0x13.scrow.commands.model.literal.RootLiteral;
import site.lab0x13.scrow.commands.parser.NodeTreeWalker; import site.lab0x13.scrow.commands.parser.NodeTreeWalker;
import site.lab0x13.scrow.commands.parser.WalkResult; import site.lab0x13.scrow.commands.parser.WalkResult;
@ -45,23 +44,18 @@ public class CommandHandler<C extends CommandContext<C>> {
String input = null; String input = null;
switch (walkResult) { switch (walkResult) {
case WalkResult.LiteralUnknown<C> res -> { case WalkResult.LiteralUnknown<C> res -> {
stream = res.lastLiteral().subLiteralMetas().stream() stream = filterMetas(ctx, res.lastLiteral().subLiteralMetas());
.filter(literalMeta -> platformAdapter.checkPermission(ctx, literalMeta.permission()))
.map(LiteralMeta::names)
.flatMap(Collection::stream);
input = res.input(); input = res.input();
} }
case WalkResult.LiteralExpected<C> res when trailingSpace -> case WalkResult.LiteralExpected<C> res when trailingSpace ->
stream = res.lastLiteral().subLiteralMetas().stream() stream = filterMetas(ctx, res.lastLiteral().subLiteralMetas());
.filter(literalMeta -> platformAdapter.checkPermission(ctx, literalMeta.permission()))
.map(LiteralMeta::names)
.flatMap(Collection::stream);
case WalkResult.ArgumentIllegal<C> res -> { case WalkResult.ArgumentIllegal<C> res -> {
stream = res.arg().suggestionProvider().suggest(ctx, res.input()).stream(); stream = res.arg().suggestionProvider().suggest(ctx, res.input()).stream();
input = res.input(); input = res.input();
} }
case WalkResult.ArgumentExpected<C> res when trailingSpace -> case WalkResult.ArgumentExpected<C> res when trailingSpace ->
stream = res.arg().suggestionProvider().suggest(ctx, "").stream(); stream = res.arg().suggestionProvider().suggest(ctx, "").stream();
case WalkResult.Complete<C> res when !trailingSpace -> stream = filterMetas(ctx, res.alternativeLiterals());
default -> { default -> {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -73,4 +67,11 @@ public class CommandHandler<C extends CommandContext<C>> {
.filter(s -> s.startsWith(finalInput)) .filter(s -> s.startsWith(finalInput))
.toList(); .toList();
} }
private Stream<String> filterMetas(C ctx, List<? extends LiteralMeta> metas) {
return metas.stream()
.filter(literalMeta -> platformAdapter.checkPermission(ctx, literalMeta.permission()))
.map(LiteralMeta::names)
.flatMap(Collection::stream);
}
} }

View file

@ -7,6 +7,7 @@ import site.lab0x13.scrow.commands.model.argument.Argument;
import site.lab0x13.scrow.commands.model.literal.Literal; import site.lab0x13.scrow.commands.model.literal.Literal;
import site.lab0x13.scrow.commands.model.literal.RootLiteral; import site.lab0x13.scrow.commands.model.literal.RootLiteral;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
@ -25,6 +26,7 @@ public class NodeTreeWalker<C extends CommandContext<C>> {
Iterator<String> iter Iterator<String> iter
) { ) {
var cursor = new Cursor(iter); var cursor = new Cursor(iter);
Literal<C> previousLiteral = null;
Literal<C> literal = rootLiteral; Literal<C> literal = rootLiteral;
while (true) { while (true) {
@ -41,6 +43,7 @@ public class NodeTreeWalker<C extends CommandContext<C>> {
var nextLiteral = literal.getSubLiteral(literalName); var nextLiteral = literal.getSubLiteral(literalName);
if (nextLiteral == null || !platformAdapter.checkPermission(ctx, nextLiteral.permission())) if (nextLiteral == null || !platformAdapter.checkPermission(ctx, nextLiteral.permission()))
return new WalkResult.LiteralUnknown<>(ctx, literal, literalName); return new WalkResult.LiteralUnknown<>(ctx, literal, literalName);
previousLiteral = literal;
literal = nextLiteral; literal = nextLiteral;
} }
@ -49,7 +52,7 @@ public class NodeTreeWalker<C extends CommandContext<C>> {
return new WalkResult.LiteralExpected<>(ctx, literal, isOptional); return new WalkResult.LiteralExpected<>(ctx, literal, isOptional);
} }
return new WalkResult.Complete<>(ctx, literal); return new WalkResult.Complete<>(ctx, literal, previousLiteral == null ? Collections.emptyList() : previousLiteral.subLiteralMetas());
} }
private @Nullable WalkResult<C> walkArgument( private @Nullable WalkResult<C> walkArgument(

View file

@ -4,6 +4,9 @@ import org.jetbrains.annotations.Nullable;
import site.lab0x13.scrow.commands.model.CommandContext; import site.lab0x13.scrow.commands.model.CommandContext;
import site.lab0x13.scrow.commands.model.argument.Argument; import site.lab0x13.scrow.commands.model.argument.Argument;
import site.lab0x13.scrow.commands.model.literal.Literal; import site.lab0x13.scrow.commands.model.literal.Literal;
import site.lab0x13.scrow.commands.model.literal.LiteralMeta;
import java.util.List;
public sealed interface WalkResult<C extends CommandContext<C>> { public sealed interface WalkResult<C extends CommandContext<C>> {
C ctx(); C ctx();
@ -65,7 +68,8 @@ public sealed interface WalkResult<C extends CommandContext<C>> {
record Complete<C extends CommandContext<C>>( record Complete<C extends CommandContext<C>>(
C ctx, C ctx,
Literal<C> lastLiteral Literal<C> lastLiteral,
List<? extends LiteralMeta> alternativeLiterals
) implements WalkResult<C> { ) implements WalkResult<C> {
@Override @Override
public boolean isValidUsage() { public boolean isValidUsage() {

View file

@ -1,2 +1,2 @@
GROUP = "site.lab0x13.scrow" GROUP = "site.lab0x13.scrow"
VERSION = "1.3.4" VERSION = "1.3.5"