diff options
Diffstat (limited to 'lldb/include')
-rw-r--r-- | lldb/include/lldb/Interpreter/CommandAlias.h | 16 | ||||
-rw-r--r-- | lldb/include/lldb/Interpreter/CommandInterpreter.h | 11 | ||||
-rw-r--r-- | lldb/include/lldb/Interpreter/CommandObject.h | 87 | ||||
-rw-r--r-- | lldb/include/lldb/Interpreter/CommandObjectMultiword.h | 21 | ||||
-rw-r--r-- | lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h | 5 | ||||
-rw-r--r-- | lldb/include/lldb/Utility/CompletionRequest.h | 94 |
6 files changed, 123 insertions, 111 deletions
diff --git a/lldb/include/lldb/Interpreter/CommandAlias.h b/lldb/include/lldb/Interpreter/CommandAlias.h index 4c59ad814a4..44b99681ca8 100644 --- a/lldb/include/lldb/Interpreter/CommandAlias.h +++ b/lldb/include/lldb/Interpreter/CommandAlias.h @@ -40,17 +40,11 @@ public: bool WantsCompletion() override; - int HandleCompletion(Args &input, int &cursor_index, - int &cursor_char_position, int match_start_point, - int max_return_elements, bool &word_complete, - StringList &matches) override; - - int HandleArgumentCompletion(Args &input, int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, int max_return_elements, - bool &word_complete, - StringList &matches) override; + int HandleCompletion(CompletionRequest &request) override; + + int HandleArgumentCompletion( + CompletionRequest &request, + OptionElementVector &opt_element_vector) override; Options *GetOptions() override; diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 8ac5928b44a..60e67f2271f 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -312,14 +312,9 @@ public: int max_return_elements, StringList &matches); // This version just returns matches, and doesn't compute the substring. It - // is here so the Help command can call it for the first argument. - // word_complete tells whether the completions are considered a "complete" - // response (so the completer should complete the quote & put a space after - // the word. - int HandleCompletionMatches(Args &input, int &cursor_index, - int &cursor_char_position, int match_start_point, - int max_return_elements, bool &word_complete, - StringList &matches); + // is here so the Help command can call it for the first argument. It uses + // a CompletionRequest for simplicity reasons. + int HandleCompletionMatches(CompletionRequest &request); int GetCommandNamesMatchingPartialString(const char *cmd_cstr, bool include_aliases, diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index 8848d5eeaee..28bf35cd9b9 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -16,6 +16,8 @@ #include <string> #include <vector> +#include <lldb/Utility/CompletionRequest.h> + // Other libraries and framework includes // Project includes #include "lldb/Utility/Flags.h" @@ -222,44 +224,13 @@ public: void SetCommandName(llvm::StringRef name); //------------------------------------------------------------------ - /// The input array contains a parsed version of the line. The insertion - /// point is given by cursor_index (the index in input of the word containing - /// the cursor) and cursor_char_position (the position of the cursor in that - /// word.) /// This default version handles calling option argument completions and then - /// calls - /// HandleArgumentCompletion if the cursor is on an argument, not an option. - /// Don't override this method, override HandleArgumentCompletion instead - /// unless - /// you have special reasons. - /// - /// @param[in] interpreter - /// The command interpreter doing the completion. - /// - /// @param[in] input - /// The command line parsed into words - /// - /// @param[in] cursor_index - /// The index in \ainput of the word in which the cursor lies. - /// - /// @param[in] cursor_char_pos - /// The character position of the cursor in its argument word. + /// calls HandleArgumentCompletion if the cursor is on an argument, not an + /// option. Don't override this method, override HandleArgumentCompletion + /// instead unless you have special reasons. /// - /// @param[in] match_start_point - /// @param[in] match_return_elements - /// FIXME: Not yet implemented... If there is a match that is expensive - /// to compute, these are - /// here to allow you to compute the completions in batches. Start the - /// completion from \amatch_start_point, - /// and return \amatch_return_elements elements. - /// - /// @param[out] word_complete - /// \btrue if this is a complete option value (a space will be inserted - /// after the - /// completion.) \bfalse otherwise. - /// - /// @param[out] matches - /// The array of matches returned. + /// @param[in/out] request + /// The completion request that needs to be answered. /// /// FIXME: This is the wrong return value, since we also need to make a /// distinction between @@ -268,10 +239,7 @@ public: /// @return /// \btrue if we were in an option, \bfalse otherwise. //------------------------------------------------------------------ - virtual int HandleCompletion(Args &input, int &cursor_index, - int &cursor_char_position, int match_start_point, - int max_return_elements, bool &word_complete, - StringList &matches); + virtual int HandleCompletion(CompletionRequest &request); //------------------------------------------------------------------ /// The input array contains a parsed version of the line. The insertion @@ -279,36 +247,10 @@ public: /// the cursor) and cursor_char_position (the position of the cursor in that /// word.) /// We've constructed the map of options and their arguments as well if that - /// is - /// helpful for the completion. - /// - /// @param[in] interpreter - /// The command interpreter doing the completion. - /// - /// @param[in] input - /// The command line parsed into words - /// - /// @param[in] cursor_index - /// The index in \ainput of the word in which the cursor lies. - /// - /// @param[in] cursor_char_pos - /// The character position of the cursor in its argument word. - /// - /// @param[in] opt_element_vector - /// The results of the options parse of \a input. - /// - /// @param[in] match_start_point - /// @param[in] match_return_elements - /// See CommandObject::HandleCompletions for a description of how these - /// work. - /// - /// @param[out] word_complete - /// \btrue if this is a complete option value (a space will be inserted - /// after the - /// completion.) \bfalse otherwise. + /// is helpful for the completion. /// - /// @param[out] matches - /// The array of matches returned. + /// @param[in/out] request + /// The completion request that needs to be answered. /// /// FIXME: This is the wrong return value, since we also need to make a /// distinction between @@ -317,10 +259,9 @@ public: /// @return /// The number of completions. //------------------------------------------------------------------ - virtual int HandleArgumentCompletion( - Args &input, int &cursor_index, int &cursor_char_position, - OptionElementVector &opt_element_vector, int match_start_point, - int max_return_elements, bool &word_complete, StringList &matches) { + virtual int + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) { return 0; } diff --git a/lldb/include/lldb/Interpreter/CommandObjectMultiword.h b/lldb/include/lldb/Interpreter/CommandObjectMultiword.h index 358023e2318..b88e699da31 100644 --- a/lldb/include/lldb/Interpreter/CommandObjectMultiword.h +++ b/lldb/include/lldb/Interpreter/CommandObjectMultiword.h @@ -56,10 +56,7 @@ public: bool WantsRawCommandString() override { return false; } - int HandleCompletion(Args &input, int &cursor_index, - int &cursor_char_position, int match_start_point, - int max_return_elements, bool &word_complete, - StringList &matches) override; + int HandleCompletion(CompletionRequest &request) override; const char *GetRepeatCommand(Args ¤t_command_args, uint32_t index) override; @@ -121,17 +118,11 @@ public: Options *GetOptions() override; - int HandleCompletion(Args &input, int &cursor_index, - int &cursor_char_position, int match_start_point, - int max_return_elements, bool &word_complete, - StringList &matches) override; - - int HandleArgumentCompletion(Args &input, int &cursor_index, - int &cursor_char_position, - OptionElementVector &opt_element_vector, - int match_start_point, int max_return_elements, - bool &word_complete, - StringList &matches) override; + int HandleCompletion(CompletionRequest &request) override; + + int HandleArgumentCompletion( + CompletionRequest &request, + OptionElementVector &opt_element_vector) override; const char *GetRepeatCommand(Args ¤t_command_args, uint32_t index) override; diff --git a/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h b/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h index 50dbebc21b1..306547e998d 100644 --- a/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h +++ b/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h @@ -40,10 +40,7 @@ public: bool HasRegexEntries() const { return !m_entries.empty(); } - int HandleCompletion(Args &input, int &cursor_index, - int &cursor_char_position, int match_start_point, - int max_return_elements, bool &word_complete, - StringList &matches) override; + int HandleCompletion(CompletionRequest &request) override; protected: bool DoExecute(const char *command, CommandReturnObject &result) override; diff --git a/lldb/include/lldb/Utility/CompletionRequest.h b/lldb/include/lldb/Utility/CompletionRequest.h new file mode 100644 index 00000000000..13e6446f4ef --- /dev/null +++ b/lldb/include/lldb/Utility/CompletionRequest.h @@ -0,0 +1,94 @@ +//===-- CompletionRequest.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_UTILITY_COMPLETIONREQUEST_H +#define LLDB_UTILITY_COMPLETIONREQUEST_H + +#include <lldb/Utility/Args.h> +#include <lldb/Utility/StringList.h> +#include <llvm/ADT/StringRef.h> + +namespace lldb_private { + +//---------------------------------------------------------------------- +/// @class CompletionRequest CompletionRequest.h +/// "lldb/Utility/ArgCompletionRequest.h" +/// +/// Contains all information necessary to complete an incomplete command +/// for the user. Will be filled with the generated completions by the different +/// completions functions. +/// +//---------------------------------------------------------------------- +class CompletionRequest { +public: + //---------------------------------------------------------------------- + /// Constructs a completion request. + /// + /// See the respective members of this class for documentation for the + /// parameters. + // TODO: Infer the parsed_line and the cursor positions from the other + // arguments. + //---------------------------------------------------------------------- + CompletionRequest(llvm::StringRef command, unsigned raw_cursor_pos, + Args &parsed_line, int cursor_index, + int cursor_char_position, int match_start_point, + int max_return_elements, bool word_complete, + StringList &matches); + + llvm::StringRef GetRawLine() const { return m_command; } + + unsigned GetRawCursorPos() const { return m_raw_cursor_pos; } + + Args &GetParsedLine() { return m_parsed_line; } + + void SetCursorIndex(int i) { m_cursor_index = i; } + int GetCursorIndex() const { return m_cursor_index; } + + void SetCursorCharPosition(int pos) { m_cursor_char_position = pos; } + int GetCursorCharPosition() const { return m_cursor_char_position; } + + int GetMatchStartPoint() const { return m_match_start_point; } + + int GetMaxReturnElements() const { return m_max_return_elements; } + + bool GetWordComplete() { return m_word_complete; } + + void SetWordComplete(bool v) { m_word_complete = v; } + + /// The array of matches returned. + StringList &GetMatches() { return *m_matches; } + +private: + /// The raw command line we are supposed to complete. + llvm::StringRef m_command; + /// The cursor position in m_command. + unsigned m_raw_cursor_pos; + /// The command line parsed as arguments. + Args m_parsed_line; + /// The index of the argument in which the completion cursor is. + int m_cursor_index; + /// The cursor position in the argument indexed by m_cursor_index. + int m_cursor_char_position; + /// If there is a match that is expensive + /// to compute, these are here to allow you to compute the completions in + /// batches. Start the completion from \amatch_start_point, and return + /// \amatch_return_elements elements. + // FIXME: These two values are not implemented. + int m_match_start_point; + int m_max_return_elements; + /// \btrue if this is a complete option value (a space will be inserted + /// after the completion.) \bfalse otherwise. + bool m_word_complete; + // We don't own the list. + StringList *m_matches; +}; + +} // namespace lldb_private + +#endif // LLDB_UTILITY_COMPLETIONREQUEST_H |