Reuse parse_util_token_extent for completion insertion

We don't need all of its features here but this makes the "completion is
appended" case more similar to the "completion replaces token" case.
This commit is contained in:
Johannes Altmanninger 2024-04-13 10:44:46 +02:00
parent dcd6c74248
commit cacfcf8089

View file

@ -5165,23 +5165,11 @@ pub fn completion_apply_to_command_line(
let mut quote = None; let mut quote = None;
let replaced = if do_escape { let replaced = if do_escape {
// We need to figure out whether the token we complete has unclosed quotes. Since the token let mut tok = 0..0;
// may be inside a command substitutions we must first determine the extents of the parse_util_token_extent(command_line, cursor_pos, &mut tok, None);
// innermost command substitution. // Find the last quote in the token to complete.
let cmdsub_range = parse_util_cmdsubst_extent(command_line, cursor_pos); if tok.contains(&cursor_pos) || cursor_pos == tok.end {
// Find the last quote in the token to complete. By parsing only the string inside any quote = get_quote(&command_line[tok.clone()], cursor_pos - tok.start);
// command substitution, we prevent the tokenizer from treating the entire command
// substitution as one token.
let mut tokenizer =
Tokenizer::new(&command_line[cmdsub_range.clone()], TOK_ACCEPT_UNFINISHED);
let rel_pos = cursor_pos - cmdsub_range.start;
while let Some(cur_tok) = tokenizer.next() {
if cur_tok.type_ == TokenType::string
&& cur_tok.location_in_or_at_end_of_source_range(rel_pos)
{
quote = get_quote(tokenizer.text_of(&cur_tok), rel_pos - cur_tok.offset());
break;
}
} }
// If the token is reported as unquoted, but ends with a (unescaped) quote, and we can // If the token is reported as unquoted, but ends with a (unescaped) quote, and we can