Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completions not working #307

Open
mcastorina opened this issue Feb 9, 2022 · 8 comments
Open

Completions not working #307

mcastorina opened this issue Feb 9, 2022 · 8 comments
Labels
A-Completions Area: Tab completion and inline hint completions A-KeybindingEmacs Area: Handling of default (Emacs style) keybindings documentation Improvements or additions to documentation

Comments

@mcastorina
Copy link

Platform linux
Terminal software rxvt-unicode

The example completions program compiles, runs, and displays a prompt. Typing a few characters then TAB or Ctrl+X does not complete the expected word or display a menu of possible completions. It appears to have the same behavior as without calling with_completions.

Steps to reproduce

[dependencies]
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }

I did this today so I believe it's 8c565e4 though I don't know how to confirm this in the project.

use reedline::{DefaultCompleter, DefaultPrompt, Reedline, Signal};

fn main() {
    let prompt = DefaultPrompt::default();

    let commands = vec![
        "test".into(),
        "hello world".into(),
        "hello world reedline".into(),
        "this is the reedline crate".into(),
    ];
    let completer = Box::new(DefaultCompleter::new_with_wordlen(commands, 2));
    let mut line_editor = Reedline::create().unwrap().with_completer(completer);

    loop {
        let sig = line_editor.read_line(&prompt).unwrap();
        match sig {
            Signal::Success(buffer) => {
                println!("We processed: {}", buffer);
            }
            Signal::CtrlD | Signal::CtrlC => {
                println!("\nAborted!");
                break;
            }
            Signal::CtrlL => {
                line_editor.clear_screen().unwrap();
            }
        }
    }
}
@mcastorina mcastorina added the bug Something isn't working label Feb 9, 2022
@sholderbach sholderbach added A-Completions Area: Tab completion and inline hint completions A-KeybindingEmacs Area: Handling of default (Emacs style) keybindings documentation Improvements or additions to documentation labels Feb 9, 2022
sholderbach added a commit to sholderbach/reedline that referenced this issue Feb 23, 2022
Keybindings are currently configured to require the completion menu. To
use the completions you have to manually add it.

Undocumented: Changing the keybindings to use the old bash style
completions with `CircularCompletionHandler`

Track nushell#307
sholderbach added a commit that referenced this issue Feb 24, 2022
Keybindings are currently configured to require the completion menu. To
use the completions you have to manually add it.

Undocumented: Changing the keybindings to use the old bash style
completions with `CircularCompletionHandler`

Track #307
@sholderbach sholderbach removed the bug Something isn't working label Mar 16, 2022
@DhruvDh
Copy link
Contributor

DhruvDh commented Apr 6, 2022

Hi, the completion menu is still not working for me -

Platform macos-aarch64
Terminal software: kitty

The example completions program compiles, runs, and displays a prompt. Typing a few characters then TAB or Ctrl+X does not complete the expected word or display a menu of possible completions. It appears to have the same behavior as without calling with_completions.

Steps to reproduce -

[dependencies]
reedline = { version = "0.3", features = ["clipboard", "system_clipboard"] }
use anyhow::Result;
use nu_ansi_term::{Color, Style};
use reedline::{
    CompletionMenu, DefaultCompleter, DefaultHinter, DefaultPrompt, ExampleHighlighter,
    FileBackedHistory, Reedline, Signal,
};

fn main() -> Result<()> {
    let prompt = DefaultPrompt::default();
    let history = Box::new(
        FileBackedHistory::with_file(5, "history.txt".into())
            .expect("Error configuring history with file"),
    );

    let commands = vec![
        "test".into(),
        "hello world".into(),
        "hello world reedline".into(),
        "this is the reedline crate".into(),
    ];

    let completer = Box::new(DefaultCompleter::new(commands.clone()));
    // Use the interactive menu to select options from the completer
    let completion_menu = Box::new(CompletionMenu::default());

    let mut line_editor = Reedline::create()?
        .with_completer(completer)
        .with_menu(completion_menu)
        .with_history(history)
        .expect("Error configuring reedline with history")
        .with_highlighter(Box::new(ExampleHighlighter::new(commands)))
        .with_hinter(Box::new(
            DefaultHinter::default().with_style(Style::new().italic().fg(Color::LightGray)),
        ));

    loop {
        let sig = line_editor.read_line(&prompt)?;
        match sig {
            Signal::Success(buffer) => {
                println!("We processed: {}", buffer);
            }
            Signal::CtrlD | Signal::CtrlC => {
                println!("\nAborted!");
                break Ok(());
            }
            Signal::CtrlL => {
                line_editor.clear_screen().unwrap();
            }
        }
    }
}

@DhruvDh
Copy link
Contributor

DhruvDh commented Apr 6, 2022

I should have dug around the new commits after release more, I think I got it to work after reading main.rs. Keybindings for the completion menu were missing, and ListMenu just wasn't working for me, but ColumnarMenu was. I am not familiar with the codebase so I am not confident in saying whether I did something wrong or it's a bug with ListMenu.

@sholderbach
Copy link
Member

Mhh @elferherrera, did something relating the general API change with your latest menu changes?

@elferherrera
Copy link
Contributor

elferherrera commented Apr 7, 2022

Not really.

@DhruvDh when you say the list menu doesn't work, what do you mean?

@DhruvDh
Copy link
Contributor

DhruvDh commented Apr 7, 2022

Sorry for not having a minimal reproduction, but this is from the repo https://github.com/DhruvDh/umm/tree/next at https://github.com/DhruvDh/umm/blob/next/src/main.rs.

This is how I am creating a line editor - https://github.com/DhruvDh/umm/blob/06f046abbaa1dc2500692c70c7d05b846d358b8a/src/main.rs#L61-L103

    let mut line_editor = Reedline::create()
        .with_history(Box::new(
            FileBackedHistory::with_file(5, "history.txt".into())
                .expect("Error configuring history with file"),
        ))
        .with_highlighter(Box::new(ExampleHighlighter::new(commands.clone())))
        .with_hinter(Box::new(
            DefaultHinter::default().with_style(Style::new().italic().fg(Color::LightGray)),
        ))
        .with_completer({
            let mut inclusions = vec!['-', '_'];
            for i in '0'..='9' {
                inclusions.push(i);
            }


            let mut completer = DefaultCompleter::with_inclusions(&inclusions);
            completer.insert(commands.clone());
            Box::new(completer)
        })
        .with_quick_completions(true)
        .with_partial_completions(true)
        .with_ansi_colors(true)
        .with_menu(ReedlineMenu::EngineCompleter(Box::new(
            ListMenu::default().with_name("completion_menu"),
        )))
        .with_edit_mode({
            let mut keybindings = default_emacs_keybindings();
            keybindings.add_binding(
                KeyModifiers::NONE,
                KeyCode::Tab,
                ReedlineEvent::UntilFound(vec![
                    ReedlineEvent::Menu("completion_menu".to_string()),
                    ReedlineEvent::MenuNext,
                ]),
            );


            keybindings.add_binding(
                KeyModifiers::SHIFT,
                KeyCode::BackTab,
                ReedlineEvent::MenuPrevious,
            );
            Box::new(Emacs::new(keybindings))
        });

With ListMenu::default().with_name("completion_menu") at line 84 (video) - https://capture.dropbox.com/2qUrH8tykkUAudM1

With ColumnarMenu::default().with_name("completion_menu") at line 84 (video) - https://capture.dropbox.com/v2R58EmyUEgfMnjx

I will add a minimal reproduction later as soon as I have time, sorry.

@elferherrera
Copy link
Contributor

elferherrera commented Apr 7, 2022

I see what is happening. The list type of menu doesn't take as input what is already written, but what you write after you activate it. Try to trigger the menu and then type something.

I'm writing a chapter to explain the differences between these menus and how they can be used with different completers

Another option is to create the menu and then use this function with the constructor with_only_buffer_difference

ListMenu::default().with_name("completion_menu").with_only_buffer_difference(false)

That should that what has been written

@DhruvDh
Copy link
Contributor

DhruvDh commented Apr 7, 2022

Ah, thank you. I figured I probably was using it incorrectly. Anyway the library is great! Thanks for all of your guys' work.

@RustyJoeM
Copy link

Hello all,
what is the current status of completion functionality? Is it available?
Latest crate version or master branch from git (as of today) does not provide CompletionMenu from reedline crate for me, and there is no visible behavior on TAB key pressing when i leave out the "non-existent" CompletionMenu rows from example code and use with_completer only...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Completions Area: Tab completion and inline hint completions A-KeybindingEmacs Area: Handling of default (Emacs style) keybindings documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants