diff --git a/driver/tab_completion.py b/driver/tab_completion.py index 94e648d0ed..bc73c5972e 100644 --- a/driver/tab_completion.py +++ b/driver/tab_completion.py @@ -61,7 +61,7 @@ def complete_planner_args(prefix, parsed_args, **kwargs): if not last_option_was_mode_switch: completions.append("--translate-options") - downward = bin_dir / "downward" + downward = bin_dir / "downward" if downward.exists(): completions += get_completions_from_downward( downward, parsed_args.search_options, prefix) @@ -87,10 +87,11 @@ def get_completions_from_downward(downward, options, prefix): comp_point = str(len(comp_line)) comp_cword = str(len(simulated_commandline) - 1) cmd = [str(downward), "--bash-complete", - comp_point, comp_line, comp_cword] + simulated_commandline + comp_point, comp_line, comp_cword] + simulated_commandline output = subprocess.check_output(cmd, text=True) return output.split() + def get_completions_from_translator(translator, options, prefix): simulated_commandline = [str(translator)] + options + [prefix] comp_line = " ".join(simulated_commandline) diff --git a/src/search/command_line.cc b/src/search/command_line.cc index 39d95f83b9..4bb3922a20 100644 --- a/src/search/command_line.cc +++ b/src/search/command_line.cc @@ -12,6 +12,7 @@ #include "utils/strings.h" #include +#include #include #include @@ -197,7 +198,32 @@ static vector complete_args( suggestions.push_back(feature->get_key()); } } else if (last_arg == "--internal-plan-file") { - // suggest filename starting with current_word + // Suggest filename starting with current_word + + // Split into directory and file_prefix + string directory = "."; + string file_prefix = current_word; + auto last_slash_pos = current_word.find_last_of("/\\"); + if (last_slash_pos != string::npos) { + directory = current_word.substr(0, last_slash_pos); + file_prefix = current_word.substr(last_slash_pos + 1); + } + + // Add file and directory names to suggestions + for (const auto& entry : filesystem::directory_iterator(directory)) { + string path = entry.path().string(); + + // Append slash to directories + if (entry.is_directory()) { + path += "/"; + } + + // Remove "./" prefix when not present in prefix + if (last_slash_pos == string::npos && directory == "." && path.starts_with("./")) { + path = path.substr(2); + } + suggestions.push_back(path); + } } else if (last_arg == "--internal-previous-portfolio-plans") { // no suggestions, integer expected } else if (last_arg == "--search") { @@ -244,7 +270,7 @@ void handle_tab_completion(int argc, const char **argv) { "$COMP_LINE is the current command line.\n" "$COMP_CWORD is an index into ${COMP_WORDS} of the word under the cursor.\n" "$COMP_WORDS is the current command line split into words.\n" - ); + ); } int cursor_pos = parse_int_arg("COMP_POINT", static_cast(argv[2])); const string command_line = static_cast(argv[3]);