diff --git a/kernel/register.cc b/kernel/register.cc index f522773ac..fa38cc15d 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -944,7 +944,7 @@ struct HelpPass : public Pass { size_t def_strip_count = 0; auto current_state = PUState_none; auto catch_verific = false; - auto blank_lines = 0; + auto blank_lines = 2; for (string line; std::getline(ss, line, '\n');) { // find position of first non space character std::size_t first_pos = line.find_first_not_of(" \t"); @@ -976,9 +976,9 @@ struct HelpPass : public Pass { bool IsIndent = def_strip_count < first_pos; // line looks like a signature - bool IsSignature = stripped_line.find(name) == 0; + bool IsSignature = stripped_line.find(name) == 0 && (stripped_line.length() == name.length() || stripped_line.at(name.size()) == ' '); - if (IsSignature) { + if (IsSignature && first_pos <= 4 && (blank_lines >= 2 || current_state == PUState_signature)) { if (current_state == PUState_options || current_state == PUState_optionbody) { cmd_help.codeblock(current_buffer, "none", null_source); current_buffer = ""; @@ -996,14 +996,20 @@ struct HelpPass : public Pass { } else if (IsDedent) { def_strip_count = first_pos; if (current_state == PUState_optionbody) { - current_state = PUState_options; if (!current_buffer.empty()) { cmd_help.codeblock(current_buffer, "none", null_source); current_buffer = ""; } - } - else + if (IsIndent) { + current_state = PUState_options; + cmd_help.close(1); + } else { + current_state = PUState_none; + cmd_help.close(2); + } + } else { current_state = PUState_none; + } } if (IsDefinition && !catch_verific && current_state != PUState_signature) { @@ -1036,6 +1042,11 @@ struct HelpPass : public Pass { } blank_lines = 0; } + + if (!current_buffer.empty()) { + cmd_help.codeblock(current_buffer, "none", null_source); + current_buffer = ""; + } } // write to json