Skip to content

feat: implement tab completion with JLine3, builtin/PATH/file completion and complete builtin - #5

Merged
podlLev merged 8 commits into
mainfrom
feature/completion
Jul 4, 2026
Merged

podlLev merged 8 commits into
mainfrom
feature/completion

Conversation

@podlLev

@podlLev podlLev commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

Implements full tab completion support using JLine3, including builtin command completion, PATH executable completion, file/directory completion, and a complete builtin for registering custom completion scripts.

Changes

Tab Completion

  • Replace Scanner with JLine3 LineReader for interactive input
  • Add SystemBinaryCompleter to scan PATH for executables, filtering non-executables on Windows via PATHEXT extensions, stripping extensions for clean completion (git.exe → git)
  • Add CandidateCollector for context-aware completion: builtins and PATH binaries at word index 0, files and dirs for arguments
  • Enable MENU_COMPLETE, AUTO_MENU, AUTO_LIST for Tab cycling

complete Builtin

  • Add complete builtin with three flags:
    • -C <script> <command> — register external completion script
    • -p <command> — print registered completion specification
    • -r <command> — remove registered completion specification
  • Store completion registrations in Environment as shared shell state
  • Run registered scripts in CandidateCollector on Tab, passing COMP_LINE and COMP_POINT environment variables
  • Fall back to file completion if no script is registered

Testing

Manually verified:

  • Tab completes builtin names (ec<Tab> → echo)
  • Tab completes PATH executables (gi<Tab> → git)
  • Tab completes file/directory paths for arguments
  • complete -C git-complete.bat git registers script
  • git <Tab> shows script-provided candidates
  • complete -p git prints registered spec
  • complete -r git removes spec, Tab falls back to file completion

podlLev added 8 commits July 4, 2026 13:54
- 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
@podlLev podlLev self-assigned this Jul 4, 2026
@podlLev podlLev added the enhancement New feature or request label Jul 4, 2026
@podlLev
podlLev merged commit b363ef9 into main Jul 4, 2026
@podlLev
podlLev deleted the feature/completion branch July 4, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant