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

@ -526,10 +526,11 @@ impl Span {
/// let span = Span::new(2, 8);
///
/// assert_eq!(span.contains(5), true);
/// assert_eq!(span.contains(8), false);
/// assert_eq!(span.contains(100), false);
/// ```
pub fn contains(&self, pos: usize) -> bool {
self.start <= pos && self.end >= pos
self.start <= pos && pos < self.end
}
/// Returns a new Span by merging an earlier Span with the current Span.