2014-06-10 20:58:02 +02:00
|
|
|
#ifndef highlighter_group_hh_INCLUDED
|
|
|
|
#define highlighter_group_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "exception.hh"
|
2017-03-07 02:12:37 +01:00
|
|
|
#include "hash_map.hh"
|
2014-06-10 20:58:02 +02:00
|
|
|
#include "highlighter.hh"
|
|
|
|
#include "utils.hh"
|
2017-10-28 05:00:51 +02:00
|
|
|
#include "safe_ptr.hh"
|
2014-06-10 20:58:02 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
struct child_not_found : public runtime_error
|
2014-06-10 20:58:02 +02:00
|
|
|
{
|
|
|
|
using runtime_error::runtime_error;
|
|
|
|
};
|
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
class HighlighterGroup : public Highlighter
|
2014-06-10 20:58:02 +02:00
|
|
|
{
|
|
|
|
public:
|
2017-05-03 20:41:37 +02:00
|
|
|
HighlighterGroup(HighlightPass passes) : Highlighter{passes} {}
|
2014-06-10 20:58:02 +02:00
|
|
|
|
2015-05-25 14:54:18 +02:00
|
|
|
bool has_children() const override { return true; }
|
2014-10-22 01:20:09 +02:00
|
|
|
void add_child(HighlighterAndId&& hl) override;
|
|
|
|
void remove_child(StringView id) override;
|
2014-06-10 20:58:02 +02:00
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
Highlighter& get_child(StringView path) override;
|
2014-06-10 20:58:02 +02:00
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
Completions complete_child(StringView path, ByteCount cursor_pos, bool group) const override;
|
2014-06-10 20:58:02 +02:00
|
|
|
|
2017-11-25 05:53:33 +01:00
|
|
|
void fill_unique_ids(Vector<StringView>& unique_ids) const override;
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
protected:
|
2017-11-25 05:53:33 +01:00
|
|
|
void do_highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range) override;
|
2018-04-06 01:12:17 +02:00
|
|
|
void do_compute_display_setup(HighlightContext context, DisplaySetup& setup) const override;
|
2017-05-03 20:41:37 +02:00
|
|
|
|
2017-03-07 02:12:37 +01:00
|
|
|
using HighlighterMap = HashMap<String, std::unique_ptr<Highlighter>, MemoryDomain::Highlight>;
|
2014-10-22 01:20:09 +02:00
|
|
|
HighlighterMap m_highlighters;
|
2014-06-10 22:35:03 +02:00
|
|
|
};
|
|
|
|
|
2017-10-31 06:53:08 +01:00
|
|
|
class Highlighters : public SafeCountable
|
2017-10-28 05:00:51 +02:00
|
|
|
{
|
|
|
|
public:
|
2017-10-31 06:53:08 +01:00
|
|
|
Highlighters(Highlighters& parent) : SafeCountable{}, m_parent{&parent}, m_group{HighlightPass::All} {}
|
2017-10-28 05:00:51 +02:00
|
|
|
|
2017-10-31 06:53:08 +01:00
|
|
|
HighlighterGroup& group() { return m_group; }
|
|
|
|
const HighlighterGroup& group() const { return m_group; }
|
|
|
|
|
2017-11-25 05:53:33 +01:00
|
|
|
void highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range);
|
2018-04-06 01:12:17 +02:00
|
|
|
void compute_display_setup(HighlightContext context, DisplaySetup& setup) const;
|
2017-10-28 05:00:51 +02:00
|
|
|
|
2017-10-31 06:53:08 +01:00
|
|
|
private:
|
2017-10-28 05:00:51 +02:00
|
|
|
friend class Scope;
|
2017-10-31 06:53:08 +01:00
|
|
|
Highlighters() : m_group{HighlightPass::All} {}
|
2017-10-28 05:00:51 +02:00
|
|
|
|
|
|
|
SafePtr<Highlighters> m_parent;
|
2017-10-31 06:53:08 +01:00
|
|
|
HighlighterGroup m_group;
|
2017-10-28 05:00:51 +02:00
|
|
|
};
|
|
|
|
|
2014-06-10 20:58:02 +02:00
|
|
|
struct DefinedHighlighters : public HighlighterGroup,
|
|
|
|
public Singleton<DefinedHighlighters>
|
|
|
|
{
|
2017-05-03 20:41:37 +02:00
|
|
|
DefinedHighlighters() : HighlighterGroup{HighlightPass::All} {}
|
2014-06-10 20:58:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // highlighter_group_hh_INCLUDED
|