From 9664fb92499f3f4dfc8591baa98b70c007191825 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 12 Apr 2024 00:44:26 +0200 Subject: [PATCH] Highlight only when necessary --- src/Client/ClientBaseHelpers.cpp | 1 + src/Parsers/IParser.cpp | 3 +++ src/Parsers/IParser.h | 1 + 3 files changed, 5 insertions(+) diff --git a/src/Client/ClientBaseHelpers.cpp b/src/Client/ClientBaseHelpers.cpp index b1d29b34ffc..8310aa67c22 100644 --- a/src/Client/ClientBaseHelpers.cpp +++ b/src/Client/ClientBaseHelpers.cpp @@ -128,6 +128,7 @@ void highlight(const String & query, std::vector & colors Tokens tokens(begin, end, 1000, true); IParser::Pos token_iterator(tokens, static_cast(1000), static_cast(10000)); Expected expected; + expected.enable_highlighting = true; /// We don't do highlighting for foreign dialects, such as PRQL and Kusto. /// Only normal ClickHouse SQL queries are highlighted. diff --git a/src/Parsers/IParser.cpp b/src/Parsers/IParser.cpp index eb4ddfa01d2..ddd210b01ec 100644 --- a/src/Parsers/IParser.cpp +++ b/src/Parsers/IParser.cpp @@ -44,6 +44,9 @@ static bool intersects(T a_begin, T a_end, T b_begin, T b_end) void Expected::highlight(HighlightedRange range) { + if (!enable_highlighting) + return; + auto it = highlights.lower_bound(range); while (it != highlights.end() && range.begin < it->end) { diff --git a/src/Parsers/IParser.h b/src/Parsers/IParser.h index f8146c0a4f6..0ae862fee75 100644 --- a/src/Parsers/IParser.h +++ b/src/Parsers/IParser.h @@ -56,6 +56,7 @@ struct Expected absl::InlinedVector variants; const char * max_parsed_pos = nullptr; + bool enable_highlighting = false; std::set highlights; /// 'description' should be statically allocated string.