aboutsummaryrefslogtreecommitdiff
path: root/source/Expression/REPL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Expression/REPL.cpp')
-rw-r--r--source/Expression/REPL.cpp87
1 files changed, 48 insertions, 39 deletions
diff --git a/source/Expression/REPL.cpp b/source/Expression/REPL.cpp
index f4ed887729d8..4f81ee3e56dd 100644
--- a/source/Expression/REPL.cpp
+++ b/source/Expression/REPL.cpp
@@ -96,7 +96,7 @@ void REPL::IOHandlerActivated(IOHandler &io_handler, bool interactive) {
lldb::ProcessSP process_sp = m_target.GetProcessSP();
if (process_sp && process_sp->IsAlive())
return;
- lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+ lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFileSP());
error_sp->Printf("REPL requires a running target process.\n");
io_handler.SetIsDone(true);
}
@@ -180,8 +180,8 @@ int REPL::IOHandlerFixIndentation(IOHandler &io_handler,
}
void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
- lldb::StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+ lldb::StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
+ lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFileSP());
bool extra_line = false;
bool did_quit = false;
@@ -206,7 +206,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
// Meta command
// Strip the ':'
code.erase(0, 1);
- if (Args::StripSpaces(code)) {
+ if (!llvm::StringRef(code).trim().empty()) {
// "lldb" was followed by arguments, so just execute the command dump
// the results
@@ -398,17 +398,22 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
// Update our code on disk
if (!m_repl_source_path.empty()) {
- lldb_private::File file;
- FileSystem::Instance().Open(file, FileSpec(m_repl_source_path),
- File::eOpenOptionWrite |
- File::eOpenOptionTruncate |
- File::eOpenOptionCanCreate,
- lldb::eFilePermissionsFileDefault);
- std::string code(m_code.CopyList());
- code.append(1, '\n');
- size_t bytes_written = code.size();
- file.Write(code.c_str(), bytes_written);
- file.Close();
+ auto file = FileSystem::Instance().Open(
+ FileSpec(m_repl_source_path),
+ File::eOpenOptionWrite | File::eOpenOptionTruncate |
+ File::eOpenOptionCanCreate,
+ lldb::eFilePermissionsFileDefault);
+ if (file) {
+ std::string code(m_code.CopyList());
+ code.append(1, '\n');
+ size_t bytes_written = code.size();
+ file.get()->Write(code.c_str(), bytes_written);
+ file.get()->Close();
+ } else {
+ std::string message = llvm::toString(file.takeError());
+ error_sp->Printf("error: couldn't open %s: %s\n",
+ m_repl_source_path.c_str(), message.c_str());
+ }
// Now set the default file and line to the REPL source file
m_target.GetSourceManager().SetDefaultFileAndLine(
@@ -418,7 +423,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
.SetBaseLineNumber(m_code.GetSize() + 1);
}
if (extra_line) {
- fprintf(output_sp->GetFile().GetStream(), "\n");
+ output_sp->Printf("\n");
}
}
}
@@ -433,31 +438,30 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
}
}
-int REPL::IOHandlerComplete(IOHandler &io_handler, const char *current_line,
- const char *cursor, const char *last_char,
- int skip_first_n_matches, int max_matches,
- StringList &matches, StringList &descriptions) {
- matches.Clear();
-
- llvm::StringRef line(current_line, cursor - current_line);
-
+void REPL::IOHandlerComplete(IOHandler &io_handler,
+ CompletionRequest &request) {
// Complete an LLDB command if the first character is a colon...
- if (!line.empty() && line[0] == ':') {
+ if (request.GetRawLine().startswith(":")) {
Debugger &debugger = m_target.GetDebugger();
// auto complete LLDB commands
- const char *lldb_current_line = line.substr(1).data();
- return debugger.GetCommandInterpreter().HandleCompletion(
- lldb_current_line, cursor, last_char, skip_first_n_matches, max_matches,
- matches, descriptions);
+ llvm::StringRef new_line = request.GetRawLine().drop_front();
+ CompletionResult sub_result;
+ CompletionRequest sub_request(new_line, request.GetRawCursorPos() - 1,
+ sub_result);
+ debugger.GetCommandInterpreter().HandleCompletion(sub_request);
+ StringList matches, descriptions;
+ sub_result.GetMatches(matches);
+ sub_result.GetDescriptions(descriptions);
+ request.AddCompletions(matches, descriptions);
+ return;
}
// Strip spaces from the line and see if we had only spaces
- line = line.ltrim();
- if (line.empty()) {
+ if (request.GetRawLine().trim().empty()) {
// Only spaces on this line, so just indent
- matches.AppendString(m_indent_str);
- return 1;
+ request.AddCompletion(m_indent_str);
+ return;
}
std::string current_code;
@@ -479,12 +483,17 @@ int REPL::IOHandlerComplete(IOHandler &io_handler, const char *current_line,
}
}
- if (cursor > current_line) {
- current_code.append("\n");
- current_code.append(current_line, cursor - current_line);
- }
-
- return CompleteCode(current_code, matches);
+ current_code.append("\n");
+ current_code += request.GetRawLine();
+
+ StringList matches;
+ int result = CompleteCode(current_code, matches);
+ if (result == -2) {
+ assert(matches.GetSize() == 1);
+ request.AddCompletion(matches.GetStringAtIndex(0), "",
+ CompletionMode::RewriteLine);
+ } else
+ request.AddCompletions(matches);
}
bool QuitCommandOverrideCallback(void *baton, const char **argv) {