This revision was automatically updated to reflect the committed changes. Closed by commit rG24bc8afd4baf: [lldb] tab completion for `target modules search-paths insert` (authored by MrHate, committed by teemperor). Herald added a subscriber: lldb-commits.
Changed prior to commit: https://reviews.llvm.org/D83309?vs=276069&id=284627#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D83309/new/ https://reviews.llvm.org/D83309 Files: lldb/source/Commands/CommandObjectTarget.cpp lldb/test/API/functionalities/completion/TestCompletion.py Index: lldb/test/API/functionalities/completion/TestCompletion.py =================================================================== --- lldb/test/API/functionalities/completion/TestCompletion.py +++ lldb/test/API/functionalities/completion/TestCompletion.py @@ -368,6 +368,18 @@ self.complete_from_to('target modules load a.ou', ['a.out']) + def test_target_modules_search_paths_insert(self): + # Completion won't work without a valid target. + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") + self.build() + target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) + self.assertTrue(target, VALID_TARGET) + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") + self.runCmd("target modules search-paths add a b") + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert 0") + # Completion only works for the first arg. + self.complete_from_to("target modules search-paths insert 0 ", "target modules search-paths insert 0 ") + def test_target_create_dash_co(self): """Test that 'target create --co' completes to 'target variable --core '.""" self.complete_from_to('target create --co', 'target create --core ') Index: lldb/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/source/Commands/CommandObjectTarget.cpp +++ lldb/source/Commands/CommandObjectTarget.cpp @@ -1157,6 +1157,25 @@ ~CommandObjectTargetModulesSearchPathsInsert() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + if (!m_exe_ctx.HasTargetScope() || request.GetCursorIndex() != 0) + return; + + Target *target = m_exe_ctx.GetTargetPtr(); + const PathMappingList &list = target->GetImageSearchPathList(); + const size_t num = list.GetSize(); + ConstString old_path, new_path; + for (size_t i = 0; i < num; ++i) { + if (!list.GetPathsAtIndex(i, old_path, new_path)) + break; + StreamString strm; + strm << old_path << " -> " << new_path; + request.TryCompleteCurrentArg(std::to_string(i), strm.GetString()); + } + } + protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget();
Index: lldb/test/API/functionalities/completion/TestCompletion.py =================================================================== --- lldb/test/API/functionalities/completion/TestCompletion.py +++ lldb/test/API/functionalities/completion/TestCompletion.py @@ -368,6 +368,18 @@ self.complete_from_to('target modules load a.ou', ['a.out']) + def test_target_modules_search_paths_insert(self): + # Completion won't work without a valid target. + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") + self.build() + target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) + self.assertTrue(target, VALID_TARGET) + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") + self.runCmd("target modules search-paths add a b") + self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert 0") + # Completion only works for the first arg. + self.complete_from_to("target modules search-paths insert 0 ", "target modules search-paths insert 0 ") + def test_target_create_dash_co(self): """Test that 'target create --co' completes to 'target variable --core '.""" self.complete_from_to('target create --co', 'target create --core ') Index: lldb/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/source/Commands/CommandObjectTarget.cpp +++ lldb/source/Commands/CommandObjectTarget.cpp @@ -1157,6 +1157,25 @@ ~CommandObjectTargetModulesSearchPathsInsert() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + if (!m_exe_ctx.HasTargetScope() || request.GetCursorIndex() != 0) + return; + + Target *target = m_exe_ctx.GetTargetPtr(); + const PathMappingList &list = target->GetImageSearchPathList(); + const size_t num = list.GetSize(); + ConstString old_path, new_path; + for (size_t i = 0; i < num; ++i) { + if (!list.GetPathsAtIndex(i, old_path, new_path)) + break; + StreamString strm; + strm << old_path << " -> " << new_path; + request.TryCompleteCurrentArg(std::to_string(i), strm.GetString()); + } + } + protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget();
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits