mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 18:24:06 +00:00
Offer the pack option when module completion has no pack to resolve
This commit is contained in:
1 parent
a00e4bbdf0
commit
22b193e70a
2 files changed
+20
-2
No files matched your search
@@ -119,11 +119,16 @@ public final class ToolingCommands {
|
|||||||
}
|
}
|
||||||
String partial = words.getLast();
|
String partial = words.getLast();
|
||||||
if (partial.startsWith(CommandLine.PACK_OPTION)) {
|
if (partial.startsWith(CommandLine.PACK_OPTION)) {
|
||||||
return packs.names().stream().map(name -> CommandLine.PACK_OPTION + name).filter(option -> option.startsWith(partial)).toList();
|
return packOptions(partial);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
CommandLine typed = CommandLine.of(words.subList(0, words.size() - 1));
|
CommandLine typed = CommandLine.of(words.subList(0, words.size() - 1));
|
||||||
ResolvedPack pack = resolvePack(sender, typed.packName());
|
ResolvedPack pack;
|
||||||
|
try {
|
||||||
|
pack = resolvePack(sender, typed.packName());
|
||||||
|
} catch (CommandFailure noPackInReach) {
|
||||||
|
return packOptions(partial);
|
||||||
|
}
|
||||||
List<CommandRegistration> roots = rootsOf(pack.served());
|
List<CommandRegistration> roots = rootsOf(pack.served());
|
||||||
if (typed.words().isEmpty()) {
|
if (typed.words().isEmpty()) {
|
||||||
return roots.stream()
|
return roots.stream()
|
||||||
@@ -142,6 +147,10 @@ public final class ToolingCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> packOptions(String partial) {
|
||||||
|
return packs.names().stream().map(name -> CommandLine.PACK_OPTION + name).filter(option -> option.startsWith(partial)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean run(ToolingSender sender, List<String> tokens, boolean onlyIfOpenToEveryone) {
|
private boolean run(ToolingSender sender, List<String> tokens, boolean onlyIfOpenToEveryone) {
|
||||||
try {
|
try {
|
||||||
CommandLine line = CommandLine.of(tokens);
|
CommandLine line = CommandLine.of(tokens);
|
||||||
|
|||||||
@@ -450,6 +450,15 @@ public class ToolingCommandsTest {
|
|||||||
assertEquals(List.of(), complete("locked "));
|
assertEquals(List.of(), complete("locked "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withoutAPackInReachCompletionOffersThePackOption() {
|
||||||
|
packWith("alpha", recording("give"));
|
||||||
|
packWith("beta", recording("take"));
|
||||||
|
|
||||||
|
assertEquals(List.of("pack=alpha", "pack=beta"), complete(""));
|
||||||
|
assertEquals(List.of("give"), complete("pack=alpha "));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void completionNeverThrows() {
|
public void completionNeverThrows() {
|
||||||
assertEquals(List.of(), complete("tools "));
|
assertEquals(List.of(), complete("tools "));
|
||||||
|
|||||||
Reference in new issue
Block a user