aboutsummaryrefslogtreecommitdiff
path: root/source/Host/common/Editline.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Host/common/Editline.cpp')
-rw-r--r--source/Host/common/Editline.cpp58
1 files changed, 43 insertions, 15 deletions
diff --git a/source/Host/common/Editline.cpp b/source/Host/common/Editline.cpp
index 329c0c1f3b70..f7ba4b5822ff 100644
--- a/source/Host/common/Editline.cpp
+++ b/source/Host/common/Editline.cpp
@@ -13,6 +13,7 @@
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/Editline.h"
+#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/LLDBAssert.h"
@@ -172,7 +173,8 @@ private:
const char *GetHistoryFilePath() {
if (m_path.empty() && m_history && !m_prefix.empty()) {
- FileSpec parent_path{"~/.lldb", true};
+ FileSpec parent_path("~/.lldb");
+ FileSystem::Instance().Resolve(parent_path);
char history_path[PATH_MAX];
if (!llvm::sys::fs::create_directory(parent_path.GetPath())) {
snprintf(history_path, sizeof(history_path), "~/.lldb/%s-history",
@@ -181,7 +183,9 @@ private:
snprintf(history_path, sizeof(history_path), "~/%s-widehistory",
m_prefix.c_str());
}
- m_path = FileSpec(history_path, true).GetPath();
+ auto file_spec = FileSpec(history_path);
+ FileSystem::Instance().Resolve(file_spec);
+ m_path = file_spec.GetPath();
}
if (m_path.empty())
return NULL;
@@ -426,7 +430,7 @@ unsigned char Editline::RecallHistory(bool earlier) {
// Treat moving from the "live" entry differently
if (!m_in_history) {
- if (earlier == false)
+ if (!earlier)
return CC_ERROR; // Can't go newer than the "live" entry
if (history_w(pHistory, &history_event, H_FIRST) == -1)
return CC_ERROR;
@@ -439,7 +443,7 @@ unsigned char Editline::RecallHistory(bool earlier) {
m_live_history_lines = m_input_lines;
m_in_history = true;
} else {
- if (history_w(pHistory, &history_event, earlier ? H_NEXT : H_PREV) == -1) {
+ if (history_w(pHistory, &history_event, earlier ? H_PREV : H_NEXT) == -1) {
// Can't move earlier than the earliest entry
if (earlier)
return CC_ERROR;
@@ -526,7 +530,7 @@ int Editline::GetCharacter(EditLineGetCharType *c) {
break;
case lldb::eConnectionStatusInterrupted:
- lldbassert(0 && "Interrupts should have been handled above.");
+ llvm_unreachable("Interrupts should have been handled above.");
case lldb::eConnectionStatusError: // Check GetError() for details
case lldb::eConnectionStatusTimedOut: // Request timed out
@@ -853,19 +857,45 @@ unsigned char Editline::BufferEndCommand(int ch) {
return CC_NEWLINE;
}
+//------------------------------------------------------------------------------
+/// Prints completions and their descriptions to the given file. Only the
+/// completions in the interval [start, end) are printed.
+//------------------------------------------------------------------------------
+static void PrintCompletion(FILE *output_file, size_t start, size_t end,
+ StringList &completions, StringList &descriptions) {
+ // This is an 'int' because of printf.
+ int max_len = 0;
+
+ for (size_t i = start; i < end; i++) {
+ const char *completion_str = completions.GetStringAtIndex(i);
+ max_len = std::max((int)strlen(completion_str), max_len);
+ }
+
+ for (size_t i = start; i < end; i++) {
+ const char *completion_str = completions.GetStringAtIndex(i);
+ const char *description_str = descriptions.GetStringAtIndex(i);
+
+ fprintf(output_file, "\n\t%-*s", max_len, completion_str);
+
+ // Print the description if we got one.
+ if (strlen(description_str))
+ fprintf(output_file, " -- %s", description_str);
+ }
+}
+
unsigned char Editline::TabCommand(int ch) {
if (m_completion_callback == nullptr)
return CC_ERROR;
const LineInfo *line_info = el_line(m_editline);
- StringList completions;
+ StringList completions, descriptions;
int page_size = 40;
const int num_completions = m_completion_callback(
line_info->buffer, line_info->cursor, line_info->lastchar,
0, // Don't skip any matches (start at match zero)
-1, // Get all the matches
- completions, m_completion_callback_baton);
+ completions, descriptions, m_completion_callback_baton);
if (num_completions == 0)
return CC_ERROR;
@@ -893,10 +923,8 @@ unsigned char Editline::TabCommand(int ch) {
int num_elements = num_completions + 1;
fprintf(m_output_file, "\n" ANSI_CLEAR_BELOW "Available completions:");
if (num_completions < page_size) {
- for (int i = 1; i < num_elements; i++) {
- completion_str = completions.GetStringAtIndex(i);
- fprintf(m_output_file, "\n\t%s", completion_str);
- }
+ PrintCompletion(m_output_file, 1, num_elements, completions,
+ descriptions);
fprintf(m_output_file, "\n");
} else {
int cur_pos = 1;
@@ -906,10 +934,10 @@ unsigned char Editline::TabCommand(int ch) {
int endpoint = cur_pos + page_size;
if (endpoint > num_elements)
endpoint = num_elements;
- for (; cur_pos < endpoint; cur_pos++) {
- completion_str = completions.GetStringAtIndex(cur_pos);
- fprintf(m_output_file, "\n\t%s", completion_str);
- }
+
+ PrintCompletion(m_output_file, cur_pos, endpoint, completions,
+ descriptions);
+ cur_pos = endpoint;
if (cur_pos >= num_elements) {
fprintf(m_output_file, "\n");