2011-11-30 02:37:20 +04:00
|
|
|
#include "highlighter_registry.hh"
|
|
|
|
|
|
|
|
#include "exception.hh"
|
|
|
|
#include "window.hh"
|
2012-01-15 17:46:45 +04:00
|
|
|
#include "highlighters.hh"
|
2011-11-30 02:37:20 +04:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct factory_not_found : public runtime_error
|
|
|
|
{
|
2012-04-14 05:17:09 +04:00
|
|
|
factory_not_found(const String& name)
|
2011-12-02 23:00:01 +04:00
|
|
|
: runtime_error("highlighter factory not found '" + name + "'") {}
|
2011-11-30 02:37:20 +04:00
|
|
|
};
|
|
|
|
|
2012-04-14 05:17:09 +04:00
|
|
|
void HighlighterRegistry::register_factory(const String& name,
|
2011-11-30 02:37:20 +04:00
|
|
|
const HighlighterFactory& factory)
|
|
|
|
{
|
2011-12-02 18:22:51 +04:00
|
|
|
assert(not m_factories.contains(name));
|
|
|
|
m_factories.append(std::make_pair(name, factory));
|
2011-11-30 02:37:20 +04:00
|
|
|
}
|
|
|
|
|
2012-01-15 17:46:45 +04:00
|
|
|
void HighlighterRegistry::add_highlighter_to_group(Window& window,
|
|
|
|
HighlighterGroup& group,
|
2012-04-14 05:17:09 +04:00
|
|
|
const String& name,
|
2012-01-15 17:46:45 +04:00
|
|
|
const HighlighterParameters& parameters)
|
|
|
|
{
|
|
|
|
auto it = m_factories.find(name);
|
|
|
|
if (it == m_factories.end())
|
|
|
|
throw factory_not_found(name);
|
|
|
|
|
2012-01-20 00:37:29 +04:00
|
|
|
group.append(it->second(window, parameters));
|
2012-01-15 17:46:45 +04:00
|
|
|
}
|
|
|
|
|
2012-04-14 05:17:09 +04:00
|
|
|
CandidateList HighlighterRegistry::complete_highlighter(const String& prefix,
|
2012-10-11 02:41:48 +04:00
|
|
|
ByteCount cursor_pos)
|
2011-11-30 02:37:20 +04:00
|
|
|
{
|
2012-06-25 21:11:13 +04:00
|
|
|
return m_factories.complete_id(prefix, cursor_pos);
|
2011-11-30 02:37:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|