diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.h b/lldb/source/Commands/CommandObjectDWIMPrint.h --- a/lldb/source/Commands/CommandObjectDWIMPrint.h +++ b/lldb/source/Commands/CommandObjectDWIMPrint.h @@ -37,6 +37,12 @@ Options *GetOptions() override; + bool WantsCompletion() override { return true; } + + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override; + private: bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override; diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp --- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp +++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp @@ -32,6 +32,10 @@ "Print a variable or expression.", "dwim-print [ | ]", eCommandProcessMustBePaused | eCommandTryTargetAPILock) { + + CommandArgumentData var_name_arg(eArgTypeVarName, eArgRepeatPlain); + m_arguments.push_back({var_name_arg}); + m_option_group.Append(&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, @@ -44,6 +48,13 @@ Options *CommandObjectDWIMPrint::GetOptions() { return &m_option_group; } +void CommandObjectDWIMPrint::HandleArgumentCompletion( + CompletionRequest &request, OptionElementVector &opt_element_vector) { + CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion, + request, nullptr); +} + bool CommandObjectDWIMPrint::DoExecute(StringRef command, CommandReturnObject &result) { m_option_group.NotifyOptionParsingStarting(&m_exe_ctx); diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py --- a/lldb/test/API/functionalities/completion/TestCompletion.py +++ b/lldb/test/API/functionalities/completion/TestCompletion.py @@ -36,42 +36,55 @@ def test_frame_variable(self): self.build() - self.main_source = "main.cpp" - self.main_source_spec = lldb.SBFileSpec(self.main_source) - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, - '// Break here', self.main_source_spec) + _, process, _, _ = lldbutil.run_to_source_breakpoint( + self, '// Break here', lldb.SBFileSpec("main.cpp")) self.assertState(process.GetState(), lldb.eStateStopped) # Since CommandInterpreter has been corrected to update the current execution # context at the beginning of HandleCompletion, we're here explicitly testing # the scenario where "frame var" is completed without any preceding commands. + self.do_test_variable_completion('frame variable') - self.complete_from_to('frame variable fo', - 'frame variable fooo') - self.complete_from_to('frame variable fooo.', - 'frame variable fooo.') - self.complete_from_to('frame variable fooo.dd', - 'frame variable fooo.dd') - - self.complete_from_to('frame variable ptr_fooo->', - 'frame variable ptr_fooo->') - self.complete_from_to('frame variable ptr_fooo->dd', - 'frame variable ptr_fooo->dd') - - self.complete_from_to('frame variable cont', - 'frame variable container') - self.complete_from_to('frame variable container.', - 'frame variable container.MemberVar') - self.complete_from_to('frame variable container.Mem', - 'frame variable container.MemberVar') - - self.complete_from_to('frame variable ptr_cont', - 'frame variable ptr_container') - self.complete_from_to('frame variable ptr_container->', - 'frame variable ptr_container->MemberVar') - self.complete_from_to('frame variable ptr_container->Mem', - 'frame variable ptr_container->MemberVar') + def test_dwim_print(self): + self.build() + + _, process, _, _ = lldbutil.run_to_source_breakpoint( + self, '// Break here', lldb.SBFileSpec("main.cpp")) + self.assertState(process.GetState(), lldb.eStateStopped) + + # Since CommandInterpreter has been corrected to update the current execution + # context at the beginning of HandleCompletion, we're here explicitly testing + # the scenario where "frame var" is completed without any preceding commands. + self.do_test_variable_completion('dwim-print') + + + def do_test_variable_completion(self, command): + self.complete_from_to(f'{command} fo', + f'{command} fooo') + self.complete_from_to(f'{command} fooo.', + f'{command} fooo.') + self.complete_from_to(f'{command} fooo.dd', + f'{command} fooo.dd') + + self.complete_from_to(f'{command} ptr_fooo->', + f'{command} ptr_fooo->') + self.complete_from_to(f'{command} ptr_fooo->dd', + f'{command} ptr_fooo->dd') + + self.complete_from_to(f'{command} cont', + f'{command} container') + self.complete_from_to(f'{command} container.', + f'{command} container.MemberVar') + self.complete_from_to(f'{command} container.Mem', + f'{command} container.MemberVar') + + self.complete_from_to(f'{command} ptr_cont', + f'{command} ptr_container') + self.complete_from_to(f'{command} ptr_container->', + f'{command} ptr_container->MemberVar') + self.complete_from_to(f'{command} ptr_container->Mem', + f'{command} ptr_container->MemberVar') def test_process_attach_dash_dash_con(self): """Test that 'process attach --con' completes to 'process attach --continue '."""