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

Add a way to retrieve the current completer #116

Closed
minijackson opened this issue Apr 4, 2017 · 2 comments · Fixed by #133
Closed

Add a way to retrieve the current completer #116

minijackson opened this issue Apr 4, 2017 · 2 comments · Fixed by #133

Comments

@minijackson
Copy link

I was messing with rustyline, it's completion API and trying do implement multiline editing at the same time, but then I encountered a problem: I need to have the input from the previous lines to have a proper context for my completion system.

Sorry if it's unclear, here's a quick example:

input> if [ x -eq 1 ];
  ...> th<tab>

In this case, my completer need to know that there's an if before to be able to complete the then.

My idea was to store the previous lines as context inside the Completer, but currently there is no way of retrieving the completer in use.

A see two ways of doing this: either make the completer field public or add the get_completer and get_completer_mut methods.

For now, I can do it by replacing the current completer with the added context, but I think that would be better by mutating the completer directly.

If there's a better way, please tell me, I'm open to discussion ;-)

@gwenn
Copy link
Collaborator

gwenn commented Apr 8, 2017

Hello,
You can keep ownership of your Completer by passing a reference:

    let c = FilenameCompleter::new();
    let mut rl = Editor::with_config(config);
    rl.set_completer(Some(&c));
    // then do something with c

Tell us if it is good enough.

@minijackson
Copy link
Author

Oooh, I didn't think of that. Unfortunately, while I can keep the ownership of the completer, I cannot modify it, because it would require having a immutable reference and a mutable reference to the completer at the same time (it's the same if I have a mutable owned completer and an immutable reference to it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants