@@ -5,39 +5,38 @@ Subject: [PATCH] fix invalid suggestions caused by dynamic arguments
55
66
77diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandTree.java b/cloud-core/src/main/java/cloud/commandframework/CommandTree.java
8- index 668239c78e25c999c6fbc9c32251b794e09cd80e..f4b95ea61e77ac0da7abed7f25588328e27238f0 100644
8+ index 668239c78e25c999c6fbc9c32251b794e09cd80e..053f5b1def212f0d3cef1a5db527fcdd2363952d 100644
99--- a/cloud-core/src/main/java/cloud/commandframework/CommandTree.java
1010+++ b/cloud-core/src/main/java/cloud/commandframework/CommandTree.java
11- @@ -702,9 +702,25 @@ public final class CommandTree<C> {
11+ @@ -702,10 +702,25 @@ public final class CommandTree<C> {
1212 // START: Parsing
1313 commandContext.setCurrentArgument(child.getValue());
1414 final ArgumentParseResult<?> result = child.getValue().getParser().parse(commandContext, commandQueue);
1515- if (result.getParsedValue().isPresent() && !commandQueue.isEmpty()) {
1616- commandContext.store(child.getValue().getName(), result.getParsedValue().get());
17- - return this.getSuggestions(commandContext, commandQueue, child);
1817+ // CloudNet start - fix suggestions for dynamic arguments
1918+ final Optional<?> parsedValue = result.getParsedValue();
2019+ final boolean parseSuccess = parsedValue.isPresent();
2120+
22- + if ((parseSuccess && !commandQueue.isEmpty()) || (!parseSuccess && commandQueue.size() > 1)) {
23- + if (parseSuccess) {
24- + // the current argument at the position is parsable and there are more arguments following
25- + commandContext.store(child.getValue().getName(), parsedValue.get());
26- + return this.getSuggestions(commandContext, commandQueue, child);
27- + } else {
28- + // at this point there should normally be no need to reset the command queue as we expect
29- + // users to only take out an argument if the parse succeeded. Just to be sure we do it anyway
30- + commandQueue.clear();
31- + commandQueue.addAll(commandQueueOriginal);
32- + // there are more arguments following but the current argument isn't matching - there
33- + // is no need to collect any further suggestions
34- + return Collections.emptyList();
35- + }
36- + // CloudNet end
21+ + if (parseSuccess && !commandQueue.isEmpty()) {
22+ + // the current argument at the position is parsable and there are more arguments following
23+ + commandContext.store(child.getValue().getName(), parsedValue.get());
24+ return this.getSuggestions(commandContext, commandQueue, child);
25+ + } else if (!parseSuccess && commandQueueOriginal.size() > 1) {
26+ + // at this point there should normally be no need to reset the command queue as we expect
27+ + // users to only take out an argument if the parse succeeded. Just to be sure we reset anyway
28+ + commandQueue.clear();
29+ + commandQueue.addAll(commandQueueOriginal);
30+ +
31+ + // there are more arguments following but the current argument isn't matching - there
32+ + // is no need to collect any further suggestions
33+ + return Collections.emptyList();
3734 }
35+ + // CloudNet end
3836 // END: Parsing
3937 }
40- @@ -713,6 +729,15 @@ public final class CommandTree<C> {
38+
39+ @@ -713,6 +728,15 @@ public final class CommandTree<C> {
4140 commandQueue.clear();
4241 commandQueue.addAll(commandQueueOriginal);
4342
0 commit comments