From 9023d106c61db0be0de6460a397bbad42bbc3d96 Mon Sep 17 00:00:00 2001 From: hachem Date: Fri, 4 Sep 2026 03:21:45 +0200 Subject: feat: macro expantion --- src/ui/source_view.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/ui/source_view.h') diff --git a/src/ui/source_view.h b/src/ui/source_view.h index 2e1a20f..c8a9a21 100644 --- a/src/ui/source_view.h +++ b/src/ui/source_view.h @@ -1,12 +1,16 @@ #pragma once #include "core/result.h" +#include "ui/macro_expander.h" #include #include +#include #include #include +struct ImDrawList; + namespace Hsdbg { class Debugger; @@ -22,6 +26,7 @@ namespace Hsdbg Number, Comment, Preprocessor, + Macro, }; struct SourceSpan @@ -52,21 +57,40 @@ namespace Hsdbg auto line_count() const -> size_t { return m_lines.size(); } auto is_open() const -> bool { return !m_lines.empty(); } + // the #defines visible in the open file, so a panel can expand the same + // macros the source view is highlighting + auto macros() const -> const MacroTable& { return m_macros; } + + // when the user clicks a highlighted macro, the invocation as written + // (name plus any argument list) is stashed here for the ui to pick up and + // hand to the macros panel; cleared once taken + auto take_macro_request() -> std::optional; + private: auto draw_open_bar() -> void; auto draw_lines(Debugger& debugger) -> void; + // renders a highlighted macro name: hovering previews its expansion, + // clicking records the invocation for the macros panel to open + auto draw_macro_span(ImDrawList* draw_list, const std::string& line, + const SourceSpan& span) -> void; + std::filesystem::path m_path; std::vector m_lines; std::vector> m_spans; + MacroTable m_macros; + std::optional m_macro_request; bool m_highlight = false; bool m_highlighting_enabled = true; bool m_line_numbers = true; bool m_highlight_current_line = true; - // indexed by SyntaxKind; the defaults match the built-in dark palette - unsigned int m_syntax_colors[7] = { + // indexed by SyntaxKind; the defaults match the built-in dark palette. + // the macro colour (last) is warm on purpose so expandable names read as + // clickable against the rest of the syntax + unsigned int m_syntax_colors[8] = { 0, 0xFFD69C56, 0xFFB0C94E, 0xFF7891CE, 0xFFA8CEB5, 0xFF55996A, 0xFFC086C5, + 0xFF4FA3E0, }; unsigned int m_current_line_color = 0xFF2E483A; std::string m_path_input; -- cgit v1.3