Skip to content

UX: Tab completion for file paths and commands #25

@evansenter

Description

@evansenter

Summary

Add tab completion in the REPL for:

  • File paths
  • Slash commands (/help, /clear, etc.)
  • Shell escape commands (!git, !cargo, etc.)

Current State

rustyline supports custom completers via the Completer trait. Clemini currently uses DefaultEditor without custom completion.

Proposed Completions

Slash commands

> /cl<TAB>  →  /clear
> /st<TAB>  →  /stats (or cycle: /stats, /status)

File paths (when context suggests a path)

> read src/too<TAB>  →  read src/tools/
> read src/tools/<TAB>  →  (shows: bash.rs, edit.rs, ...)

Shell escapes

> !car<TAB>  →  !cargo
> !cargo bu<TAB>  →  !cargo build

Implementation Notes

use rustyline::completion::{Completer, Pair};

struct CleminiCompleter {
    cwd: PathBuf,
}

impl Completer for CleminiCompleter {
    fn complete(&self, line: &str, pos: usize) -> Result<(usize, Vec<Pair>)> {
        if line.starts_with('/') {
            // Complete slash commands
        } else if line.starts_with('!') {
            // Complete shell commands  
        } else {
            // Could do path completion for quoted strings
        }
    }
}

Related

  • rustyline Helper trait combines Completer, Highlighter, Hinter, Validator

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions