Skip to content

WIP: Tab completions

BafDyce requested to merge BafDyce/ion:tab-completions-wip into master

IMPORTANT This is sorta, kinda WIP and NOT intended to be merged as it is! The code still needs a few tweaks, and the commits are not meaningful on their own (I just committed all wip-stuff at once when I made breaks). This is more like a proposal and a basis for discussion.

Problem: This PR adds support for tab completions. See #397

Solution: The general idea: For each application, there is a user-friendly config file (RON-format) which defines different types of command line parameters, etc. Currently supported features:

  • boolean flags (e.g. --version)
  • paths
  • files with specific file extensions
  • numbers
  • key=value
  • string (aka "everything else that takes custom values") with support for options (predefined list of possible values)

If an application has no completion-config, the default file file completer is used.

Changes introduced by this pull request:

  • New dependencies: libflate, ron, serde
  • A new completer (IonCmdCompleter) was created, similar to the existing IonFileCompleter
  • When the user hits tab twice and the application (first word on the command line) has a completion defined, it is examined for possible matches.
  • I've added a base ("empty") config file as well as two (unfinished) configs for cargo and git.

Drawbacks:

  • I don't know if my code structure/architecture is fine, as I figured out how liner works as I worked on this, so the code may be restructured more cleanly?
  • Also, I had to add an unsafe (https://gitlab.redox-os.org/BafDyce/ion/blob/adb13743757078f021614e89a8820958ea15203e/src/lib/shell/completer.rs#L71) to satisfy the borrow checker. Don't know if this can be avoided by restructuring.
  • Aliases (different names for the same application) are not handled/implemented yet.
  • Tab completions don't work when using the absolute path
    • For both issues we would need some efficient HashMap-like data structure to map multiple keys to the same value

TODOs:

  • Discuss whether such a config-file based solution is wanted. mmstick seems to be OK with it!? ;)
  • Add support for "dynamic" parameters (list of completions generated at runtime by executing an ion script?)
  • Add support for "scheme" parameters
  • Decide where to save the config files -> ION_CONFIG_DIR/completions/
    • Add hook for installation script
    • Adapt initialization code accordingly Implement lazy-loading functionality
  • Fix issue: auto-complete does not work if the cursor is on the right edge of a completed parameter (no space is inserted afterwards) Fixed by recent liner upgrade
  • Cleanup the code, Add comments
  • Rebase onto current master and fix merge conflicts
  • Add a new builtin for (re)loading completions at runtime
  • Implement parsers to import completions:
    • From man-pages
      • Improve parsing capabilities (subcommands, detect & filter invalid parsed files)
  • Test on Redox (currently only on Linux tested)
  • Add a bunch of completion configs.
  • Add completions for ion builtins
  • CI: Add validation of supplied completion files (just check whether they can be parsed correctly)
  • rustmft
  • clippy
  • Bug fixes

Fixes: #397

State: WIP

Blocking/related: None that I know of.

Other:

I'm open for feedback, however I'll also be busy in the next days.

Edit 2018-06-17: Update text to match current state of MR

Edited by BafDyce

Merge request reports