diff options
Diffstat (limited to 'source/Utility/CompletionRequest.cpp')
-rw-r--r-- | source/Utility/CompletionRequest.cpp | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/source/Utility/CompletionRequest.cpp b/source/Utility/CompletionRequest.cpp index c62ec4f56ffa..3b5a4570e324 100644 --- a/source/Utility/CompletionRequest.cpp +++ b/source/Utility/CompletionRequest.cpp @@ -13,46 +13,32 @@ using namespace lldb_private; CompletionRequest::CompletionRequest(llvm::StringRef command_line, unsigned raw_cursor_pos, - int match_start_point, - int max_return_elements, CompletionResult &result) : m_command(command_line), m_raw_cursor_pos(raw_cursor_pos), - m_match_start_point(match_start_point), - m_max_return_elements(max_return_elements), m_result(result) { + m_result(result) { + assert(raw_cursor_pos <= command_line.size() && "Out of bounds cursor?"); // We parse the argument up to the cursor, so the last argument in // parsed_line is the one containing the cursor, and the cursor is after the // last character. - m_parsed_line = Args(command_line); - m_partial_parsed_line = Args(command_line.substr(0, raw_cursor_pos)); + llvm::StringRef partial_command(command_line.substr(0, raw_cursor_pos)); + m_parsed_line = Args(partial_command); - m_cursor_index = m_partial_parsed_line.GetArgumentCount() - 1; - - if (m_cursor_index == -1) + if (GetParsedLine().GetArgumentCount() == 0) { + m_cursor_index = 0; m_cursor_char_position = 0; - else + } else { + m_cursor_index = GetParsedLine().GetArgumentCount() - 1U; m_cursor_char_position = - strlen(m_partial_parsed_line.GetArgumentAtIndex(m_cursor_index)); - - const char *cursor = command_line.data() + raw_cursor_pos; - if (raw_cursor_pos > 0 && cursor[-1] == ' ') { - // We are just after a space. If we are in an argument, then we will - // continue parsing, but if we are between arguments, then we have to - // complete whatever the next element would be. We can distinguish the two - // cases because if we are in an argument (e.g. because the space is - // protected by a quote) then the space will also be in the parsed - // argument... - - const char *current_elem = - m_partial_parsed_line.GetArgumentAtIndex(m_cursor_index); - if (m_cursor_char_position == 0 || - current_elem[m_cursor_char_position - 1] != ' ') { - m_parsed_line.InsertArgumentAtIndex(m_cursor_index + 1, llvm::StringRef(), - '\0'); - m_cursor_index++; - m_cursor_char_position = 0; - } + strlen(GetParsedLine().GetArgumentAtIndex(m_cursor_index)); } + + // The cursor is after a space but the space is not part of the argument. + // Let's add an empty fake argument to the end to make sure the completion + // code. Note: The space could be part of the last argument when it's quoted. + if (partial_command.endswith(" ") && + !GetCursorArgumentPrefix().endswith(" ")) + AppendEmptyArgument(); } std::string CompletionResult::Completion::GetUniqueKey() const { @@ -66,13 +52,16 @@ std::string CompletionResult::Completion::GetUniqueKey() const { std::string result; result.append(std::to_string(m_completion.size())); result.append(m_completion); + result.append(std::to_string(static_cast<int>(m_mode))); + result.append(":"); result.append(m_descripton); return result; } void CompletionResult::AddResult(llvm::StringRef completion, - llvm::StringRef description) { - Completion r(completion, description); + llvm::StringRef description, + CompletionMode mode) { + Completion r(completion, description, mode); // Add the completion if we haven't seen the same value before. if (m_added_values.insert(r.GetUniqueKey()).second) @@ -82,11 +71,11 @@ void CompletionResult::AddResult(llvm::StringRef completion, void CompletionResult::GetMatches(StringList &matches) const { matches.Clear(); for (const Completion &completion : m_results) - matches.AppendString(completion.m_completion); + matches.AppendString(completion.GetCompletion()); } void CompletionResult::GetDescriptions(StringList &descriptions) const { descriptions.Clear(); for (const Completion &completion : m_results) - descriptions.AppendString(completion.m_descripton); + descriptions.AppendString(completion.GetDescription()); } |