Fix completion for builtins (with subcommands)

Presently the completion engine ignores builtins that are part of the
fish syntax. This can be a problem when completing a string that was
based on the output of `commandline -p`.  This changes completions to
treat these builtins like any other command.

This also disables generic (filename) completion inside comments and
after strings that do not tokenize.

Additionally, comments are stripped off the output of `commandline -p`.

Fixes #5415
Fixes #2705
This commit is contained in:
Johannes Altmanninger
2019-10-29 13:32:26 +01:00
parent 5f99ec7eae
commit 6fb7f9b6b8
18 changed files with 248 additions and 279 deletions

View File

@@ -87,6 +87,13 @@ struct tok_t {
// Construct from a token type.
explicit tok_t(token_type_t type);
/// Returns whether the given location is within the source range or at its end.
bool location_in_or_at_end_of_source_range(size_t loc) const {
return offset <= loc && loc - offset <= length;
}
/// Gets source for the token, or the empty string if it has no source.
wcstring get_source(const wcstring &str) const { return {str, offset, length}; }
};
/// The tokenizer struct.