aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Interpreter/CommandInterpreter.cpp
diff options
context:
space:
mode:
authorShu Anzai <shu.anzai@gmail.com>2020-08-12 12:54:28 +0200
committerRaphael Isemann <teemperor@gmail.com>2020-08-14 11:37:49 +0200
commitde9e85026fcb7c3e992f12a86594fd50bb101ad3 (patch)
tree0e515798498b74700ce0af39e6f2403748d44505 /lldb/source/Interpreter/CommandInterpreter.cpp
parent9a47bcae7c564bb83de659be601509241f31cc11 (diff)
downloadllvm-de9e85026fcb7c3e992f12a86594fd50bb101ad3.zip
llvm-de9e85026fcb7c3e992f12a86594fd50bb101ad3.tar.gz
llvm-de9e85026fcb7c3e992f12a86594fd50bb101ad3.tar.bz2
[lldb] Display autosuggestion part in gray if there is one possible suggestion
This is relanding D81001. The patch originally failed as on newer editline versions it seems CC_REFRESH will move the cursor to the start of the line via \r and then back to the original position. On older editline versions like the one used by default on macOS, CC_REFRESH doesn't move the cursor at all. As the patch changed the way we handle tab completion (previously we did REDISPLAY but now we're doing CC_REFRESH), this caused a few completion tests to receive this unexpected cursor movement in the output stream. This patch updates those tests to also accept output that contains the specific cursor movement commands (\r and then \x1b[XC). lldbpexpect.py received an utility method for generating the cursor movement escape sequence. Original summary: I implemented autosuggestion if there is one possible suggestion. I set the keybinds for every character. When a character is typed, Editline::TypedCharacter is called. Then, autosuggestion part is displayed in gray, and you can actually input by typing C-k. Editline::Autosuggest is a function for finding completion, and it is like Editline::TabCommand now, but I will add more features to it. Testing does not work well in my environment, so I can't confirm that it goes well, sorry. I am dealing with it now. Reviewed By: teemperor, JDevlieghere, #lldb Differential Revision: https://reviews.llvm.org/D81001
Diffstat (limited to 'lldb/source/Interpreter/CommandInterpreter.cpp')
-rw-r--r--lldb/source/Interpreter/CommandInterpreter.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 4786e46..ec82efb 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1878,6 +1878,19 @@ void CommandInterpreter::HandleCompletion(CompletionRequest &request) {
HandleCompletionMatches(request);
}
+llvm::Optional<std::string>
+CommandInterpreter::GetAutoSuggestionForCommand(llvm::StringRef line) {
+ if (line.empty())
+ return llvm::None;
+ const size_t s = m_command_history.GetSize();
+ for (int i = s - 1; i >= 0; --i) {
+ llvm::StringRef entry = m_command_history.GetStringAtIndex(i);
+ if (entry.consume_front(line))
+ return entry.str();
+ }
+ return llvm::None;
+}
+
CommandInterpreter::~CommandInterpreter() {}
void CommandInterpreter::UpdatePrompt(llvm::StringRef new_prompt) {