1
0
Fork 0

case-insensitive completion

This commit is contained in:
Jan Steemann 2014-05-14 18:43:01 +02:00
parent 8a5c2438b9
commit a02611fba1
1 changed files with 71 additions and 59 deletions

View File

@ -198,6 +198,7 @@ static char* CompletionGenerator (char const* text, int state) {
static void LinenoiseCompletionGenerator (char const* text, linenoiseCompletions * lc) {
vector<string> completions;
// locate global object or sub-object
v8::Handle<v8::Object> current = v8::Context::GetCurrent()->Global();
string path;
@ -272,21 +273,32 @@ static void LinenoiseCompletionGenerator (char const* text, linenoiseCompletions
char const* s = *str;
if (s != 0 && *s) {
string suffix = (current->Get(v)->IsFunction()) ? "()" : "";
string name = path + s + suffix;
string const suffix = (current->Get(v)->IsFunction()) ? "()" : "";
if (*prefix == '\0' || TRI_IsPrefixString(s, prefix)) {
linenoiseAddCompletion(lc, name.c_str());
string name = path + s + suffix;
completions.push_back(name);
}
}
}
}
// sort completions
size_t const n = completions.size();
std::sort(completions.begin(), completions.end(),
[](std::string const& l, std::string const& r) -> bool {
int res = strcasecmp(l.c_str(), r.c_str());
return (res < 0);
}
);
for (size_t i = 0; i < n; ++i) {
linenoiseAddCompletion(lc, completions[i].c_str());
}
lc->multiLine = 1;
TRI_FreeString(TRI_CORE_MEM_ZONE, prefix);
}
#endif