Highlight only when necessary

This commit is contained in:
Alexey Milovidov 2024-04-12 00:44:26 +02:00
parent da05238c8e
commit 9664fb9249
3 changed files with 5 additions and 0 deletions

View File

@ -128,6 +128,7 @@ void highlight(const String & query, std::vector<replxx::Replxx::Color> & colors
Tokens tokens(begin, end, 1000, true);
IParser::Pos token_iterator(tokens, static_cast<uint32_t>(1000), static_cast<uint32_t>(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.

View File

@ -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)
{

View File

@ -56,6 +56,7 @@ struct Expected
absl::InlinedVector<const char *, 7> variants;
const char * max_parsed_pos = nullptr;
bool enable_highlighting = false;
std::set<HighlightedRange> highlights;
/// 'description' should be statically allocated string.