More bug fixes for completions (#2476)

* Use the cursor position for the span when between locations.

This fixes a bug where completing

    ls <TAB>

would result in replacing the entire line.

* Revert to the default update implementation.

Replacing the length of the elected value was intended to do replacement when
one moves inside a quote. The problem is that a long elected suggestion could
replace bits of a pipeline that are after the cursor. For example:

    ls <TAB> | get name | str collect
This commit is contained in:
Jason Gedge 2020-09-01 00:10:46 -04:00 committed by GitHub
parent 6b5d96337e
commit 860c2a606d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -232,10 +232,10 @@ pub fn completion_location(line: &str, block: &Block, pos: usize) -> Vec<Complet
// is after some character that would imply we're in the command position.
let start = prev.span.end();
if line[start..pos].contains(BEFORE_COMMAND_CHARS) {
vec![LocationType::Command.spanned(Span::unknown())]
vec![LocationType::Command.spanned(Span::new(pos, pos))]
} else {
// TODO this should be able to be mapped to a command
vec![LocationType::Argument(command, None).spanned(Span::unknown())]
vec![LocationType::Argument(command, None).spanned(Span::new(pos, pos))]
}
} else {
// Cursor is before any possible completion location, so must be a command

View File

@ -54,7 +54,7 @@ impl rustyline::completion::Completer for Helper {
}
fn update(&self, line: &mut rustyline::line_buffer::LineBuffer, start: usize, elected: &str) {
let end = (start + elected.len()).min(line.len());
let end = line.pos();
line.replace(start..end, elected)
}
}