QOL improvements to docsearch: alphabetize, filter out unittests
This commit is contained in:
@@ -577,24 +577,26 @@ void SourceDB::register_lua_builtins() {
|
||||
}
|
||||
|
||||
bool SourceDB::search_docs(const eng::string &substring, std::ostream &ostream) {
|
||||
bool found_anything = false;
|
||||
eng::map<eng::string, eng::string> results;
|
||||
|
||||
// Search the built-in functions.
|
||||
for (const LuaFunctionReg *reg = LuaFunctionReg::All; reg != nullptr; reg=reg->next()) {
|
||||
eng::string proto = get_reg_prototype(reg);
|
||||
if (reg->get_sandbox()) continue;
|
||||
if (sv::has_prefix(reg->get_name(), "unittests_")) continue;
|
||||
if (sv::contains_substring_utf8(proto, substring) ||
|
||||
sv::contains_substring_utf8(reg->get_docs(), substring)) {
|
||||
ostream << proto;
|
||||
std::ostringstream oss;
|
||||
oss << proto;
|
||||
util::StringVec docs = util::split_docstring(reg->get_docs());
|
||||
for (const eng::string &line : docs) {
|
||||
if (sv::contains_substring_utf8(line, substring)) {
|
||||
ostream << " -- " << sv::trim(line);
|
||||
oss << " -- " << sv::trim(line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ostream << std::endl;
|
||||
found_anything = true;
|
||||
oss << std::endl;
|
||||
results[get_reg_fullname(reg->get_name())] = oss.str();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,17 +608,20 @@ bool SourceDB::search_docs(const eng::string &substring, std::ostream &ostream)
|
||||
util::StringVec lines = util::split_lines(code);
|
||||
int comment_lines = 0;
|
||||
for (int i = 0; i < int(lines.size()); i++) {
|
||||
if (sv::is_lua_function_prototype(lines[i])) {
|
||||
std::string_view fullname = sv::lua_function_proto_name(lines[i]);
|
||||
if (sv::has_prefix(fullname, "unittests.")) continue;
|
||||
if (!fullname.empty()) {
|
||||
if (lines_contain_substring(lines, i - comment_lines, i+1, substring)) {
|
||||
ostream << lines[i];
|
||||
eng::ostringstream oss;
|
||||
oss << lines[i];
|
||||
for (int j = i - comment_lines; j < i; j++) {
|
||||
if (sv::contains_substring_utf8(lines[j], substring)) {
|
||||
ostream << " " << sv::trim(lines[j]);
|
||||
oss << " " << sv::trim(lines[j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ostream << std::endl;
|
||||
found_anything = true;
|
||||
oss << std::endl;
|
||||
results[eng::string(fullname)] = oss.str();
|
||||
}
|
||||
comment_lines = 0;
|
||||
} else if (sv::is_lua_comment(lines[i])) {
|
||||
@@ -627,7 +632,10 @@ bool SourceDB::search_docs(const eng::string &substring, std::ostream &ostream)
|
||||
}
|
||||
}
|
||||
|
||||
return found_anything;
|
||||
for (const auto &pair : results) {
|
||||
ostream << pair.second;
|
||||
}
|
||||
return !results.empty();
|
||||
}
|
||||
|
||||
bool SourceDB::function_docs(const LuaCoreStack &LS, LuaSlot fn, std::ostream &ostream) {
|
||||
|
||||
Reference in New Issue
Block a user