diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-08-15 13:14:10 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-08-15 13:14:10 +0000 |
commit | 2fc20f652cd848abdbfc40b6ae7fc0b0b403ea7d (patch) | |
tree | 44d036fe01586ba334cff331edceca798c93799c /lldb/source/Core/IOHandler.cpp | |
parent | dc23c832f4f7e5ae8204acfe800bdb611525c8bd (diff) | |
download | bcm5719-llvm-2fc20f652cd848abdbfc40b6ae7fc0b0b403ea7d.tar.gz bcm5719-llvm-2fc20f652cd848abdbfc40b6ae7fc0b0b403ea7d.zip |
[lldb][NFC] Refactor remaining completion logic to use CompletionRequests
This patch moves the remaining completion functions from the
old completion API (that used several variables) to just
passing a single CompletionRequest.
This is for the most part a simple change as we just replace
the old arguments with a single CompletionRequest argument.
There are a few places where I had to create new CompletionRequests
in the called functions as CompletionRequests itself are immutable
and don't expose their internal match list anymore. This means that
if a function wanted to change the CompletionRequest or directly
access the result list, we need to work around this by creating
a new CompletionRequest and a temporary match/description list.
Preparation work for rdar://53769355
llvm-svn: 369000
Diffstat (limited to 'lldb/source/Core/IOHandler.cpp')
-rw-r--r-- | lldb/source/Core/IOHandler.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 6dcd8e32fd4..1a35f300e52 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -170,17 +170,15 @@ IOHandlerConfirm::IOHandlerConfirm(Debugger &debugger, llvm::StringRef prompt, IOHandlerConfirm::~IOHandlerConfirm() = default; -int IOHandlerConfirm::IOHandlerComplete( - IOHandler &io_handler, const char *current_line, const char *cursor, - const char *last_char, StringList &matches, StringList &descriptions) { - if (current_line == cursor) { - if (m_default_response) { - matches.AppendString("y"); - } else { - matches.AppendString("n"); - } +int IOHandlerConfirm::IOHandlerComplete(IOHandler &io_handler, + CompletionRequest &request) { + if (request.GetRawCursorPos() == 0) { + if (m_default_response) + request.AddCompletion("y"); + else + request.AddCompletion("n"); } - return matches.GetSize(); + return request.GetNumberOfMatches(); } void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler, @@ -218,39 +216,43 @@ void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler, } } -int IOHandlerDelegate::IOHandlerComplete( - IOHandler &io_handler, const char *current_line, const char *cursor, - const char *last_char, StringList &matches, StringList &descriptions) { +int IOHandlerDelegate::IOHandlerComplete(IOHandler &io_handler, + CompletionRequest &request) { switch (m_completion) { case Completion::None: break; case Completion::LLDBCommand: return io_handler.GetDebugger().GetCommandInterpreter().HandleCompletion( - current_line, cursor, last_char, matches, descriptions); + request); case Completion::Expression: { CompletionResult result; - CompletionRequest request(current_line, cursor - current_line, result); + CompletionRequest subrequest(request.GetRawLine(), + request.GetRawCursorPos(), result); CommandCompletions::InvokeCommonCompletionCallbacks( io_handler.GetDebugger().GetCommandInterpreter(), - CommandCompletions::eVariablePathCompletion, request, nullptr); + CommandCompletions::eVariablePathCompletion, subrequest, nullptr); + StringList matches; + StringList descriptions; result.GetMatches(matches); result.GetDescriptions(descriptions); - size_t num_matches = request.GetNumberOfMatches(); + size_t num_matches = subrequest.GetNumberOfMatches(); if (num_matches > 0) { std::string common_prefix = matches.LongestCommonPrefix(); - const size_t partial_name_len = request.GetCursorArgumentPrefix().size(); + const size_t partial_name_len = + subrequest.GetCursorArgumentPrefix().size(); // If we matched a unique single command, add a space... Only do this if // the completer told us this was a complete word, however... - if (num_matches == 1 && request.GetWordComplete()) { + if (num_matches == 1 && subrequest.GetWordComplete()) { common_prefix.push_back(' '); } common_prefix.erase(0, partial_name_len); - matches.InsertStringAtIndex(0, std::move(common_prefix)); + request.AddCompletion(common_prefix); } - return num_matches; + request.AddCompletions(matches, descriptions); + return request.GetNumberOfMatches(); } break; } @@ -443,14 +445,12 @@ int IOHandlerEditline::FixIndentationCallback(Editline *editline, *editline_reader, lines, cursor_position); } -int IOHandlerEditline::AutoCompleteCallback( - const char *current_line, const char *cursor, const char *last_char, - StringList &matches, StringList &descriptions, void *baton) { +int IOHandlerEditline::AutoCompleteCallback(CompletionRequest &request, + void *baton) { IOHandlerEditline *editline_reader = (IOHandlerEditline *)baton; if (editline_reader) - return editline_reader->m_delegate.IOHandlerComplete( - *editline_reader, current_line, cursor, last_char, matches, - descriptions); + return editline_reader->m_delegate.IOHandlerComplete(*editline_reader, + request); return 0; } #endif |