Skip to content

[2.x] fix: Fixes java++ tab completion#8778

Merged
eed3si9n merged 10 commits intosbt:developfrom
bitloi:fix/java-plus-plus-completion-4310
Feb 23, 2026
Merged

[2.x] fix: Fixes java++ tab completion#8778
eed3si9n merged 10 commits intosbt:developfrom
bitloi:fix/java-plus-plus-completion-4310

Conversation

@bitloi
Copy link
Copy Markdown
Contributor

@bitloi bitloi commented Feb 22, 2026

Fixes #4310

Problem

Typing java++ (with space) and pressing Tab caused JLine to show "Display all 1114782 possibilities? (y or n)" because the optional-command argument used matched(state.combinedParser) with no completion limit.

Solution

  • Limit tab completions for the optional command after java++ to a small fixed list: -v, compile, test, run, clean, console, package.
  • Use .examples(JavaSwitchCommandCompletions*) on the optional-command token in switchParser (CrossJava.scala).
  • Add CrossJavaTest test that the completion list is bounded and contains key entries.

Verification

  1. ./sbt "mainProj/Test/testOnly sbt.internal.CrossJavaTest" — all 16 tests pass (including "java++ tab completion list is bounded (Too many candidate list "java++" command tab completion #4310)").
  2. Manual: start sbt, type java++ and Tab — completions are a short list, not "Display all N possibilities?".

Root cause

  • optionalCommand was Parser.opt(token(Space ~> matched(state.combinedParser))); matched(combinedParser) delegates completions to the full sbt grammar, yielding millions of candidates.
  • Fix: same pattern as BasicCommands.reportParser and NetworkChannel.disconnect — cap completions via .examples(...).

- Limit optional-command completions after 'java++ ' to a small fixed list
  (-v, compile, test, run, clean, console, package) so JLine no longer
  prompts 'Display all 1114782 possibilities?'.
- Add JavaSwitchCommandCompletions and use .examples(...) on the
  matched(combinedParser) token in switchParser.
- Add CrossJavaTest test asserting the completion list is bounded and
  contains -v, compile, test.

Fixes sbt#4310
…plus-completion

- CrossJavaTest: use Fewer Braces for java++ completion test
- Add scripted test that asserts java++ completions are bounded (<=100)
Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks. This looks great.

@eed3si9n eed3si9n changed the title Fix java++ tab completion showing 1M+ candidates (#4310) [2.x] fix: Fixes java++ tab completion Feb 22, 2026
bitloi and others added 4 commits February 22, 2026 00:21
Move .examples(JavaSwitchCommandCompletions*) from outside token() to
inside on matched(state.combinedParser). The prior placement caused
FixedSetExamples.withAddedPrefix to filter out all examples after the
space character was derived, yielding zero completions after the user
typed the space before the command.

Remove actions/java-plus-plus-completion scripted test that called
Parser.completions on the full state.combinedParser, which is too
expensive and caused the CI job to timeout. The unit test in
CrossJavaTest already covers the fix adequately.
Per review, the OOM comes from the version parser - token(StringBasic)
on the right side of || has no examples constraint. Move
.examples(knownVersions*) from the inner number parser to wrap the
entire || expression, so both alternatives are bounded.
@bitloi bitloi requested a review from eed3si9n February 23, 2026 01:16
Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks!

@eed3si9n eed3si9n merged commit 20f4a9c into sbt:develop Feb 23, 2026
15 checks passed
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.

Too many candidate list "java++" command tab completion

2 participants