1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:17:35 +00:00

LibWeb: Add debugging statements in SyntaxHighlighter

This also changes SyntaxHighlighter.{h,cpp} to use east const style.
This commit is contained in:
Max Wipfli 2021-06-04 11:25:09 +02:00 committed by Ali Mohammad Pur
parent 04897f6842
commit 93d830b5cc
2 changed files with 14 additions and 2 deletions

View file

@ -1,9 +1,11 @@
/* /*
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org> * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
* Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <AK/Debug.h>
#include <LibWeb/HTML/Parser/HTMLTokenizer.h> #include <LibWeb/HTML/Parser/HTMLTokenizer.h>
#include <LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.h> #include <LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.h>
@ -30,13 +32,15 @@ bool SyntaxHighlighter::is_navigatable(void*) const
return false; return false;
} }
void SyntaxHighlighter::rehighlight(const Palette& palette) void SyntaxHighlighter::rehighlight(Palette const& palette)
{ {
dbgln_if(SYNTAX_HIGHLIGHTING_DEBUG, "(HTML::SyntaxHighlighter) starting rehighlight");
(void)palette; (void)palette;
auto text = m_client->get_text(); auto text = m_client->get_text();
Vector<GUI::TextDocumentSpan> spans; Vector<GUI::TextDocumentSpan> spans;
auto highlight = [&](auto start_line, auto start_column, auto end_line, auto end_column, Gfx::TextAttributes attributes, AugmentedTokenKind kind) { auto highlight = [&](auto start_line, auto start_column, auto end_line, auto end_column, Gfx::TextAttributes attributes, AugmentedTokenKind kind) {
dbgln_if(SYNTAX_HIGHLIGHTING_DEBUG, "(HTML::SyntaxHighlighter) highlighting ({}-{}) to ({}-{}) with color {}", start_line, start_column, end_line, end_column, attributes.color);
spans.empend( spans.empend(
GUI::TextRange { GUI::TextRange {
{ start_line, start_column }, { start_line, start_column },
@ -57,6 +61,7 @@ void SyntaxHighlighter::rehighlight(const Palette& palette)
auto token = tokenizer.next_token(); auto token = tokenizer.next_token();
if (!token.has_value()) if (!token.has_value())
break; break;
dbgln_if(SYNTAX_HIGHLIGHTING_DEBUG, "(HTML::SyntaxHighlighter) got token of type {}", token->to_string());
if (token->is_start_tag()) { if (token->is_start_tag()) {
if (token->tag_name() == "script"sv) { if (token->tag_name() == "script"sv) {
@ -124,6 +129,13 @@ void SyntaxHighlighter::rehighlight(const Palette& palette)
} }
} }
if constexpr (SYNTAX_HIGHLIGHTING_DEBUG) {
dbgln("(HTML::SyntaxHighlighter) list of all spans:");
for (auto& span : spans)
dbgln("{}, {}", span.range, span.attributes.color);
dbgln("(HTML::SyntaxHighlighter) end of list");
}
m_client->do_set_spans(move(spans)); m_client->do_set_spans(move(spans));
m_has_brace_buddies = false; m_has_brace_buddies = false;
highlight_matching_token_pair(); highlight_matching_token_pair();

View file

@ -19,7 +19,7 @@ public:
virtual bool is_navigatable(void*) const override; virtual bool is_navigatable(void*) const override;
virtual Syntax::Language language() const override { return Syntax::Language::HTML; } virtual Syntax::Language language() const override { return Syntax::Language::HTML; }
virtual void rehighlight(const Palette&) override; virtual void rehighlight(Palette const&) override;
protected: protected:
virtual Vector<MatchingTokenPair> matching_token_pairs() const override; virtual Vector<MatchingTokenPair> matching_token_pairs() const override;