9#ifndef LLDB_UTILITY_COMPLETIONREQUEST_H
10#define LLDB_UTILITY_COMPLETIONREQUEST_H
15#include "llvm/ADT/StringRef.h"
16#include "llvm/ADT/StringSet.h"
53 Completion(llvm::StringRef completion, llvm::StringRef description,
75 void AddResult(llvm::StringRef completion, llvm::StringRef description,
176 const size_t number_of_results =
m_result.GetNumberOfResults();
192 llvm::StringRef description =
"",
194 m_result.AddResult(completion, description, mode);
203 template <CompletionMode M = CompletionMode::Normal>
205 llvm::StringRef description =
"") {
210 "Shouldn't rewrite line with this function");
221 for (
const std::string &completion : completions)
236 for (std::size_t i = 0; i < completions.
GetSize(); ++i)
A command line argument class.
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
size_t m_cursor_char_position
The cursor position in the argument indexed by m_cursor_index.
CompletionResult & m_result
The result this request is supposed to fill out.
CompletionRequest(llvm::StringRef command_line, unsigned raw_cursor_pos, CompletionResult &result)
Constructs a completion request.
void SetMaxReturnElements(size_t max_return_elements)
Sets the maximum number of completions that should be returned.
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
void AddCompletions(const StringList &completions)
Adds multiple possible completion strings.
llvm::StringRef GetRawLine() const
Returns the raw user input used to create this CompletionRequest cut off at the cursor position.
void AddCompletions(const StringList &completions, const StringList &descriptions)
Adds multiple possible completion strings alongside their descriptions.
unsigned GetRawCursorPos() const
const Args & GetParsedLine() const
llvm::StringRef GetCursorArgumentPrefix() const
size_t m_max_return_elements
The maximum number of completions that should be returned.
void ShiftArguments()
Drops the first argument from the argument list.
llvm::StringRef GetRawLineWithUnusedSuffix() const
Returns the full raw user input used to create this CompletionRequest.
bool ShouldAddCompletions() const
Returns true if the maximum number of completions has not been reached yet, hence we should keep addi...
size_t m_cursor_index
The index of the argument in which the completion cursor is.
Args m_parsed_line
The command line parsed as arguments.
size_t GetMaxReturnElements() const
size_t GetCursorCharPos() const
void AppendEmptyArgument()
Adds an empty argument at the end of the argument list and moves the cursor to this new argument.
llvm::StringRef m_command
The raw command line we are supposed to complete.
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
size_t GetMaxNumberOfCompletionsToAdd() const
Returns the maximum number of completions that need to be added until reaching the maximum.
const Args::ArgEntry & GetParsedArg()
unsigned m_raw_cursor_pos
The cursor position in m_command.
size_t GetCursorIndex() const
const std::string & GetCompletion() const
std::string m_descripton
The description that should be displayed to the user alongside the completion text.
std::string m_completion
The actual text that should be completed.
const std::string & GetDescription() const
Completion(llvm::StringRef completion, llvm::StringRef description, CompletionMode mode)
CompletionMode GetMode() const
std::string GetUniqueKey() const
Generates a string that uniquely identifies this completion result.
llvm::ArrayRef< Completion > GetResults() const
std::vector< Completion > m_results
List of found completions.
void AddResult(llvm::StringRef completion, llvm::StringRef description, CompletionMode mode)
void GetDescriptions(StringList &descriptions) const
Adds all collected completion descriptions to the given list.
std::size_t GetNumberOfResults() const
void GetMatches(StringList &matches) const
Adds all collected completion matches to the given list.
llvm::StringSet m_added_values
A set of the unique keys of all found completions so far.
const char * GetStringAtIndex(size_t idx) const
A class that represents a running process on the host machine.
@ Partial
The current token has been partially completed.
@ Normal
The current token has been completed.
@ RewriteLine
The full line has been rewritten by the completion.