mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 19:41:14 -03:00
Remove "parse_util" prefix from functions in that module
This was a naming holdover from C++
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
panic::panic_handler,
|
||||
parse_constants::{ParseErrorList, ParseTreeFlags},
|
||||
parse_tree::ParsedSource,
|
||||
parse_util::parse_util_detect_errors_in_ast,
|
||||
parse_util::detect_parse_errors_in_ast,
|
||||
parser::{BlockType, CancelBehavior, Parser, ParserEnvSetMode},
|
||||
path::path_get_config,
|
||||
prelude::*,
|
||||
@@ -195,7 +195,7 @@ fn run_command_list(parser: &Parser, cmds: &[OsString]) -> Result<(), libc::c_in
|
||||
let mut errors = ParseErrorList::new();
|
||||
let ast = ast::parse(&cmd_wcs, ParseTreeFlags::default(), Some(&mut errors));
|
||||
let errored = ast.errored() || {
|
||||
parse_util_detect_errors_in_ast(&ast, &cmd_wcs, Some(&mut errors)).is_err()
|
||||
detect_parse_errors_in_ast(&ast, &cmd_wcs, Some(&mut errors)).is_err()
|
||||
};
|
||||
|
||||
if !errored {
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
use crate::operation_context::{OperationContext, no_cancel};
|
||||
use crate::parse_constants::{ParseTreeFlags, ParserTestErrorBits};
|
||||
use crate::parse_util::{
|
||||
parse_util_detect_errors, parse_util_get_offset_from_line, parse_util_job_extent,
|
||||
parse_util_lineno, parse_util_process_extent, parse_util_token_extent,
|
||||
detect_parse_errors, get_job_extent, get_offset_from_line, get_process_extent,
|
||||
get_token_extent, lineno,
|
||||
};
|
||||
use crate::prelude::*;
|
||||
use crate::proc::is_interactive_session;
|
||||
@@ -18,8 +18,7 @@
|
||||
commandline_get_state, commandline_set_buffer, commandline_set_search_field,
|
||||
reader_execute_readline_cmd, reader_showing_suggestion,
|
||||
};
|
||||
use crate::tokenizer::TOK_ACCEPT_UNFINISHED;
|
||||
use crate::tokenizer::{TokenType, Tokenizer};
|
||||
use crate::tokenizer::{TOK_ACCEPT_UNFINISHED, TokenType, Tokenizer};
|
||||
use fish_wcstringutil::join_strings;
|
||||
use std::ops::Range;
|
||||
|
||||
@@ -523,10 +522,9 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
|
||||
};
|
||||
|
||||
let new_pos = if line_mode {
|
||||
let Some(offset) = parse_util_get_offset_from_line(
|
||||
&rstate.text,
|
||||
i32::try_from(new_coord).unwrap(),
|
||||
) else {
|
||||
let Some(offset) =
|
||||
get_offset_from_line(&rstate.text, i32::try_from(new_coord).unwrap())
|
||||
else {
|
||||
streams
|
||||
.err
|
||||
.append(&wgettext_fmt!("%s: there is no line %s\n", cmd, arg));
|
||||
@@ -536,12 +534,11 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
|
||||
offset
|
||||
} else {
|
||||
let line_index =
|
||||
i32::try_from(parse_util_lineno(&rstate.text, rstate.cursor_pos)).unwrap() - 1;
|
||||
i32::try_from(lineno(&rstate.text, rstate.cursor_pos)).unwrap() - 1;
|
||||
let line_offset =
|
||||
parse_util_get_offset_from_line(&rstate.text, line_index).unwrap_or_default();
|
||||
get_offset_from_line(&rstate.text, line_index).unwrap_or_default();
|
||||
let next_line_offset =
|
||||
parse_util_get_offset_from_line(&rstate.text, line_index + 1)
|
||||
.unwrap_or(rstate.text.len());
|
||||
get_offset_from_line(&rstate.text, line_index + 1).unwrap_or(rstate.text.len());
|
||||
if line_offset + new_coord > next_line_offset {
|
||||
streams.err.append(&wgettext_fmt!(
|
||||
"%s: column %s exceeds line length\n",
|
||||
@@ -558,13 +555,12 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
|
||||
streams.out.append(&sprintf!(
|
||||
"%d\n",
|
||||
if line_mode {
|
||||
parse_util_lineno(&rstate.text, rstate.cursor_pos)
|
||||
lineno(&rstate.text, rstate.cursor_pos)
|
||||
} else {
|
||||
rstate.cursor_pos + 1
|
||||
- parse_util_get_offset_from_line(
|
||||
- get_offset_from_line(
|
||||
&rstate.text,
|
||||
i32::try_from(parse_util_lineno(&rstate.text, rstate.cursor_pos) - 1)
|
||||
.unwrap(),
|
||||
i32::try_from(lineno(&rstate.text, rstate.cursor_pos) - 1).unwrap(),
|
||||
)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
@@ -659,7 +655,7 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
|
||||
if current_buffer.is_empty() {
|
||||
return Err(STATUS_CMD_ERROR);
|
||||
}
|
||||
let res = parse_util_detect_errors(current_buffer, None, /*accept_incomplete=*/ true);
|
||||
let res = detect_parse_errors(current_buffer, None, /*accept_incomplete=*/ true);
|
||||
return match res {
|
||||
Ok(()) => Ok(SUCCESS),
|
||||
Err(err) => {
|
||||
@@ -688,13 +684,13 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
|
||||
range = 0..current_buffer.len();
|
||||
}
|
||||
TextScope::Job => {
|
||||
range = parse_util_job_extent(current_buffer, current_cursor_pos, None);
|
||||
range = get_job_extent(current_buffer, current_cursor_pos, None);
|
||||
}
|
||||
TextScope::Process => {
|
||||
range = parse_util_process_extent(current_buffer, current_cursor_pos, None);
|
||||
range = get_process_extent(current_buffer, current_cursor_pos, None);
|
||||
}
|
||||
TextScope::Token => {
|
||||
(range, _) = parse_util_token_extent(current_buffer, current_cursor_pos);
|
||||
(range, _) = get_token_extent(current_buffer, current_cursor_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
use crate::highlight::highlight_and_colorize;
|
||||
use crate::operation_context::OperationContext;
|
||||
use crate::parse_constants::ParseErrorList;
|
||||
use crate::parse_util::parse_util_detect_errors_in_argument_list;
|
||||
use crate::parse_util::{parse_util_detect_errors, parse_util_token_extent};
|
||||
use crate::parse_util::detect_errors_in_argument_list;
|
||||
use crate::parse_util::{detect_parse_errors, get_token_extent};
|
||||
use crate::proc::is_interactive_session;
|
||||
use crate::reader::{commandline_get_state, completion_apply_to_command_line};
|
||||
use crate::{
|
||||
@@ -449,7 +449,7 @@ pub fn complete(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) ->
|
||||
|
||||
for condition_string in &condition {
|
||||
let mut errors = ParseErrorList::new();
|
||||
if parse_util_detect_errors(condition_string, Some(&mut errors), false).is_err() {
|
||||
if detect_parse_errors(condition_string, Some(&mut errors), false).is_err() {
|
||||
for error in errors {
|
||||
let prefix = cmd.to_owned() + L!(": -n '") + &condition_string[..] + L!("': ");
|
||||
streams.err.append(&error.describe_with_prefix(
|
||||
@@ -469,7 +469,7 @@ pub fn complete(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) ->
|
||||
prefix.push_utfstr(cmd);
|
||||
prefix.push_str(": ");
|
||||
|
||||
if let Err(err_text) = parse_util_detect_errors_in_argument_list(&comp, &prefix) {
|
||||
if let Err(err_text) = detect_errors_in_argument_list(&comp, &prefix) {
|
||||
streams.err.append(&wgettext_fmt!(
|
||||
"%s: %s: contains a syntax error\n",
|
||||
cmd,
|
||||
@@ -499,7 +499,7 @@ pub fn complete(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) ->
|
||||
Some(param) => param,
|
||||
};
|
||||
|
||||
let (token, _) = parse_util_token_extent(&do_complete_param, do_complete_param.len());
|
||||
let (token, _) = get_token_extent(&do_complete_param, do_complete_param.len());
|
||||
|
||||
// Create a scoped transient command line, so that builtin_commandline will see our
|
||||
// argument, not the reader buffer.
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
use crate::highlight::{HighlightRole, HighlightSpec, colorize, highlight_shell};
|
||||
use crate::operation_context::OperationContext;
|
||||
use crate::parse_constants::{ParseTokenType, ParseTreeFlags, SourceRange};
|
||||
use crate::parse_util::{SPACES_PER_INDENT, apply_indents, parse_util_compute_indents};
|
||||
use crate::parse_util::{SPACES_PER_INDENT, apply_indents, compute_indents};
|
||||
use crate::prelude::*;
|
||||
use crate::print_help::print_help;
|
||||
use crate::threads;
|
||||
@@ -162,7 +162,7 @@ fn new(source: &'source wstr, ast: &'ast Ast, do_indent: bool) -> Self {
|
||||
indents: if do_indent
|
||||
/* Whether to indent, or just insert spaces. */
|
||||
{
|
||||
parse_util_compute_indents(source)
|
||||
compute_indents(source)
|
||||
} else {
|
||||
vec![0; source.len()]
|
||||
},
|
||||
@@ -1106,7 +1106,7 @@ enum OutputType {
|
||||
}
|
||||
|
||||
let output_wtext = if only_indent || only_unindent {
|
||||
let indents = parse_util_compute_indents(&src);
|
||||
let indents = compute_indents(&src);
|
||||
if only_indent {
|
||||
apply_indents(&src, &indents)
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
use crate::function;
|
||||
use crate::highlight::highlight_and_colorize;
|
||||
use crate::parse_util::apply_indents;
|
||||
use crate::parse_util::parse_util_compute_indents;
|
||||
use crate::parse_util::compute_indents;
|
||||
use crate::parser_keywords::parser_keywords_is_reserved;
|
||||
use crate::termsize::termsize_last;
|
||||
|
||||
@@ -415,7 +415,7 @@ pub fn functions(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -
|
||||
}
|
||||
|
||||
if props.definition_file().is_none() {
|
||||
def = apply_indents(&def, &parse_util_compute_indents(&def));
|
||||
def = apply_indents(&def, &compute_indents(&def));
|
||||
}
|
||||
|
||||
if opts.color.enabled(streams) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::fds::BorrowedFdFile;
|
||||
use crate::io::OutputStream;
|
||||
use crate::parse_constants::UNKNOWN_BUILTIN_ERR_MSG;
|
||||
use crate::parse_util::parse_util_argument_is_help;
|
||||
use crate::parse_util::argument_is_help;
|
||||
use crate::parser::{BlockType, LoopStatus};
|
||||
use crate::proc::{Pid, ProcStatus, no_exec};
|
||||
use crate::{builtins::*, wutil};
|
||||
@@ -476,7 +476,7 @@ pub fn builtin_run(parser: &Parser, argv: &mut [&wstr], streams: &mut IoStreams)
|
||||
// We can be handed a keyword by the parser as if it was a command. This happens when the user
|
||||
// follows the keyword by `-h` or `--help`. Since it isn't really a builtin command we need to
|
||||
// handle displaying help for it here.
|
||||
if argv.len() == 2 && parse_util_argument_is_help(argv[1]) && cmd_needs_help(argv[0]) {
|
||||
if argv.len() == 2 && argument_is_help(argv[1]) && cmd_needs_help(argv[0]) {
|
||||
builtin_print_help(parser, streams, argv[0]);
|
||||
return ProcStatus::from_exit_code(STATUS_CMD_OK);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use super::*;
|
||||
use crate::env::{EnvVar, EnvVarFlags};
|
||||
use crate::flog::flog;
|
||||
use crate::parse_util::parse_util_unescape_wildcards;
|
||||
use crate::parse_util::unescape_wildcards;
|
||||
use crate::parser::ParserEnvSetMode;
|
||||
use crate::wildcard::{ANY_STRING, wildcard_match};
|
||||
|
||||
@@ -365,7 +365,7 @@ fn report_match<'a>(
|
||||
|
||||
impl<'opts, 'args> WildCardMatcher<'opts, 'args> {
|
||||
fn new(pattern: &'args wstr, opts: &'opts Match<'args>) -> Self {
|
||||
let mut wcpattern = parse_util_unescape_wildcards(pattern);
|
||||
let mut wcpattern = unescape_wildcards(pattern);
|
||||
if opts.ignore_case {
|
||||
wcpattern = wcpattern.to_lowercase();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
use crate::common::bytes2wcstring;
|
||||
use crate::function;
|
||||
use crate::highlight::highlight_and_colorize;
|
||||
use crate::parse_util::{apply_indents, parse_util_compute_indents};
|
||||
use crate::parse_util::{apply_indents, compute_indents};
|
||||
use crate::path::{path_get_path, path_get_paths};
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -144,7 +144,7 @@ pub fn r#type(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> B
|
||||
props.annotated_definition(arg)
|
||||
));
|
||||
if props.definition_file().is_none() {
|
||||
def = apply_indents(&def, &parse_util_compute_indents(&def));
|
||||
def = apply_indents(&def, &compute_indents(&def));
|
||||
}
|
||||
|
||||
if opts.color.enabled(streams) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
use crate::global_safety::AtomicRef;
|
||||
use crate::global_safety::RelaxedAtomicBool;
|
||||
use crate::key;
|
||||
use crate::parse_util::parse_util_escape_string_with_quote;
|
||||
use crate::parse_util::escape_string_with_quote;
|
||||
use crate::prelude::*;
|
||||
use crate::terminal::Output;
|
||||
use crate::termsize::Termsize;
|
||||
@@ -227,7 +227,7 @@ fn escape_string_script(input: &wstr, flags: EscapeFlags) -> WString {
|
||||
out.clear();
|
||||
out.reserve(2 + input.len());
|
||||
out.push(quote);
|
||||
out.push_utfstr(&parse_util_escape_string_with_quote(
|
||||
out.push_utfstr(&escape_string_with_quote(
|
||||
input,
|
||||
Some(quote),
|
||||
EscapeFlags::empty(),
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
history::{History, history_session_id},
|
||||
operation_context::OperationContext,
|
||||
parse_constants::SourceRange,
|
||||
parse_util::{
|
||||
parse_util_cmdsubst_extent, parse_util_process_extent, parse_util_unescape_wildcards,
|
||||
},
|
||||
parse_util::{get_cmdsubst_extent, get_process_extent, unescape_wildcards},
|
||||
parser::{Block, Parser, ParserEnvSetMode},
|
||||
parser_keywords::parser_keywords_is_subcommand,
|
||||
path::{path_get_path, path_try_get_path},
|
||||
@@ -654,7 +652,7 @@ fn perform_for_commandline_impl(&mut self, cmdline: WString) {
|
||||
|
||||
// Get all the arguments.
|
||||
let mut tokens = Vec::new();
|
||||
parse_util_process_extent(&cmdline, position_in_statement, Some(&mut tokens));
|
||||
get_process_extent(&cmdline, position_in_statement, Some(&mut tokens));
|
||||
let actual_token_count = tokens.len();
|
||||
|
||||
// Hack: fix autosuggestion by removing prefixing "and"s #6249.
|
||||
@@ -930,7 +928,7 @@ fn complete_strings(
|
||||
return;
|
||||
}
|
||||
|
||||
let wc = parse_util_unescape_wildcards(&tmp);
|
||||
let wc = unescape_wildcards(&tmp);
|
||||
for comp in possible_comp {
|
||||
let comp_str = &comp.completion;
|
||||
if !comp_str.is_empty() {
|
||||
@@ -2368,7 +2366,7 @@ pub fn complete(
|
||||
ctx: &OperationContext,
|
||||
) -> (Vec<Completion>, Vec<WString>) {
|
||||
// Determine the innermost subcommand.
|
||||
let cmdsubst = parse_util_cmdsubst_extent(cmd_with_subcmds, cmd_with_subcmds.len());
|
||||
let cmdsubst = get_cmdsubst_extent(cmd_with_subcmds, cmd_with_subcmds.len());
|
||||
let cmd = cmd_with_subcmds[cmdsubst].to_owned();
|
||||
let mut completer = Completer::new(ctx, flags);
|
||||
completer.perform_for_commandline(cmd);
|
||||
|
||||
@@ -19,9 +19,7 @@
|
||||
use crate::history::{History, history_session_id};
|
||||
use crate::operation_context::OperationContext;
|
||||
use crate::parse_constants::{ParseError, ParseErrorCode, ParseErrorList, SOURCE_LOCATION_UNKNOWN};
|
||||
use crate::parse_util::{
|
||||
MaybeParentheses, parse_util_expand_variable_error, parse_util_locate_cmdsubst_range,
|
||||
};
|
||||
use crate::parse_util::{MaybeParentheses, expand_variable_error, locate_cmdsubst_range};
|
||||
use crate::path::path_apply_working_directory;
|
||||
use crate::prelude::*;
|
||||
use crate::wildcard::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, WildcardResult};
|
||||
@@ -624,7 +622,7 @@ fn expand_variables(
|
||||
// It's an error if the name is empty.
|
||||
if var_name.is_empty() {
|
||||
if let Some(errors) = errors {
|
||||
parse_util_expand_variable_error(
|
||||
expand_variable_error(
|
||||
&instr,
|
||||
0, /* global_token_pos */
|
||||
varexp_char_idx,
|
||||
@@ -930,7 +928,7 @@ pub fn expand_cmdsubst(
|
||||
let mut cursor = 0;
|
||||
let mut is_quoted = false;
|
||||
let mut has_dollar = false;
|
||||
let parens = match parse_util_locate_cmdsubst_range(
|
||||
let parens = match locate_cmdsubst_range(
|
||||
&input,
|
||||
&mut cursor,
|
||||
false,
|
||||
@@ -1330,7 +1328,7 @@ fn stage_cmdsubst(&mut self, input: WString, out: &mut CompletionReceiver) -> Ex
|
||||
}
|
||||
if self.flags.contains(ExpandFlags::FAIL_ON_CMDSUBST) {
|
||||
let mut cursor = 0;
|
||||
match parse_util_locate_cmdsubst_range(&input, &mut cursor, true, None, None) {
|
||||
match locate_cmdsubst_range(&input, &mut cursor, true, None, None) {
|
||||
MaybeParentheses::Error => ExpandResult::make_error(STATUS_EXPAND_ERROR),
|
||||
MaybeParentheses::None => {
|
||||
if !out.add(input) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
use crate::prelude::*;
|
||||
use crate::wildcard::wildcard_match;
|
||||
use crate::wutil::write_to_fd;
|
||||
use crate::{parse_util::parse_util_unescape_wildcards, wutil::unescape_bytes_and_write_to_fd};
|
||||
use crate::{parse_util::unescape_wildcards, wutil::unescape_bytes_and_write_to_fd};
|
||||
use libc::c_int;
|
||||
use std::sync::atomic::{AtomicI32, Ordering};
|
||||
|
||||
@@ -259,7 +259,7 @@ macro_rules! should_flog {
|
||||
|
||||
/// For each category, if its name matches the wildcard, set its enabled to the given sense.
|
||||
fn apply_one_wildcard(wc_esc: &wstr, sense: bool) {
|
||||
let wc = parse_util_unescape_wildcards(wc_esc);
|
||||
let wc = unescape_wildcards(wc_esc);
|
||||
let mut match_found = false;
|
||||
for cat in categories::all_categories() {
|
||||
if wildcard_match(cat.name, &wc, false) {
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
ParseKeyword, ParseTokenType, ParseTreeFlags, SourceRange, StatementDecoration,
|
||||
};
|
||||
use crate::parse_util::{
|
||||
MaybeParentheses, parse_util_locate_cmdsubst_range, parse_util_process_first_token_offset,
|
||||
parse_util_slice_length,
|
||||
MaybeParentheses, get_process_first_token_offset, locate_cmdsubst_range, slice_length,
|
||||
};
|
||||
use crate::path::{path_as_implicit_cd, path_get_cdpath, path_get_path, paths_are_same_file};
|
||||
use crate::terminal::Outputter;
|
||||
@@ -344,7 +343,7 @@ pub fn autosuggest_validate_from_history(
|
||||
assert_is_background_thread();
|
||||
|
||||
if suggested_range != (0..item_commandline.char_count())
|
||||
&& parse_util_process_first_token_offset(item_commandline, suggested_range.start)
|
||||
&& get_process_first_token_offset(item_commandline, suggested_range.start)
|
||||
.is_some_and(|offset| offset != suggested_range.start)
|
||||
{
|
||||
return false;
|
||||
@@ -434,7 +433,7 @@ fn color_variable(inp: &wstr, colors: &mut [HighlightSpec]) -> usize {
|
||||
// Handle a slice, up to dollar_count of them. Note that we currently don't do any validation of
|
||||
// the slice's contents, e.g. $foo[blah] will not show an error even though it's invalid.
|
||||
for _slice_count in 0..dollar_count {
|
||||
match parse_util_slice_length(&inp[idx..]) {
|
||||
match slice_length(&inp[idx..]) {
|
||||
Some(slice_len) if slice_len > 0 => {
|
||||
colors[idx] = HighlightSpec::with_fg(HighlightRole::operat);
|
||||
colors[idx + slice_len - 1] = HighlightSpec::with_fg(HighlightRole::operat);
|
||||
@@ -828,7 +827,7 @@ fn color_as_argument(&mut self, node: &dyn ast::Node, options_allowed: bool /* =
|
||||
// Now do command substitutions.
|
||||
let mut cmdsub_cursor = 0;
|
||||
let mut is_quoted = false;
|
||||
while let MaybeParentheses::CommandSubstitution(parens) = parse_util_locate_cmdsubst_range(
|
||||
while let MaybeParentheses::CommandSubstitution(parens) = locate_cmdsubst_range(
|
||||
arg_str,
|
||||
&mut cmdsub_cursor,
|
||||
/*accept_incomplete=*/ true,
|
||||
@@ -1117,7 +1116,7 @@ fn visit_brace_statement(&mut self, brace_statement: &BraceStatement) {
|
||||
/// Return whether a string contains a command substitution.
|
||||
fn has_cmdsub(src: &wstr) -> bool {
|
||||
let mut cursor = 0;
|
||||
match parse_util_locate_cmdsubst_range(src, &mut cursor, true, None, None) {
|
||||
match locate_cmdsubst_range(src, &mut cursor, true, None, None) {
|
||||
MaybeParentheses::Error => false,
|
||||
MaybeParentheses::None => false,
|
||||
MaybeParentheses::CommandSubstitution(_) => true,
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
localization::wgettext_fmt,
|
||||
operation_context::{EXPANSION_LIMIT_BACKGROUND, OperationContext},
|
||||
parse_constants::{ParseTreeFlags, StatementDecoration},
|
||||
parse_util::{parse_util_detect_errors, parse_util_unescape_wildcards},
|
||||
parse_util::{detect_parse_errors, unescape_wildcards},
|
||||
parser::Parser,
|
||||
path::{path_get_config, path_get_data, path_is_valid},
|
||||
prelude::*,
|
||||
@@ -226,7 +226,7 @@ pub fn matches_search(&self, term: &wstr, typ: SearchType, case_sensitive: bool)
|
||||
.split(|&c| c == '\n')
|
||||
.any(|line| line.starts_with(term.as_char_slice())),
|
||||
SearchType::ContainsGlob => {
|
||||
let mut pat = parse_util_unescape_wildcards(term);
|
||||
let mut pat = unescape_wildcards(term);
|
||||
if !pat.starts_with(ANY_STRING) {
|
||||
pat.insert(0, ANY_STRING);
|
||||
}
|
||||
@@ -236,7 +236,7 @@ pub fn matches_search(&self, term: &wstr, typ: SearchType, case_sensitive: bool)
|
||||
wildcard_match(content_to_match.as_ref(), &pat, false)
|
||||
}
|
||||
SearchType::PrefixGlob => {
|
||||
let mut pat = parse_util_unescape_wildcards(term);
|
||||
let mut pat = unescape_wildcards(term);
|
||||
if !pat.ends_with(ANY_STRING) {
|
||||
pat.push(ANY_STRING);
|
||||
}
|
||||
@@ -1185,7 +1185,7 @@ fn should_import_bash_history_line(line: &wstr) -> bool {
|
||||
|
||||
// In doing this test do not allow incomplete strings. Hence the "false" argument.
|
||||
let mut errors = Vec::new();
|
||||
let _ = parse_util_detect_errors(line, Some(&mut errors), false);
|
||||
let _ = detect_parse_errors(line, Some(&mut errors), false);
|
||||
errors.is_empty()
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@
|
||||
};
|
||||
use crate::parse_tree::{LineCounter, NodeRef, ParsedSourceRef};
|
||||
use crate::parse_util::{
|
||||
MaybeParentheses::CommandSubstitution, parse_util_locate_cmdsubst_range,
|
||||
parse_util_unescape_wildcards,
|
||||
MaybeParentheses::CommandSubstitution, locate_cmdsubst_range, unescape_wildcards,
|
||||
};
|
||||
use crate::parser::{
|
||||
Block, BlockData, BlockId, BlockType, LoopStatus, Parser, ParserEnvSetMode, ProfileItem,
|
||||
@@ -1157,7 +1156,7 @@ fn run_switch_statement(
|
||||
if case_result == EndExecutionReason::Ok {
|
||||
for arg in case_args {
|
||||
// Unescape wildcards so they can be expanded again.
|
||||
let unescaped_arg = parse_util_unescape_wildcards(&arg);
|
||||
let unescaped_arg = unescape_wildcards(&arg);
|
||||
if wildcard_match(&switch_value_expanded, &unescaped_arg, false) {
|
||||
// If this matched, we're done.
|
||||
matching_case_item = Some(case_item);
|
||||
@@ -1464,7 +1463,7 @@ fn determine_redirections(
|
||||
if oper.mode == RedirectionMode::Input && {
|
||||
let redir_unexpanded = self.node_source(redir_node);
|
||||
redir_unexpanded.starts_with(L!("<("))
|
||||
&& match parse_util_locate_cmdsubst_range(
|
||||
&& match locate_cmdsubst_range(
|
||||
&redir_unexpanded[1..],
|
||||
&mut 0,
|
||||
false,
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
/// Handles slices: the square brackets in an expression like $foo[5..4]
|
||||
/// Return the length of the slice starting at `in`, or 0 if there is no slice, or None on error.
|
||||
/// This never accepts incomplete slices.
|
||||
pub fn parse_util_slice_length(input: &wstr) -> Option<usize> {
|
||||
pub fn slice_length(input: &wstr) -> Option<usize> {
|
||||
let openc = '[';
|
||||
let closec = ']';
|
||||
let mut escaped = false;
|
||||
@@ -129,7 +129,7 @@ pub enum MaybeParentheses {
|
||||
/// \param out_has_dollar whether the command substitution has the optional leading $.
|
||||
/// Return -1 on syntax error, 0 if no subshells exist and 1 on success
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn parse_util_locate_cmdsubst_range(
|
||||
pub fn locate_cmdsubst_range(
|
||||
s: &wstr,
|
||||
inout_cursor_offset: &mut usize,
|
||||
accept_incomplete: bool,
|
||||
@@ -142,7 +142,7 @@ pub fn parse_util_locate_cmdsubst_range(
|
||||
}
|
||||
|
||||
// Defer to the wonky version.
|
||||
let ret = parse_util_locate_cmdsub(
|
||||
let ret = locate_cmdsub(
|
||||
s,
|
||||
*inout_cursor_offset,
|
||||
accept_incomplete,
|
||||
@@ -167,12 +167,12 @@ pub fn parse_util_locate_cmdsubst_range(
|
||||
/// \param cursor_pos the position of the cursor
|
||||
/// \param a the start of the searched string
|
||||
/// \param b the end of the searched string
|
||||
pub fn parse_util_cmdsubst_extent(buff: &wstr, cursor: usize) -> ops::Range<usize> {
|
||||
pub fn get_cmdsubst_extent(buff: &wstr, cursor: usize) -> ops::Range<usize> {
|
||||
// The tightest command substitution found so far.
|
||||
let mut result = 0..buff.len();
|
||||
let mut pos = 0;
|
||||
loop {
|
||||
let parens = match parse_util_locate_cmdsub(buff, pos, true, None, None) {
|
||||
let parens = match locate_cmdsub(buff, pos, true, None, None) {
|
||||
// No subshell found, all done.
|
||||
MaybeParentheses::Error | MaybeParentheses::None => break,
|
||||
MaybeParentheses::CommandSubstitution(parens) => parens,
|
||||
@@ -202,7 +202,7 @@ pub fn parse_util_cmdsubst_extent(buff: &wstr, cursor: usize) -> ops::Range<usiz
|
||||
result
|
||||
}
|
||||
|
||||
fn parse_util_locate_cmdsub(
|
||||
fn locate_cmdsub(
|
||||
input: &wstr,
|
||||
cursor: usize,
|
||||
allow_incomplete: bool,
|
||||
@@ -376,20 +376,18 @@ fn process_opening_quote(
|
||||
///
|
||||
/// \param buff the string to search for subshells
|
||||
/// \param cursor_pos the position of the cursor
|
||||
/// \param a the start of the process
|
||||
/// \param b the end of the process
|
||||
/// \param tokens the tokens in the process
|
||||
pub fn parse_util_process_extent(
|
||||
pub fn get_process_extent(
|
||||
buff: &wstr,
|
||||
cursor_pos: usize,
|
||||
out_tokens: Option<&mut Vec<Tok>>,
|
||||
) -> ops::Range<usize> {
|
||||
job_or_process_extent(true, buff, cursor_pos, out_tokens)
|
||||
get_job_or_process_extent(true, buff, cursor_pos, out_tokens)
|
||||
}
|
||||
|
||||
pub fn parse_util_process_first_token_offset(buff: &wstr, cursor_pos: usize) -> Option<usize> {
|
||||
pub fn get_process_first_token_offset(buff: &wstr, cursor_pos: usize) -> Option<usize> {
|
||||
let mut tokens = vec![];
|
||||
parse_util_process_extent(buff, cursor_pos, Some(&mut tokens));
|
||||
get_process_extent(buff, cursor_pos, Some(&mut tokens));
|
||||
tokens.first().map(|tok| tok.offset())
|
||||
}
|
||||
|
||||
@@ -397,19 +395,17 @@ pub fn parse_util_process_first_token_offset(buff: &wstr, cursor_pos: usize) ->
|
||||
///
|
||||
/// \param buff the string to search for subshells
|
||||
/// \param cursor_pos the position of the cursor
|
||||
/// \param a the start of the process
|
||||
/// \param b the end of the process
|
||||
/// \param tokens the tokens in the process
|
||||
pub fn parse_util_job_extent(
|
||||
/// \param out_tokens the tokens in the process
|
||||
pub fn get_job_extent(
|
||||
buff: &wstr,
|
||||
cursor_pos: usize,
|
||||
out_tokens: Option<&mut Vec<Tok>>,
|
||||
) -> ops::Range<usize> {
|
||||
job_or_process_extent(false, buff, cursor_pos, out_tokens)
|
||||
get_job_or_process_extent(false, buff, cursor_pos, out_tokens)
|
||||
}
|
||||
|
||||
/// Get the beginning and end of the job or process definition under the cursor.
|
||||
fn job_or_process_extent(
|
||||
fn get_job_or_process_extent(
|
||||
process: bool,
|
||||
buff: &wstr,
|
||||
cursor_pos: usize,
|
||||
@@ -417,7 +413,7 @@ fn job_or_process_extent(
|
||||
) -> ops::Range<usize> {
|
||||
let mut finished = false;
|
||||
|
||||
let cmdsub_range = parse_util_cmdsubst_extent(buff, cursor_pos);
|
||||
let cmdsub_range = get_cmdsubst_extent(buff, cursor_pos);
|
||||
assert!(cursor_pos >= cmdsub_range.start);
|
||||
let pos = cursor_pos - cmdsub_range.start;
|
||||
|
||||
@@ -461,8 +457,8 @@ fn job_or_process_extent(
|
||||
///
|
||||
/// \param buff the string to search for subshells
|
||||
/// \param cursor_pos the position of the cursor
|
||||
pub fn parse_util_token_extent(buff: &wstr, cursor_pos: usize) -> (Range<usize>, Range<usize>) {
|
||||
let cmdsubst_range = parse_util_cmdsubst_extent(buff, cursor_pos);
|
||||
pub fn get_token_extent(buff: &wstr, cursor_pos: usize) -> (Range<usize>, Range<usize>) {
|
||||
let cmdsubst_range = get_cmdsubst_extent(buff, cursor_pos);
|
||||
let cmdsubst_begin = cmdsubst_range.start;
|
||||
|
||||
// pos is equivalent to cursor_pos within the range of the command substitution {begin, end}.
|
||||
@@ -515,7 +511,7 @@ pub fn parse_util_token_extent(buff: &wstr, cursor_pos: usize) -> (Range<usize>,
|
||||
}
|
||||
|
||||
/// Get the line number at the specified character offset.
|
||||
pub fn parse_util_lineno(s: &wstr, offset: usize) -> usize {
|
||||
pub fn lineno(s: &wstr, offset: usize) -> usize {
|
||||
// Return the line number of position offset, starting with 1.
|
||||
if s.is_empty() {
|
||||
return 1;
|
||||
@@ -526,7 +522,7 @@ pub fn parse_util_lineno(s: &wstr, offset: usize) -> usize {
|
||||
}
|
||||
|
||||
/// Calculate the line number of the specified cursor position.
|
||||
pub fn parse_util_get_line_from_offset(s: &wstr, pos: usize) -> isize {
|
||||
pub fn get_line_from_offset(s: &wstr, pos: usize) -> isize {
|
||||
// Return the line pos is on, or -1 if it's after the end.
|
||||
if pos > s.len() {
|
||||
return -1;
|
||||
@@ -535,7 +531,7 @@ pub fn parse_util_get_line_from_offset(s: &wstr, pos: usize) -> isize {
|
||||
}
|
||||
|
||||
/// Get the offset of the first character on the specified line.
|
||||
pub fn parse_util_get_offset_from_line(s: &wstr, line: i32) -> Option<usize> {
|
||||
pub fn get_offset_from_line(s: &wstr, line: i32) -> Option<usize> {
|
||||
// Return the first position on line X, counting from 0.
|
||||
if line < 0 {
|
||||
return None;
|
||||
@@ -555,9 +551,9 @@ pub fn parse_util_get_offset_from_line(s: &wstr, line: i32) -> Option<usize> {
|
||||
}
|
||||
|
||||
/// Return the total offset of the buffer for the cursor position nearest to the specified position.
|
||||
pub fn parse_util_get_offset(s: &wstr, line: i32, line_offset: isize) -> Option<usize> {
|
||||
let off = parse_util_get_offset_from_line(s, line)?;
|
||||
let off2 = parse_util_get_offset_from_line(s, line + 1).unwrap_or(s.len() + 1);
|
||||
pub fn get_offset(s: &wstr, line: i32, line_offset: isize) -> Option<usize> {
|
||||
let off = get_offset_from_line(s, line)?;
|
||||
let off2 = get_offset_from_line(s, line + 1).unwrap_or(s.len() + 1);
|
||||
|
||||
let mut line_offset = line_offset as usize;
|
||||
if line_offset >= off2 - off - 1 {
|
||||
@@ -569,7 +565,7 @@ pub fn parse_util_get_offset(s: &wstr, line: i32, line_offset: isize) -> Option<
|
||||
|
||||
/// Return the given string, unescaping wildcard characters but not performing any other character
|
||||
/// transformation.
|
||||
pub fn parse_util_unescape_wildcards(s: &wstr) -> WString {
|
||||
pub fn unescape_wildcards(s: &wstr) -> WString {
|
||||
let mut result = WString::with_capacity(s.len());
|
||||
let unesc_qmark = !feature_test(FeatureFlag::QuestionMarkNoGlob);
|
||||
|
||||
@@ -598,7 +594,7 @@ pub fn parse_util_unescape_wildcards(s: &wstr) -> WString {
|
||||
}
|
||||
|
||||
/// Return if the given string contains wildcard characters.
|
||||
pub fn parse_util_contains_wildcards(s: &wstr) -> bool {
|
||||
pub fn contains_wildcards(s: &wstr) -> bool {
|
||||
let unesc_qmark = !feature_test(FeatureFlag::QuestionMarkNoGlob);
|
||||
|
||||
let mut i = 0;
|
||||
@@ -626,7 +622,7 @@ pub fn parse_util_contains_wildcards(s: &wstr) -> bool {
|
||||
|
||||
/// Escape any wildcard characters in the given string. e.g. convert
|
||||
/// "a*b" to "a\*b".
|
||||
pub fn parse_util_escape_wildcards(s: &wstr) -> WString {
|
||||
pub fn escape_wildcards(s: &wstr) -> WString {
|
||||
let mut result = WString::with_capacity(s.len());
|
||||
let unesc_qmark = !feature_test(FeatureFlag::QuestionMarkNoGlob);
|
||||
|
||||
@@ -645,7 +641,7 @@ pub fn parse_util_escape_wildcards(s: &wstr) -> WString {
|
||||
}
|
||||
|
||||
/// Checks if the specified string is a help option.
|
||||
pub fn parse_util_argument_is_help(s: &wstr) -> bool {
|
||||
pub fn argument_is_help(s: &wstr) -> bool {
|
||||
[L!("-h"), L!("--help")].contains(&s)
|
||||
}
|
||||
|
||||
@@ -700,7 +696,7 @@ fn error_for_character(c: char) -> WString {
|
||||
/// Attempts to escape the string 'cmd' using the given quote type, as determined by the quote
|
||||
/// character. The quote can be a single quote or double quote, or L'\0' to indicate no quoting (and
|
||||
/// thus escaping should be with backslashes). Optionally do not escape tildes.
|
||||
pub fn parse_util_escape_string_with_quote(
|
||||
pub fn escape_string_with_quote(
|
||||
cmd: &wstr,
|
||||
quote: Option<char>,
|
||||
escape_flags: EscapeFlags,
|
||||
@@ -757,11 +753,12 @@ pub fn parse_util_escape_string_with_quote(
|
||||
|
||||
/// Given a string, parse it as fish code and then return the indents. The return value has the same
|
||||
/// size as the string.
|
||||
pub fn parse_util_compute_indents(src: &wstr) -> Vec<i32> {
|
||||
compute_indents(src, 0)
|
||||
pub fn compute_indents(src: &wstr) -> Vec<i32> {
|
||||
compute_indents_from(src, 0)
|
||||
}
|
||||
|
||||
fn compute_indents(src: &wstr, initial_indent: i32) -> Vec<i32> {
|
||||
/// Compute the indents for the given source, starting with the specified initial indent.
|
||||
fn compute_indents_from(src: &wstr, initial_indent: i32) -> Vec<i32> {
|
||||
// Make a vector the same size as the input string, which contains the indents. Initialize them
|
||||
// to 0.
|
||||
let mut indents = vec![0; src.len()];
|
||||
@@ -929,7 +926,7 @@ fn indent_leaf(&mut self, range: SourceRange) {
|
||||
let mut was_double_quoted;
|
||||
loop {
|
||||
was_double_quoted = is_double_quoted;
|
||||
let parens = match parse_util_locate_cmdsubst_range(
|
||||
let parens = match locate_cmdsubst_range(
|
||||
node_src,
|
||||
&mut cursor,
|
||||
/*accept_incomplete=*/ true,
|
||||
@@ -946,7 +943,7 @@ fn indent_leaf(&mut self, range: SourceRange) {
|
||||
let command = parens.command();
|
||||
self.indent_string_part(done..range.start() + command.start, was_double_quoted);
|
||||
let cmdsub_contents = &node_src[command.clone()];
|
||||
let indents = compute_indents(cmdsub_contents, self.indent + 1);
|
||||
let indents = compute_indents_from(cmdsub_contents, self.indent + 1);
|
||||
self.indents[range.start() + command.start..range.start() + command.end]
|
||||
.copy_from_slice(&indents);
|
||||
|
||||
@@ -1124,7 +1121,7 @@ fn visit(&mut self, node: &'a dyn Node) {
|
||||
/// incomplete (e.g. an unclosed quote), an error is not returned and the ParserTestErrorBits::INCOMPLETE bit
|
||||
/// is set in the return value. If allow_incomplete is not set, then incomplete strings result in an
|
||||
/// error.
|
||||
pub fn parse_util_detect_errors(
|
||||
pub fn detect_parse_errors(
|
||||
buff_src: &wstr,
|
||||
mut out_errors: Option<&mut ParseErrorList>,
|
||||
allow_incomplete: bool, /*=false*/
|
||||
@@ -1176,12 +1173,12 @@ pub fn parse_util_detect_errors(
|
||||
}
|
||||
|
||||
// Defer to the tree-walking version.
|
||||
parse_util_detect_errors_in_ast(&ast, buff_src, out_errors)
|
||||
detect_parse_errors_in_ast(&ast, buff_src, out_errors)
|
||||
}
|
||||
|
||||
/// Like parse_util_detect_errors but accepts an already-parsed ast.
|
||||
/// Like detect_parse_errors but accepts an already-parsed ast.
|
||||
/// The top of the ast is assumed to be a job list.
|
||||
pub fn parse_util_detect_errors_in_ast(
|
||||
pub fn detect_parse_errors_in_ast(
|
||||
ast: &Ast,
|
||||
buff_src: &wstr,
|
||||
mut out_errors: Option<&mut ParseErrorList>,
|
||||
@@ -1230,7 +1227,7 @@ pub fn parse_util_detect_errors_in_ast(
|
||||
}
|
||||
Kind::Argument(arg) => {
|
||||
let arg_src = arg.source(buff_src);
|
||||
res |= parse_util_detect_errors_in_argument(arg, arg_src, &mut out_errors)
|
||||
res |= detect_errors_in_argument(arg, arg_src, &mut out_errors)
|
||||
.err()
|
||||
.unwrap_or_default();
|
||||
}
|
||||
@@ -1318,10 +1315,7 @@ pub fn parse_util_detect_errors_in_ast(
|
||||
|
||||
/// Detect errors in the specified string when parsed as an argument list. Returns the text of an
|
||||
/// error, or none if no error occurred.
|
||||
pub fn parse_util_detect_errors_in_argument_list(
|
||||
arg_list_src: &wstr,
|
||||
prefix: &wstr,
|
||||
) -> Result<(), WString> {
|
||||
pub fn detect_errors_in_argument_list(arg_list_src: &wstr, prefix: &wstr) -> Result<(), WString> {
|
||||
// Helper to return a description of the first error.
|
||||
let get_error_text = |errors: &ParseErrorList| {
|
||||
assert!(!errors.is_empty(), "Expected an error");
|
||||
@@ -1346,7 +1340,7 @@ pub fn parse_util_detect_errors_in_argument_list(
|
||||
let args = &arg_list.arguments;
|
||||
for arg in args.iter() {
|
||||
let arg_src = arg.source(arg_list_src);
|
||||
if parse_util_detect_errors_in_argument(arg, arg_src, &mut Some(&mut errors)).is_err() {
|
||||
if detect_errors_in_argument(arg, arg_src, &mut Some(&mut errors)).is_err() {
|
||||
return get_error_text(&errors);
|
||||
}
|
||||
}
|
||||
@@ -1388,7 +1382,7 @@ macro_rules! append_syntax_error_formatted {
|
||||
/// Test if this argument contains any errors. Detected errors include syntax errors in command
|
||||
/// substitutions, improperly escaped characters and improper use of the variable expansion
|
||||
/// operator.
|
||||
pub fn parse_util_detect_errors_in_argument(
|
||||
pub fn detect_errors_in_argument(
|
||||
arg: &ast::Argument,
|
||||
arg_src: &wstr,
|
||||
out_errors: &mut Option<&mut ParseErrorList>,
|
||||
@@ -1454,12 +1448,7 @@ pub fn parse_util_detect_errors_in_argument(
|
||||
{
|
||||
first_dollar -= 1;
|
||||
}
|
||||
parse_util_expand_variable_error(
|
||||
unesc.into(),
|
||||
source_start,
|
||||
first_dollar,
|
||||
out_errors,
|
||||
);
|
||||
expand_variable_error(unesc.into(), source_start, first_dollar, out_errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1474,7 +1463,7 @@ pub fn parse_util_detect_errors_in_argument(
|
||||
let mut is_quoted = false;
|
||||
while do_loop {
|
||||
let mut has_dollar = false;
|
||||
match parse_util_locate_cmdsubst_range(
|
||||
match locate_cmdsubst_range(
|
||||
arg_src,
|
||||
&mut cursor,
|
||||
false,
|
||||
@@ -1496,11 +1485,9 @@ pub fn parse_util_detect_errors_in_argument(
|
||||
out_errors,
|
||||
);
|
||||
let mut subst_errors = ParseErrorList::new();
|
||||
if let Err(subst_err) = parse_util_detect_errors(
|
||||
&arg_src[parens.command()],
|
||||
Some(&mut subst_errors),
|
||||
false,
|
||||
) {
|
||||
if let Err(subst_err) =
|
||||
detect_parse_errors(&arg_src[parens.command()], Some(&mut subst_errors), false)
|
||||
{
|
||||
err |= subst_err;
|
||||
}
|
||||
|
||||
@@ -1634,7 +1621,7 @@ fn detect_errors_in_decorated_statement(
|
||||
let mut first_arg_is_help = false;
|
||||
if let Some(arg) = get_first_arg(&dst.args_or_redirs) {
|
||||
let arg_src = arg.source(buff_src);
|
||||
first_arg_is_help = parse_util_argument_is_help(arg_src);
|
||||
first_arg_is_help = argument_is_help(arg_src);
|
||||
}
|
||||
|
||||
// Get the statement we are part of.
|
||||
@@ -1856,7 +1843,7 @@ fn detect_errors_in_block_redirection_list(
|
||||
/// Given a string containing a variable expansion error, append an appropriate error to the errors
|
||||
/// list. The global_token_pos is the offset of the token in the larger source, and the dollar_pos
|
||||
/// is the offset of the offending dollar sign within the token.
|
||||
pub fn parse_util_expand_variable_error(
|
||||
pub fn expand_variable_error(
|
||||
token: &wstr,
|
||||
global_token_pos: usize,
|
||||
dollar_pos: usize,
|
||||
@@ -1977,9 +1964,8 @@ pub fn parse_util_expand_variable_error(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
BOOL_AFTER_BACKGROUND_ERROR_MSG, parse_util_cmdsubst_extent, parse_util_compute_indents,
|
||||
parse_util_detect_errors, parse_util_escape_string_with_quote, parse_util_process_extent,
|
||||
parse_util_slice_length,
|
||||
BOOL_AFTER_BACKGROUND_ERROR_MSG, compute_indents, detect_parse_errors,
|
||||
escape_string_with_quote, get_cmdsubst_extent, get_process_extent, slice_length,
|
||||
};
|
||||
use crate::common::EscapeFlags;
|
||||
use crate::parse_constants::{
|
||||
@@ -2035,7 +2021,7 @@ fn string_matches_format(s: &wstr, format: &wstr) -> bool {
|
||||
macro_rules! validate {
|
||||
($src:expr, $error_text_format:expr) => {
|
||||
let mut errors = vec![];
|
||||
let res = parse_util_detect_errors(L!($src), Some(&mut errors), false);
|
||||
let res = detect_parse_errors(L!($src), Some(&mut errors), false);
|
||||
let fmt = wgettext!($error_text_format);
|
||||
assert!(res.is_err());
|
||||
assert!(
|
||||
@@ -2069,11 +2055,11 @@ macro_rules! validate {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_util_process_extent() {
|
||||
fn test_get_process_extent() {
|
||||
macro_rules! validate {
|
||||
($commandline:literal, $cursor:expr, $expected_range:expr) => {
|
||||
assert_eq!(
|
||||
parse_util_process_extent(L!($commandline), $cursor, None),
|
||||
get_process_extent(L!($commandline), $cursor, None),
|
||||
$expected_range
|
||||
);
|
||||
};
|
||||
@@ -2085,31 +2071,28 @@ macro_rules! validate {
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn test_parse_util_cmdsubst_extent() {
|
||||
fn test_get_cmdsubst_extent() {
|
||||
let _cleanup = test_init();
|
||||
let a = L!("echo (echo (echo hi");
|
||||
assert_eq!(parse_util_cmdsubst_extent(a, 0), 0..a.len());
|
||||
assert_eq!(parse_util_cmdsubst_extent(a, 1), 0..a.len());
|
||||
assert_eq!(parse_util_cmdsubst_extent(a, 2), 0..a.len());
|
||||
assert_eq!(parse_util_cmdsubst_extent(a, 3), 0..a.len());
|
||||
assert_eq!(get_cmdsubst_extent(a, 0), 0..a.len());
|
||||
assert_eq!(get_cmdsubst_extent(a, 1), 0..a.len());
|
||||
assert_eq!(get_cmdsubst_extent(a, 2), 0..a.len());
|
||||
assert_eq!(get_cmdsubst_extent(a, 3), 0..a.len());
|
||||
assert_eq!(get_cmdsubst_extent(a, 8), "echo (".chars().count()..a.len());
|
||||
assert_eq!(
|
||||
parse_util_cmdsubst_extent(a, 8),
|
||||
"echo (".chars().count()..a.len()
|
||||
);
|
||||
assert_eq!(
|
||||
parse_util_cmdsubst_extent(a, 17),
|
||||
get_cmdsubst_extent(a, 17),
|
||||
"echo (echo (".chars().count()..a.len()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn test_parse_util_slice_length() {
|
||||
fn test_slice_length() {
|
||||
let _cleanup = test_init();
|
||||
assert_eq!(parse_util_slice_length(L!("[2]")), Some(3));
|
||||
assert_eq!(parse_util_slice_length(L!("[12]")), Some(4));
|
||||
assert_eq!(parse_util_slice_length(L!("[\"foo\"]")), Some(7));
|
||||
assert_eq!(parse_util_slice_length(L!("[\"foo\"")), None);
|
||||
assert_eq!(slice_length(L!("[2]")), Some(3));
|
||||
assert_eq!(slice_length(L!("[12]")), Some(4));
|
||||
assert_eq!(slice_length(L!("[\"foo\"]")), Some(7));
|
||||
assert_eq!(slice_length(L!("[\"foo\"")), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2119,7 +2102,7 @@ fn test_escape_quotes() {
|
||||
macro_rules! validate {
|
||||
($cmd:expr, $quote:expr, $no_tilde:expr, $expected:expr) => {
|
||||
assert_eq!(
|
||||
parse_util_escape_string_with_quote(
|
||||
escape_string_with_quote(
|
||||
L!($cmd),
|
||||
$quote,
|
||||
if $no_tilde {
|
||||
@@ -2135,7 +2118,7 @@ macro_rules! validate {
|
||||
macro_rules! validate_no_quoted {
|
||||
($cmd:expr, $quote:expr, $no_tilde:expr, $expected:expr) => {
|
||||
assert_eq!(
|
||||
parse_util_escape_string_with_quote(
|
||||
escape_string_with_quote(
|
||||
L!($cmd),
|
||||
$quote,
|
||||
EscapeFlags::NO_QUOTED
|
||||
@@ -2205,7 +2188,7 @@ fn do_validate(segments: &[Segment]) {
|
||||
expected_indents.push(segment.indent);
|
||||
}
|
||||
}
|
||||
let indents = parse_util_compute_indents(&text);
|
||||
let indents = compute_indents(&text);
|
||||
assert_eq!(indents, expected_indents);
|
||||
}
|
||||
macro_rules! validate {
|
||||
|
||||
@@ -598,12 +598,12 @@ pub fn eval_wstr(
|
||||
block_type: BlockType,
|
||||
) -> Result<EvalRes, WString> {
|
||||
use crate::parse_tree::ParsedSource;
|
||||
use crate::parse_util::parse_util_detect_errors_in_ast;
|
||||
use crate::parse_util::detect_parse_errors_in_ast;
|
||||
let mut errors = vec![];
|
||||
let ast = ast::parse(&src, ParseTreeFlags::default(), Some(&mut errors));
|
||||
let mut errored = ast.errored();
|
||||
if !errored {
|
||||
errored = parse_util_detect_errors_in_ast(&ast, &src, Some(&mut errors)).is_err();
|
||||
errored = detect_parse_errors_in_ast(&ast, &src, Some(&mut errors)).is_err();
|
||||
}
|
||||
if errored {
|
||||
let sb = self.get_backtrace(&src, &errors);
|
||||
@@ -1492,7 +1492,7 @@ mod tests {
|
||||
ParseErrorCode, ParseTokenType, ParseTreeFlags, ParserTestErrorBits, StatementDecoration,
|
||||
};
|
||||
use crate::parse_tree::{LineCounter, parse_source};
|
||||
use crate::parse_util::{parse_util_detect_errors, parse_util_detect_errors_in_argument};
|
||||
use crate::parse_util::{detect_errors_in_argument, detect_parse_errors};
|
||||
use crate::prelude::*;
|
||||
use crate::reader::{fake_scoped_reader, reader_reset_interrupted};
|
||||
use crate::signal::{signal_clear_cancel, signal_reset_handlers, signal_set_handlers};
|
||||
@@ -1506,7 +1506,7 @@ fn test_parser() {
|
||||
let _cleanup = test_init();
|
||||
macro_rules! detect_errors {
|
||||
($src:literal) => {
|
||||
parse_util_detect_errors(L!($src), None, true /* accept incomplete */)
|
||||
detect_parse_errors(L!($src), None, true /* accept incomplete */)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1519,7 +1519,7 @@ fn detect_argument_errors(src: &str) -> Result<(), ParserTestErrorBits> {
|
||||
let args = &ast.top().arguments;
|
||||
let first_arg = args.first().expect("Failed to parse an argument");
|
||||
let mut errors = None;
|
||||
parse_util_detect_errors_in_argument(first_arg, first_arg.source(&src), &mut errors)
|
||||
detect_errors_in_argument(first_arg, first_arg.source(&src), &mut errors)
|
||||
}
|
||||
|
||||
// Testing block nesting
|
||||
@@ -1694,7 +1694,7 @@ fn detect_argument_errors(src: &str) -> Result<(), ParserTestErrorBits> {
|
||||
);
|
||||
|
||||
// Within command substitutions, we should be able to detect everything that
|
||||
// parse_util_detect_errors! can detect.
|
||||
// detect_errors! can detect.
|
||||
assert!(
|
||||
detect_argument_errors("foo(cat | or cat)")
|
||||
.unwrap_err()
|
||||
|
||||
@@ -102,47 +102,37 @@
|
||||
use crate::panic::AT_EXIT;
|
||||
use crate::parse_constants::SourceRange;
|
||||
use crate::parse_constants::{ParseTreeFlags, ParserTestErrorBits};
|
||||
use crate::parse_util::MaybeParentheses;
|
||||
use crate::parse_util::SPACES_PER_INDENT;
|
||||
use crate::parse_util::parse_util_process_extent;
|
||||
use crate::parse_util::parse_util_process_first_token_offset;
|
||||
use crate::parse_util::{
|
||||
parse_util_cmdsubst_extent, parse_util_compute_indents, parse_util_contains_wildcards,
|
||||
parse_util_detect_errors, parse_util_escape_string_with_quote, parse_util_escape_wildcards,
|
||||
parse_util_get_line_from_offset, parse_util_get_offset, parse_util_get_offset_from_line,
|
||||
parse_util_lineno, parse_util_locate_cmdsubst_range, parse_util_token_extent,
|
||||
MaybeParentheses, SPACES_PER_INDENT, compute_indents, contains_wildcards, detect_parse_errors,
|
||||
escape_string_with_quote, escape_wildcards, get_cmdsubst_extent, get_line_from_offset,
|
||||
get_offset, get_offset_from_line, get_process_extent, get_process_first_token_offset,
|
||||
get_token_extent, lineno, locate_cmdsubst_range,
|
||||
};
|
||||
use crate::parser::ParserEnvSetMode;
|
||||
use crate::parser::{BlockType, EvalRes, Parser};
|
||||
use crate::parser::{BlockType, EvalRes, Parser, ParserEnvSetMode};
|
||||
use crate::prelude::*;
|
||||
use crate::proc::{
|
||||
HAVE_PROC_STAT, hup_jobs, is_interactive_session, job_reap, jobs_requiring_warning_on_exit,
|
||||
print_exit_warning_for_jobs, proc_update_jiffies,
|
||||
};
|
||||
use crate::screen::is_dumb;
|
||||
use crate::screen::{CharOffset, Screen, screen_force_clear_to_end};
|
||||
use crate::screen::{CharOffset, Screen, is_dumb, screen_force_clear_to_end};
|
||||
use crate::should_flog;
|
||||
use crate::signal::{
|
||||
signal_check_cancel, signal_clear_cancel, signal_reset_handlers, signal_set_handlers,
|
||||
signal_set_handlers_once,
|
||||
};
|
||||
use crate::terminal::BufferedOutputter;
|
||||
use crate::terminal::Output;
|
||||
use crate::terminal::Outputter;
|
||||
use crate::terminal::TerminalCommand::{
|
||||
self, ClearScreen, DecrstAlternateScreenBuffer, DecsetAlternateScreenBuffer, DecsetShowCursor,
|
||||
Osc0WindowTitle, Osc1TabTitle, Osc133CommandFinished, Osc133CommandStart, QueryBackgroundColor,
|
||||
QueryCursorPosition, QueryKittyKeyboardProgressiveEnhancements, QueryPrimaryDeviceAttribute,
|
||||
QueryXtgettcap, QueryXtversion,
|
||||
};
|
||||
use crate::terminal::{BufferedOutputter, Output, Outputter};
|
||||
use crate::termsize::{safe_termsize_invalidate_tty, termsize_last, termsize_update};
|
||||
use crate::text_face::TextFace;
|
||||
use crate::text_face::parse_text_face;
|
||||
use crate::text_face::{TextFace, parse_text_face};
|
||||
use crate::threads::{assert_is_background_thread, assert_is_main_thread};
|
||||
use crate::tokenizer::quote_end;
|
||||
use crate::tokenizer::variable_assignment_equals_pos;
|
||||
use crate::tokenizer::{
|
||||
TOK_ACCEPT_UNFINISHED, TOK_SHOW_COMMENTS, TokenType, Tokenizer, tok_command,
|
||||
TOK_ACCEPT_UNFINISHED, TOK_SHOW_COMMENTS, TokenType, Tokenizer, quote_end, tok_command,
|
||||
variable_assignment_equals_pos,
|
||||
};
|
||||
use crate::tty_handoff::SCROLL_CONTENT_UP_TERMINFO_CODE;
|
||||
use crate::tty_handoff::XTGETTCAP_QUERY_OS_NAME;
|
||||
@@ -1656,7 +1646,7 @@ fn combine_command_and_autosuggestion(
|
||||
// Here we do something funny: if the last token of the command line contains any uppercase
|
||||
// characters, we use its case. Otherwise we use the case of the autosuggestion. This
|
||||
// is an idea from issue #335.
|
||||
let (tok, _) = parse_util_token_extent(cmdline, cmdline.len() - 1);
|
||||
let (tok, _) = get_token_extent(cmdline, cmdline.len() - 1);
|
||||
let last_token_contains_uppercase = cmdline[tok].chars().any(|c| c.is_uppercase());
|
||||
if !last_token_contains_uppercase {
|
||||
// Use the autosuggestion's case.
|
||||
@@ -1879,7 +1869,7 @@ fn paint_layout(&mut self, reason: &wstr, is_final_rendering: bool) {
|
||||
);
|
||||
|
||||
// Compute the indentation.
|
||||
let indents = parse_util_compute_indents(&full_line);
|
||||
let indents = compute_indents(&full_line);
|
||||
|
||||
let screen = &mut self.data.screen;
|
||||
let pager = &mut self.data.pager;
|
||||
@@ -2095,7 +2085,7 @@ fn clear_transient_edit(&mut self) {
|
||||
fn replace_current_token(&mut self, new_token: WString) {
|
||||
// Find current token.
|
||||
let (elt, el) = self.active_edit_line();
|
||||
let (token_range, _) = parse_util_token_extent(el.text(), el.position());
|
||||
let (token_range, _) = get_token_extent(el.text(), el.position());
|
||||
|
||||
self.replace_substring(elt, token_range, new_token);
|
||||
}
|
||||
@@ -3368,7 +3358,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) {
|
||||
let el = &self.data.command_line;
|
||||
if matches!(mode, SearchMode::Token | SearchMode::LastToken) {
|
||||
// Searching by token.
|
||||
let (token_range, _) = parse_util_token_extent(el.text(), el.position());
|
||||
let (token_range, _) = get_token_extent(el.text(), el.position());
|
||||
self.data.history_search.reset_to_mode(
|
||||
el.text()[token_range.clone()].to_owned(),
|
||||
self.history.clone(),
|
||||
@@ -3450,17 +3440,15 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) {
|
||||
let search_string = if !self.history_search.active()
|
||||
|| self.history_search.search_string().is_empty()
|
||||
{
|
||||
let cmdsub = parse_util_cmdsubst_extent(
|
||||
self.command_line.text(),
|
||||
self.command_line.position(),
|
||||
);
|
||||
let cmdsub =
|
||||
get_cmdsubst_extent(self.command_line.text(), self.command_line.position());
|
||||
let cmdsub = &self.command_line.text()[cmdsub];
|
||||
let needle = if !cmdsub.contains('\n') {
|
||||
cmdsub
|
||||
} else {
|
||||
line_at_cursor(self.command_line.text(), self.command_line.position())
|
||||
};
|
||||
parse_util_escape_wildcards(needle)
|
||||
escape_wildcards(needle)
|
||||
} else {
|
||||
// If we have an actual history search already going, reuse that term
|
||||
// - this is if the user looks around a bit and decides to switch to the pager.
|
||||
@@ -3848,8 +3836,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) {
|
||||
// Not navigating the pager contents.
|
||||
let (elt, el) = self.active_edit_line();
|
||||
let line_old =
|
||||
i32::try_from(parse_util_get_line_from_offset(el.text(), el.position()))
|
||||
.unwrap();
|
||||
i32::try_from(get_line_from_offset(el.text(), el.position())).unwrap();
|
||||
|
||||
let line_new = if c == rl::UpLine {
|
||||
line_old - 1
|
||||
@@ -3857,14 +3844,12 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) {
|
||||
line_old + 1
|
||||
};
|
||||
|
||||
let line_count = parse_util_lineno(el.text(), el.len()) - 1;
|
||||
let line_count = lineno(el.text(), el.len()) - 1;
|
||||
|
||||
if (0..=i32::try_from(line_count).unwrap()).contains(&line_new) {
|
||||
let indents = parse_util_compute_indents(el.text());
|
||||
let base_pos_new =
|
||||
parse_util_get_offset_from_line(el.text(), line_new).unwrap();
|
||||
let base_pos_old =
|
||||
parse_util_get_offset_from_line(el.text(), line_old).unwrap();
|
||||
let indents = compute_indents(el.text());
|
||||
let base_pos_new = get_offset_from_line(el.text(), line_new).unwrap();
|
||||
let base_pos_old = get_offset_from_line(el.text(), line_old).unwrap();
|
||||
|
||||
let indent_old = indents[std::cmp::min(indents.len() - 1, base_pos_old)];
|
||||
let indent_new = indents[std::cmp::min(indents.len() - 1, base_pos_new)];
|
||||
@@ -3873,7 +3858,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) {
|
||||
|
||||
let line_offset_old =
|
||||
isize::try_from(el.position() - base_pos_old).unwrap();
|
||||
let total_offset_new = parse_util_get_offset(
|
||||
let total_offset_new = get_offset(
|
||||
el.text(),
|
||||
line_new,
|
||||
line_offset_old
|
||||
@@ -3935,13 +3920,13 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) {
|
||||
let (elt, el) = self.active_edit_line();
|
||||
let text = el.text();
|
||||
|
||||
let (mut tok, mut prev_tok) = parse_util_token_extent(text, el.position());
|
||||
let (mut tok, mut prev_tok) = get_token_extent(text, el.position());
|
||||
|
||||
// In case we didn't find a token at or after the cursor...
|
||||
if tok.start == el.len() {
|
||||
// ...retry beginning from the previous token.
|
||||
let pos = prev_tok.end;
|
||||
(tok, prev_tok) = parse_util_token_extent(text, pos);
|
||||
(tok, prev_tok) = get_token_extent(text, pos);
|
||||
}
|
||||
|
||||
// Make sure we have two tokens.
|
||||
@@ -4346,12 +4331,12 @@ fn backward_token(&mut self) -> Option<usize> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let (tok, prev_tok) = parse_util_token_extent(el.text(), el.position());
|
||||
let (tok, prev_tok) = get_token_extent(el.text(), el.position());
|
||||
|
||||
// if we are at the start of a token, go back one
|
||||
let new_position = if tok.start == pos {
|
||||
if prev_tok.start == pos {
|
||||
let cmdsub = parse_util_cmdsubst_extent(el.text(), prev_tok.start);
|
||||
let cmdsub = get_cmdsubst_extent(el.text(), prev_tok.start);
|
||||
cmdsub.start.saturating_sub(1)
|
||||
} else {
|
||||
prev_tok.start
|
||||
@@ -4382,7 +4367,7 @@ fn forward_token(&self, autosuggest: bool) -> Option<usize> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let cmdsubst_range = parse_util_cmdsubst_extent(&buffer, pos);
|
||||
let cmdsubst_range = get_cmdsubst_extent(&buffer, pos);
|
||||
for token in Tokenizer::new(&buffer[cmdsubst_range.clone()], TOK_ACCEPT_UNFINISHED) {
|
||||
if token.type_ != TokenType::String {
|
||||
continue;
|
||||
@@ -5240,10 +5225,10 @@ fn get_autosuggestion_performer(
|
||||
if search_type == SearchType::LinePrefix {
|
||||
let cursor_line_has_process_start = {
|
||||
let mut tokens = vec![];
|
||||
parse_util_process_extent(&command_line, cursor_pos, Some(&mut tokens));
|
||||
get_process_extent(&command_line, cursor_pos, Some(&mut tokens));
|
||||
range_of_line_at_cursor(
|
||||
&command_line,
|
||||
parse_util_process_first_token_offset(&command_line, cursor_pos)
|
||||
get_process_first_token_offset(&command_line, cursor_pos)
|
||||
.unwrap_or(cursor_pos),
|
||||
) == range
|
||||
};
|
||||
@@ -5761,7 +5746,7 @@ fn history_pager_search(
|
||||
smartcase_flags(search_string),
|
||||
history_index,
|
||||
);
|
||||
if !search.go_to_next_match(direction) && !parse_util_contains_wildcards(search_string) {
|
||||
if !search.go_to_next_match(direction) && !contains_wildcards(search_string) {
|
||||
// If there were no matches, and the user is not intending for
|
||||
// wildcard search, try again with subsequence search.
|
||||
search = HistorySearch::new_with(
|
||||
@@ -5983,7 +5968,7 @@ fn extract_tokens(s: &wstr) -> Vec<PositionedToken> {
|
||||
let mut has_cmd_subs = false;
|
||||
let mut cmdsub_cursor = range.start();
|
||||
loop {
|
||||
match parse_util_locate_cmdsubst_range(
|
||||
match locate_cmdsubst_range(
|
||||
s,
|
||||
&mut cmdsub_cursor,
|
||||
/*accept_incomplete=*/ true,
|
||||
@@ -6318,7 +6303,7 @@ fn reader_run_command(parser: &Parser, cmd: &wstr) -> EvalRes {
|
||||
|
||||
fn reader_shell_test(parser: &Parser, bstr: &wstr) -> Result<(), ParserTestErrorBits> {
|
||||
let mut errors = vec![];
|
||||
let res = parse_util_detect_errors(bstr, Some(&mut errors), /*accept_incomplete=*/ true);
|
||||
let res = detect_parse_errors(bstr, Some(&mut errors), /*accept_incomplete=*/ true);
|
||||
|
||||
if res.is_err_and(|err| err.contains(ParserTestErrorBits::ERROR)) {
|
||||
let mut error_desc = parser.get_backtrace(bstr, &errors);
|
||||
@@ -6644,7 +6629,7 @@ pub fn completion_apply_to_command_line(
|
||||
|
||||
if do_replace_line {
|
||||
assert!(!do_escape, "unsupported completion flag");
|
||||
let cmdsub = parse_util_cmdsubst_extent(command_line, cursor_pos);
|
||||
let cmdsub = get_cmdsubst_extent(command_line, cursor_pos);
|
||||
return if !command_line[cmdsub.clone()].contains('\n') {
|
||||
*inout_cursor_pos = cmdsub.start + val_str.len();
|
||||
command_line[..cmdsub.start].to_owned() + val_str + &command_line[cmdsub.end..]
|
||||
@@ -6678,7 +6663,7 @@ pub fn completion_apply_to_command_line(
|
||||
}
|
||||
}
|
||||
let mut move_cursor = 0;
|
||||
let (range, _) = parse_util_token_extent(command_line, cursor_pos);
|
||||
let (range, _) = get_token_extent(command_line, cursor_pos);
|
||||
|
||||
let mut sb = command_line[..range.start].to_owned();
|
||||
|
||||
@@ -6714,7 +6699,7 @@ pub fn completion_apply_to_command_line(
|
||||
|
||||
let mut quote = None;
|
||||
let replaced = if do_escape {
|
||||
let (tok, _) = parse_util_token_extent(command_line, cursor_pos);
|
||||
let (tok, _) = get_token_extent(command_line, cursor_pos);
|
||||
// Find the last quote in the token to complete.
|
||||
let mut have_token = false;
|
||||
if tok.contains(&cursor_pos) || cursor_pos == tok.end {
|
||||
@@ -6739,7 +6724,7 @@ pub fn completion_apply_to_command_line(
|
||||
escape_flags.insert(EscapeFlags::NO_QUOTED);
|
||||
}
|
||||
|
||||
parse_util_escape_string_with_quote(val_str, quote, escape_flags)
|
||||
escape_string_with_quote(val_str, quote, escape_flags)
|
||||
} else {
|
||||
val_str.to_owned()
|
||||
};
|
||||
@@ -6757,7 +6742,7 @@ pub fn completion_apply_to_command_line(
|
||||
insertion_point + replaced.len() + if back_into_trailing_quote { 1 } else { 0 };
|
||||
if let Some(mut trailer) = trailer {
|
||||
if is_variable_name {
|
||||
let (tok, _) = parse_util_token_extent(command_line, cursor_pos);
|
||||
let (tok, _) = get_token_extent(command_line, cursor_pos);
|
||||
maybe_add_slash(&mut trailer, &result[tok.start..new_cursor_pos]);
|
||||
}
|
||||
// TODO(MSRV/edition 2024): use if let chain for quote instead of `is_some` followed
|
||||
@@ -6819,13 +6804,13 @@ fn compute_and_apply_completions(&mut self, c: ReadlineCmd) {
|
||||
// This is because we only look at the current command substitution to form
|
||||
// completions - stuff happening outside of it is not interesting.
|
||||
let el = &self.command_line;
|
||||
let cmdsub_range = parse_util_cmdsubst_extent(el.text(), el.position());
|
||||
let cmdsub_range = get_cmdsubst_extent(el.text(), el.position());
|
||||
let position_in_cmdsub = el.position() - cmdsub_range.start;
|
||||
|
||||
// Figure out the extent of the token within the command substitution. Note we
|
||||
// pass cmdsub_begin here, not buff.
|
||||
let (mut token_range, _) =
|
||||
parse_util_token_extent(&el.text()[cmdsub_range.clone()], position_in_cmdsub);
|
||||
get_token_extent(&el.text()[cmdsub_range.clone()], position_in_cmdsub);
|
||||
let position_in_token = position_in_cmdsub - token_range.start;
|
||||
|
||||
// Hack: the token may extend past the end of the command substitution, e.g. in
|
||||
|
||||
@@ -2185,7 +2185,7 @@ pub fn wcswidth_rendered(s: &wstr) -> isize {
|
||||
mod tests {
|
||||
use crate::common::get_ellipsis_char;
|
||||
use crate::highlight::HighlightSpec;
|
||||
use crate::parse_util::parse_util_compute_indents;
|
||||
use crate::parse_util::compute_indents;
|
||||
use crate::prelude::*;
|
||||
use crate::screen::{
|
||||
LayoutCache, PromptCacheEntry, PromptLayout, ScreenLayout, compute_layout,
|
||||
@@ -2448,7 +2448,7 @@ macro_rules! validate {
|
||||
+ L!($autosuggestion_str)
|
||||
+ L!($commandline_after_suggestion);
|
||||
let mut colors = vec![HighlightSpec::default(); full_commandline.len()];
|
||||
let mut indent = parse_util_compute_indents(&full_commandline);
|
||||
let mut indent = compute_indents(&full_commandline);
|
||||
assert_eq!(
|
||||
compute_layout(
|
||||
'…',
|
||||
|
||||
Reference in New Issue
Block a user