Repository navigation
feat: implement tab completion with JLine3, builtin/PATH/file completion and complete builtin - #5
Merged
Merged
Conversation
- Add JLine3 and jline dependencies to pom.xml - Replace Scanner with JLine3 LineReader in Shell REPL - Add AggregateCompleter with builtin names, file and directory completion - Handle Ctrl+C (UserInterruptException) and Ctrl+D (EndOfFileException) - Add getBuiltinNames() to CommandRegistry for completer access - Configure DefaultParser with no escape chars to avoid conflicts with custom Tokenizer
- Add SystemBinaryCompleter that scans PATH directories for executables - Only completes at word index 0 (command position, not arguments) - Strip extensions on Windows for clean completion (git.exe → git) - Case-insensitive matching for Windows compatibility - Register alongside builtin, file and directory completers
- Add CandidateCollector to separate completion sources by context: builtins and PATH binaries at word index 0, files and dirs for arguments - Enable MENU_COMPLETE, AUTO_MENU, AUTO_LIST options for Tab cycling - Wire CandidateCollector as the single completer in LineReaderBuilder
- Add CompleteBuiltin handling the -p flag to query completion specifications - Reports "no completion specification" for commands without custom completions - Register CompleteBuiltin as singleton in BuiltinFactory enum
…n scripts - Add -C flag support to register external completion scripts per command - Add -p flag to print registered completion specification for a command - Move completion script registry into Environment as shared shell state - Convert CompleteBuiltin from singleton to environment-dependent builtin - Update BuiltinFactory to construct CompleteBuiltin with Environment
- Run registered completion scripts in CandidateCollector when Tab is pressed for commands with a registered completion spec - Pass COMP_LINE and COMP_POINT environment variables to scripts - Collect script stdout lines as completion candidates - Fall back to file completion if script fails or is not registered - Test verified with git-complete.bat on Windows
- Add removeCompletion() to Environment to delete completion registrations - Handle -r flag in CompleteBuiltin to unregister a command's completion spec - Refactor CompleteBuiltin.execute to use switch expression for flag handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements full tab completion support using JLine3, including builtin command completion, PATH executable completion, file/directory completion, and a
completebuiltin for registering custom completion scripts.Changes
Tab Completion
Scannerwith JLine3LineReaderfor interactive inputSystemBinaryCompleterto scan PATH for executables, filtering non-executables on Windows via PATHEXT extensions, stripping extensions for clean completion (git.exe→git)CandidateCollectorfor context-aware completion: builtins and PATH binaries at word index 0, files and dirs for argumentsMENU_COMPLETE,AUTO_MENU,AUTO_LISTfor Tab cyclingcompleteBuiltincompletebuiltin with three flags:-C <script> <command>— register external completion script-p <command>— print registered completion specification-r <command>— remove registered completion specificationEnvironmentas shared shell stateCandidateCollectoron Tab, passingCOMP_LINEandCOMP_POINTenvironment variablesTesting
Manually verified:
ec<Tab>→echo)gi<Tab>→git)complete -C git-complete.bat gitregisters scriptgit <Tab>shows script-provided candidatescomplete -p gitprints registered speccomplete -r gitremoves spec, Tab falls back to file completion