Offer the pack option when module completion has no pack to resolve

This commit is contained in:
piexel committed 2026-11-10 16:53:11 +01:00
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();
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 {
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());
if (typed.words().isEmpty()) {
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) {
try {
CommandLine line = CommandLine.of(tokens);
@@ -450,6 +450,15 @@ public class ToolingCommandsTest {
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
public void completionNeverThrows() {
assertEquals(List.of(), complete("tools "));