Add method to convert ClassifiedBlock into completion locations. (#2316)

The completion engine maps completion locations to spans on a line, which
indicate whther to complete a command name, flag name, argument, and so on.

Initial implementation is simplistic, with some rough edges, since it relies
heavily on the parser's interpretation. For example

    du -

if asking for completions, `-` is considered a positional argument by the
parser, but the user is likely looking for a flag. These scenarios will be
addressed in a series of progressive enhancements to the engine.
This commit is contained in:
Jason Gedge
2020-08-21 15:37:51 -04:00
committed by GitHub
parent 0dd1403a69
commit 9f85b10fcb
14 changed files with 589 additions and 381 deletions

View File

@ -4,10 +4,10 @@ use std::fmt::Debug;
#[derive(Debug)]
pub struct ParseError<T: Debug> {
/// An informative cause for this parse error
pub(crate) cause: nu_errors::ParseError,
pub cause: nu_errors::ParseError,
/// What has been successfully parsed, if anything
pub(crate) partial: Option<T>,
pub partial: Option<T>,
}
pub type ParseResult<T> = Result<T, ParseError<T>>;

View File

@ -133,11 +133,6 @@ fn bare(src: &mut Input, span_offset: usize) -> ParseResult<Spanned<String>> {
// correct information from the non-lite parse.
bare.push(delimiter);
let span = Span::new(
start_offset + span_offset,
start_offset + span_offset + bare.len(),
);
return Err(ParseError {
cause: nu_errors::ParseError::unexpected_eof(delimiter.to_string(), span),
partial: Some(bare.spanned(span)),

View File

@ -1358,7 +1358,7 @@ fn classify_pipeline(
}),
positional: Some(args),
named: None,
span: Span::unknown(),
span: name_span,
external_redirection: if iter.peek().is_none() {
ExternalRedirection::None
} else {
@ -1448,7 +1448,7 @@ fn classify_pipeline(
}),
positional: Some(args),
named: None,
span: Span::unknown(),
span: name_span,
external_redirection: if iter.peek().is_none() {
ExternalRedirection::None
} else {