From 560e3631ec57d34c679e6b0faec1e0efdd18d915 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 10 Aug 2024 11:26:26 +1000 Subject: Move debug utils to debug.hh/debug.cc Lots of code includes buffer_utils.hh just for write_to_debug_buffer which pulls many unnecessary dependencies. Reorganise to reduce compile times. --- src/command_manager.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/command_manager.cc') diff --git a/src/command_manager.cc b/src/command_manager.cc index f7d094bb..3e44ab1e 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -2,10 +2,11 @@ #include "alias_registry.hh" #include "assert.hh" -#include "buffer_utils.hh" #include "context.hh" +#include "debug.hh" #include "flags.hh" #include "file.hh" +#include "hook_manager.hh" #include "optional.hh" #include "option_types.hh" #include "profile.hh" @@ -13,6 +14,7 @@ #include "regex.hh" #include "register_manager.hh" #include "shell_manager.hh" +#include "scope.hh" #include "utils.hh" #include "unit_tests.hh" -- cgit v1.2.3 From 9275d965a6952d44035fd0502ee0d3991352c460 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Aug 2024 21:00:08 +1000 Subject: Do not gather full input data in a single string when piping Refactor ShellManager and pipe to feed lines from the buffer directly, this should reduce memory use when piping big chunks of buffers. The pipe output is still provided as a single big buffer. --- src/command_manager.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/command_manager.cc') diff --git a/src/command_manager.cc b/src/command_manager.cc index 3e44ab1e..fd32f93c 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -350,7 +350,8 @@ void expand_token(Token&& token, const Context& context, const ShellContext& she case Token::Type::ShellExpand: { auto str = ShellManager::instance().eval( - content, context, {}, ShellManager::Flags::WaitForStdout, + content, context, StringView{}, + ShellManager::Flags::WaitForStdout, shell_context).first; if (not str.empty() and str.back() == '\n') -- cgit v1.2.3 From 50917b39ca410feac0f8dbf37b6db408aeedc2b8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 22 Oct 2024 21:18:23 +1100 Subject: Remove now unused CompletionFlags Since shell-script-completions now runs the script asynchronously and unconditionally, there is no use for the CompletionFlags::Fast anymore which means we can remove that type altogether. --- src/command_manager.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/command_manager.cc') diff --git a/src/command_manager.cc b/src/command_manager.cc index fd32f93c..e30f8a68 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -658,7 +658,7 @@ Completions CommandManager::complete_module_name(StringView query) const | transform(&ModuleMap::Item::key))}; } -static Completions complete_expansion(const Context& context, CompletionFlags flags, +static Completions complete_expansion(const Context& context, Token token, ByteCount start, ByteCount cursor_pos, ByteCount pos_in_token) { @@ -674,7 +674,7 @@ static Completions complete_expansion(const Context& context, CompletionFlags fl token.content, pos_in_token) }; case Token::Type::ShellExpand: - return offset_pos(shell_complete(context, flags, token.content, + return offset_pos(shell_complete(context, token.content, pos_in_token), start); case Token::Type::ValExpand: @@ -695,7 +695,7 @@ static Completions complete_expansion(const Context& context, CompletionFlags fl } } -static Completions complete_expand(const Context& context, CompletionFlags flags, +static Completions complete_expand(const Context& context, StringView prefix, ByteCount start, ByteCount cursor_pos, ByteCount pos_in_token) { @@ -713,7 +713,7 @@ static Completions complete_expand(const Context& context, CompletionFlags flags continue; if (token.type == Token::Type::Raw or token.type == Token::Type::RawQuoted) return {}; - return complete_expansion(context, flags, token, + return complete_expansion(context, token, start + token.pos, cursor_pos, pos_in_token - token.pos); } @@ -748,8 +748,7 @@ static Completions requote(Completions completions, Token::Type token_type) } Completions CommandManager::Completer::operator()( - const Context& context, CompletionFlags flags, - StringView command_line, ByteCount cursor_pos) + const Context& context, StringView command_line, ByteCount cursor_pos) { auto prefix = command_line.substr(0_byte, cursor_pos); CommandParser parser{prefix}; @@ -800,7 +799,7 @@ Completions CommandManager::Completer::operator()( case Token::Type::ShellExpand: case Token::Type::ValExpand: case Token::Type::FileExpand: - return complete_expansion(context, flags, token, start, cursor_pos, pos_in_token); + return complete_expansion(context, token, start, cursor_pos, pos_in_token); case Token::Type::Raw: case Token::Type::RawQuoted: @@ -840,7 +839,7 @@ Completions CommandManager::Completer::operator()( const auto& switch_desc = command.param_desc.switches.get(raw_params.at(raw_params.size() - 2).substr(1_byte)); if (not *switch_desc.arg_completer) return Completions{}; - return offset_pos(requote((*switch_desc.arg_completer)(context, flags, raw_params.back(), pos_in_token), token.type), start); + return offset_pos(requote((*switch_desc.arg_completer)(context, raw_params.back(), pos_in_token), token.type), start); } case ParametersParser::State::Positional: break; @@ -852,10 +851,10 @@ Completions CommandManager::Completer::operator()( Vector params{parser.begin(), parser.end()}; auto index = params.size() - 1; - return offset_pos(requote(m_command_completer(context, flags, params, index, pos_in_token), token.type), start); + return offset_pos(requote(m_command_completer(context, params, index, pos_in_token), token.type), start); } case Token::Type::Expand: - return complete_expand(context, flags, token.content, start, cursor_pos, pos_in_token); + return complete_expand(context, token.content, start, cursor_pos, pos_in_token); default: break; } @@ -863,7 +862,7 @@ Completions CommandManager::Completer::operator()( } Completions CommandManager::NestedCompleter::operator()( - const Context& context, CompletionFlags flags, CommandParameters params, + const Context& context, CommandParameters params, size_t token_to_complete, ByteCount pos_in_token) { StringView prefix = params[token_to_complete].substr(0, pos_in_token); @@ -881,7 +880,7 @@ Completions CommandManager::NestedCompleter::operator()( } return m_command_completer - ? m_command_completer(context, flags, params.subrange(1), token_to_complete-1, pos_in_token) + ? m_command_completer(context, params.subrange(1), token_to_complete-1, pos_in_token) : Completions{}; } -- cgit v1.2.3 From be82047dbf5f74f123e925b96e0e13962a4e0c09 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 28 Oct 2024 12:21:09 +1100 Subject: Only check for ascii horizontal blanks during command parsing The general is_horizontal_blank supports various unicode blanks, but passing an utf8 continuation byte to it can lead to surprising results as we can match with 0xA0 (when char is unsigned). Fixes #5250 --- src/command_manager.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/command_manager.cc') diff --git a/src/command_manager.cc b/src/command_manager.cc index e30f8a68..0db97e94 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -179,6 +179,13 @@ ParseResult parse_quoted_balanced(ParseState& state) return {String{String::NoCopy{}, {beg, pos - terminated}}, terminated}; } +bool is_ascii_horizontal_blank(char c) +{ + return c == '\t' or + c == '\f' or + c == ' '; +} + String parse_unquoted(ParseState& state) { const char* beg = state.pos; @@ -189,7 +196,7 @@ String parse_unquoted(ParseState& state) while (state.pos != end) { const char c = *state.pos; - if (is_command_separator(c) or is_horizontal_blank(c)) + if (is_command_separator(c) or is_ascii_horizontal_blank(c)) { str += StringView{beg, state.pos}; if (state.pos != beg and *(state.pos - 1) == '\\') @@ -235,8 +242,8 @@ void skip_blanks_and_comments(ParseState& state) { while (state) { - const Codepoint c = *state.pos; - if (is_horizontal_blank(c)) + const char c = *state.pos; + if (is_ascii_horizontal_blank(c)) ++state.pos; else if (c == '\\' and state.pos + 1 != state.str.end() and state.pos[1] == '\n') -- cgit v1.2.3