Fix parse_util_process_extent including too much on the left

This commit is contained in:
Johannes Altmanninger 2024-12-24 15:29:51 +01:00
parent 83b0294fc9
commit 3fcc6482cb
2 changed files with 7 additions and 1 deletions

View file

@ -401,6 +401,7 @@ fn job_or_process_extent(
let pos = cursor_pos - cmdsub_range.start;
let mut result = cmdsub_range.clone();
let mut found_start = false;
for token in Tokenizer::new(
&buff[cmdsub_range.clone()],
TOK_ACCEPT_UNFINISHED | TOK_SHOW_COMMENTS,
@ -422,13 +423,17 @@ fn job_or_process_extent(
result.end = cmdsub_range.start + tok_begin;
} else {
// Statement at cursor might start after this token.
result.start = cmdsub_range.start + tok_begin + token.length();
found_start = false;
out_tokens.as_mut().map(|tokens| tokens.clear());
}
continue; // Do not add this to tokens
}
_ => (),
}
if !found_start {
result.start = cmdsub_range.start + tok_begin;
found_start = true;
}
out_tokens.as_mut().map(|tokens| tokens.push(token));
}
result

View file

@ -102,6 +102,7 @@ fn test_parse_util_process_extent() {
};
}
validate!("for file in (path base\necho", 22, 13..22);
validate!("begin\n\n\nec", 10, 8..10);
}
#[test]