Skip to content

Commit

Permalink
Merge remote-tracking branch 'lenormf/fix-4367'
Browse files Browse the repository at this point in the history
  • Loading branch information
mawww committed Nov 7, 2021
2 parents 960e7c7 + 6cadffa commit da150a8
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 129 deletions.
14 changes: 13 additions & 1 deletion src/commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,19 @@ const CommandDesc add_highlighter_cmd = {
HighlighterRegistry& registry = HighlighterRegistry::instance();
auto it = registry.find(params[1]);
if (it != registry.end())
return format("{}:\n{}", params[1], indent(it->value.docstring));
{
auto docstring = it->value.description->docstring;
auto desc_params = generate_switches_doc(it->value.description->params.switches);

if (desc_params.empty())
return format("{}:\n{}", params[1], indent(docstring));
else
{
auto desc_indent = Vector<String>{docstring, "Switches:", indent(desc_params)}
| transform([](auto& s) { return indent(s); });
return format("{}:\n{}", params[1], join(desc_indent, "\n"));
}
}
}
return "";
},
Expand Down
13 changes: 10 additions & 3 deletions src/highlighter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "array_view.hh"
#include "string.hh"
#include "utils.hh"
#include "parameters_parser.hh"

#include <memory>

Expand Down Expand Up @@ -86,13 +87,19 @@ private:
using HighlighterParameters = ConstArrayView<String>;
using HighlighterFactory = std::unique_ptr<Highlighter> (*)(HighlighterParameters params, Highlighter* parent);

struct HighlighterFactoryAndDocstring
struct HighlighterDesc
{
const char* docstring;
ParameterDesc params;
};

struct HighlighterFactoryAndDescription
{
HighlighterFactory factory;
String docstring;
const HighlighterDesc* description;
};

struct HighlighterRegistry : HashMap<String, HighlighterFactoryAndDocstring, MemoryDomain::Highlight>,
struct HighlighterRegistry : HashMap<String, HighlighterFactoryAndDescription, MemoryDomain::Highlight>,
Singleton<HighlighterRegistry>
{};

Expand Down
Loading

0 comments on commit da150a8

Please sign in to comment.