From 94a0c9bb4564632c06e25eb3fbc4e7123ff842ff Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 31 Oct 2017 13:53:08 +0800 Subject: [PATCH] Highlighters does not need to inherit from HighlighterGroup Just compose, to avoid coupling Highlighters with the Highlighter interface. And yeah, that naming is a bit confusing. --- src/commands.cc | 6 +++--- src/highlighter_group.cc | 14 +++++++------- src/highlighter_group.hh | 18 ++++++++++++------ src/window.cc | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index f4f4dc754..39af4e205 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -653,7 +653,7 @@ Completions highlighter_cmd_completer( if (scope == "shared") root = &DefinedHighlighters::instance(); else if (auto* s = get_scope_ifp(scope, context)) - root = &s->highlighters(); + root = &s->highlighters().group(); else return {}; @@ -676,8 +676,8 @@ Highlighter& get_highlighter(const Context& context, StringView path) auto sep_it = find(path, '/'); StringView scope{path.begin(), sep_it}; - auto* root = (scope == "shared") ? (HighlighterGroup*)&DefinedHighlighters::instance() - : (HighlighterGroup*)&get_scope(scope, context).highlighters(); + auto* root = (scope == "shared") ? static_cast(&DefinedHighlighters::instance()) + : static_cast(&get_scope(scope, context).highlighters().group()); if (sep_it != path.end()) return root->get_child(StringView{sep_it+1, path.end()}); return *root; diff --git a/src/highlighter_group.cc b/src/highlighter_group.cc index 39130159c..9768c1604 100644 --- a/src/highlighter_group.cc +++ b/src/highlighter_group.cc @@ -69,19 +69,19 @@ Completions HighlighterGroup::complete_child(StringView path, ByteCount cursor_p return { 0, 0, std::move(candidates) }; } -void Highlighters::do_highlight(const Context& context, HighlightPass pass, - DisplayBuffer& display_buffer, BufferRange range) +void Highlighters::highlight(const Context& context, HighlightPass pass, + DisplayBuffer& display_buffer, BufferRange range) { if (m_parent) - m_parent->do_highlight(context, pass, display_buffer, range); - HighlighterGroup::do_highlight(context, pass, display_buffer, range); + m_parent->highlight(context, pass, display_buffer, range); + m_group.highlight(context, pass, display_buffer, range); } -void Highlighters::do_compute_display_setup(const Context& context, HighlightPass pass, DisplaySetup& setup) +void Highlighters::compute_display_setup(const Context& context, HighlightPass pass, DisplaySetup& setup) { if (m_parent) - m_parent->do_compute_display_setup(context, pass, setup); - HighlighterGroup::do_compute_display_setup(context, pass, setup); + m_parent->compute_display_setup(context, pass, setup); + m_group.compute_display_setup(context, pass, setup); } } diff --git a/src/highlighter_group.hh b/src/highlighter_group.hh index 95a88a6b6..ff9a2f053 100644 --- a/src/highlighter_group.hh +++ b/src/highlighter_group.hh @@ -36,19 +36,25 @@ protected: HighlighterMap m_highlighters; }; -class Highlighters : public HighlighterGroup, public SafeCountable +struct ScopeList; + +class Highlighters : public SafeCountable { public: - Highlighters(Highlighters& parent) : HighlighterGroup{HighlightPass::All}, SafeCountable{}, m_parent(&parent) {} + Highlighters(Highlighters& parent) : SafeCountable{}, m_parent{&parent}, m_group{HighlightPass::All} {} + + HighlighterGroup& group() { return m_group; } + const HighlighterGroup& group() const { return m_group; } + + void highlight(const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange range); + void compute_display_setup(const Context& context, HighlightPass pass, DisplaySetup& setup); private: - void do_highlight(const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange range) override; - void do_compute_display_setup(const Context& context, HighlightPass pass, DisplaySetup& setup) override; - friend class Scope; - Highlighters() : HighlighterGroup{HighlightPass::All} {} + Highlighters() : m_group{HighlightPass::All} {} SafePtr m_parent; + HighlighterGroup m_group; }; struct DefinedHighlighters : public HighlighterGroup, diff --git a/src/window.cc b/src/window.cc index e1bd3ee54..76cb10cb3 100644 --- a/src/window.cc +++ b/src/window.cc @@ -28,7 +28,7 @@ Window::Window(Buffer& buffer) options().register_watcher(*this); - setup_builtin_highlighters(m_builtin_highlighters); + setup_builtin_highlighters(m_builtin_highlighters.group()); for (auto& option : options().flatten_options()) on_option_changed(*option);