1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

LibSyntax+Libraries: Replace TextStyle with Gfx::TextAttributes

Rather than creating a TextStyle struct, and then copying its fields
over to a TextAttributes, let's just create a TextAttributes to start
with. This also simplifies the syntax highlighting code by letting us
define underlines along with the other text styling.
This commit is contained in:
Sam Atkins 2023-03-15 12:49:17 +00:00 committed by Andreas Kling
parent 6d8f046fd0
commit 406a7ea577
10 changed files with 59 additions and 90 deletions

View file

@ -85,44 +85,44 @@ void SemanticSyntaxHighlighter::rehighlight(Palette const& palette)
update_spans(new_tokens_info, palette);
}
static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, CodeComprehension::TokenInfo::SemanticType type)
static Gfx::TextAttributes style_for_token_type(Gfx::Palette const& palette, CodeComprehension::TokenInfo::SemanticType type)
{
switch (type) {
case CodeComprehension::TokenInfo::SemanticType::Unknown:
return { palette.base_text(), false };
return { palette.base_text() };
case CodeComprehension::TokenInfo::SemanticType::Keyword:
return { palette.syntax_keyword(), true };
return { palette.syntax_keyword(), {}, true };
case CodeComprehension::TokenInfo::SemanticType::Type:
return { palette.syntax_type(), true };
return { palette.syntax_type(), {}, true };
case CodeComprehension::TokenInfo::SemanticType::Identifier:
return { palette.syntax_identifier(), false };
return { palette.syntax_identifier() };
case CodeComprehension::TokenInfo::SemanticType::String:
return { palette.syntax_string(), false };
return { palette.syntax_string() };
case CodeComprehension::TokenInfo::SemanticType::Number:
return { palette.syntax_number(), false };
return { palette.syntax_number() };
case CodeComprehension::TokenInfo::SemanticType::IncludePath:
return { palette.syntax_preprocessor_value(), false };
return { palette.syntax_preprocessor_value() };
case CodeComprehension::TokenInfo::SemanticType::PreprocessorStatement:
return { palette.syntax_preprocessor_statement(), false };
return { palette.syntax_preprocessor_statement() };
case CodeComprehension::TokenInfo::SemanticType::Comment:
return { palette.syntax_comment(), false };
return { palette.syntax_comment() };
case CodeComprehension::TokenInfo::SemanticType::Function:
return { palette.syntax_function(), false };
return { palette.syntax_function() };
case CodeComprehension::TokenInfo::SemanticType::Variable:
return { palette.syntax_variable(), false };
return { palette.syntax_variable() };
case CodeComprehension::TokenInfo::SemanticType::CustomType:
return { palette.syntax_custom_type(), false };
return { palette.syntax_custom_type() };
case CodeComprehension::TokenInfo::SemanticType::Namespace:
return { palette.syntax_namespace(), false };
return { palette.syntax_namespace() };
case CodeComprehension::TokenInfo::SemanticType::Member:
return { palette.syntax_member(), false };
return { palette.syntax_member() };
case CodeComprehension::TokenInfo::SemanticType::Parameter:
return { palette.syntax_parameter(), false };
return { palette.syntax_parameter() };
case CodeComprehension::TokenInfo::SemanticType::PreprocessorMacro:
return { palette.syntax_preprocessor_value(), false };
return { palette.syntax_preprocessor_value() };
default:
VERIFY_NOT_REACHED();
return { palette.base_text(), false };
return { palette.base_text() };
}
}
void SemanticSyntaxHighlighter::update_spans(Vector<CodeComprehension::TokenInfo> const& tokens_info, Gfx::Palette const& palette)
@ -133,9 +133,7 @@ void SemanticSyntaxHighlighter::update_spans(Vector<CodeComprehension::TokenInfo
GUI::TextDocumentSpan span;
span.range.set_start({ token.start_line, token.start_column });
span.range.set_end({ token.end_line, token.end_column + 1 });
auto style = style_for_token_type(palette, token.type);
span.attributes.color = style.color;
span.attributes.bold = style.bold;
span.attributes = style_for_token_type(palette, token.type);
span.is_skippable = token.type == CodeComprehension::TokenInfo::SemanticType::Whitespace;
span.data = static_cast<u64>(token.type);
spans.append(span);