teemperor created this revision. teemperor added a reviewer: LLDB. Herald added subscribers: lldb-commits, JDevlieghere. Herald added a project: LLDB.
Right now our argument completions are rather cryptic for command options as they only list the letters: (lldb) breakpoint set - Available completions: -G -C -c -d -i -o -q -t -x [...] With the new completion API we can easily extend this with the flag description so that it looks like this now: (lldb) breakpoint set - Available completions: -G -- The breakpoint will auto-continue after running its commands. -C -- A command to run when the breakpoint is hit, can be provided more than once, the commands will get run in order left to right. -c -- The breakpoint stops only if this condition expression evaluates to true. -d -- Disable the breakpoint. -i -- Set the number of times this breakpoint is skipped before stopping. -o -- The breakpoint is deleted the first time it stop causes a stop. -q -- The breakpoint stops only for threads in the queue whose name is given by this argument. -t -- The breakpoint stops only for the thread whose TID matches this argument. -x -- The breakpoint stops only for the thread whose index matches this argument. The same happens with --long-options now. Repository: rLLDB LLDB https://reviews.llvm.org/D67063 Files: lldb/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py lldb/source/Interpreter/Options.cpp Index: lldb/source/Interpreter/Options.cpp =================================================================== --- lldb/source/Interpreter/Options.cpp +++ lldb/source/Interpreter/Options.cpp @@ -672,7 +672,7 @@ if (!def.short_option) continue; opt_str[1] = def.short_option; - request.AddCompletion(opt_str); + request.AddCompletion(opt_str, def.usage_text); } return true; @@ -684,7 +684,7 @@ full_name.erase(full_name.begin() + 2, full_name.end()); full_name.append(def.long_option); - request.AddCompletion(full_name); + request.AddCompletion(full_name, def.usage_text); } return true; } else if (opt_defs_index != OptionArgElement::eUnrecognizedArg) { @@ -692,9 +692,10 @@ // anyway (getopt_long_only is happy with shortest unique string, but // it's still a nice thing to do.) Otherwise return The string so the // upper level code will know this is a full match and add the " ". - llvm::StringRef long_option = opt_defs[opt_defs_index].long_option; + const OptionDefinition &opt = opt_defs[opt_defs_index]; + llvm::StringRef long_option = opt.long_option; if (cur_opt_str.startswith("--") && cur_opt_str != long_option) { - request.AddCompletion("--" + long_option.str()); + request.AddCompletion("--" + long_option.str(), opt.usage_text); return true; } else request.AddCompletion(request.GetCursorArgument()); @@ -710,7 +711,7 @@ for (auto &def : opt_defs) { llvm::StringRef long_option(def.long_option); if (long_option.startswith(cur_opt_str)) - request.AddCompletion("--" + long_option.str()); + request.AddCompletion("--" + long_option.str(), def.usage_text); } } return true; Index: lldb/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py =================================================================== --- lldb/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py +++ lldb/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py @@ -375,6 +375,24 @@ self.check_completion_with_desc("comman", []) self.check_completion_with_desc("non-existent-command", []) + def test_completion_description_command_options(self): + """Test descriptions of command options""" + # short options + self.check_completion_with_desc("breakpoint set -", [ + ["-h", "Set the breakpoint on exception catcH."], + ["-w", "Set the breakpoint on exception throW."] + ]) + + # long options. + self.check_completion_with_desc("breakpoint set --", [ + ["--on-catch", "Set the breakpoint on exception catcH."], + ["--on-throw", "Set the breakpoint on exception throW."] + ]) + + # Unknown long option. + self.check_completion_with_desc("breakpoint set --Z", [ + ]) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489") def test_symbol_name(self): self.build()
Index: lldb/source/Interpreter/Options.cpp =================================================================== --- lldb/source/Interpreter/Options.cpp +++ lldb/source/Interpreter/Options.cpp @@ -672,7 +672,7 @@ if (!def.short_option) continue; opt_str[1] = def.short_option; - request.AddCompletion(opt_str); + request.AddCompletion(opt_str, def.usage_text); } return true; @@ -684,7 +684,7 @@ full_name.erase(full_name.begin() + 2, full_name.end()); full_name.append(def.long_option); - request.AddCompletion(full_name); + request.AddCompletion(full_name, def.usage_text); } return true; } else if (opt_defs_index != OptionArgElement::eUnrecognizedArg) { @@ -692,9 +692,10 @@ // anyway (getopt_long_only is happy with shortest unique string, but // it's still a nice thing to do.) Otherwise return The string so the // upper level code will know this is a full match and add the " ". - llvm::StringRef long_option = opt_defs[opt_defs_index].long_option; + const OptionDefinition &opt = opt_defs[opt_defs_index]; + llvm::StringRef long_option = opt.long_option; if (cur_opt_str.startswith("--") && cur_opt_str != long_option) { - request.AddCompletion("--" + long_option.str()); + request.AddCompletion("--" + long_option.str(), opt.usage_text); return true; } else request.AddCompletion(request.GetCursorArgument()); @@ -710,7 +711,7 @@ for (auto &def : opt_defs) { llvm::StringRef long_option(def.long_option); if (long_option.startswith(cur_opt_str)) - request.AddCompletion("--" + long_option.str()); + request.AddCompletion("--" + long_option.str(), def.usage_text); } } return true; Index: lldb/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py =================================================================== --- lldb/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py +++ lldb/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py @@ -375,6 +375,24 @@ self.check_completion_with_desc("comman", []) self.check_completion_with_desc("non-existent-command", []) + def test_completion_description_command_options(self): + """Test descriptions of command options""" + # short options + self.check_completion_with_desc("breakpoint set -", [ + ["-h", "Set the breakpoint on exception catcH."], + ["-w", "Set the breakpoint on exception throW."] + ]) + + # long options. + self.check_completion_with_desc("breakpoint set --", [ + ["--on-catch", "Set the breakpoint on exception catcH."], + ["--on-throw", "Set the breakpoint on exception throW."] + ]) + + # Unknown long option. + self.check_completion_with_desc("breakpoint set --Z", [ + ]) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489") def test_symbol_name(self): self.build()
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits