Restructure default_render_buffer to only color visible tokens, and only look up tokens that are identifiers
This commit is contained in:
parent
2ab0c0a2de
commit
7359649465
|
@ -325,6 +325,13 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id,
|
||||||
f32 mark_thickness = (f32)def_get_config_u64(app, vars_save_string_lit("mark_thickness"));
|
f32 mark_thickness = (f32)def_get_config_u64(app, vars_save_string_lit("mark_thickness"));
|
||||||
|
|
||||||
// NOTE(allen): Token colorizing
|
// NOTE(allen): Token colorizing
|
||||||
|
|
||||||
|
ARGB_Color color_default = fcolor_resolve(fcolor_id(defcolor_text_default));
|
||||||
|
ARGB_Color color_function = fcolor_resolve(fcolor_id(defcolor_function));
|
||||||
|
ARGB_Color color_operator = fcolor_resolve(fcolor_id(defcolor_operator));
|
||||||
|
ARGB_Color color_type = fcolor_resolve(fcolor_id(defcolor_type));
|
||||||
|
ARGB_Color color_macro = fcolor_resolve(fcolor_id(defcolor_macro));
|
||||||
|
|
||||||
Token_Array token_array = get_token_array_from_buffer(app, buffer);
|
Token_Array token_array = get_token_array_from_buffer(app, buffer);
|
||||||
if (token_array.tokens != 0){
|
if (token_array.tokens != 0){
|
||||||
draw_cpp_token_colors(app, text_layout_id, &token_array);
|
draw_cpp_token_colors(app, text_layout_id, &token_array);
|
||||||
|
@ -342,55 +349,45 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id,
|
||||||
// NOTE(allen): Color functions
|
// NOTE(allen): Color functions
|
||||||
Scratch_Block scratch(app);
|
Scratch_Block scratch(app);
|
||||||
|
|
||||||
ARGB_Color color_function = fcolor_resolve(fcolor_id(defcolor_function));
|
|
||||||
ARGB_Color color_operator = fcolor_resolve(fcolor_id(defcolor_operator));
|
|
||||||
ARGB_Color color_type = fcolor_resolve(fcolor_id(defcolor_type));
|
|
||||||
ARGB_Color color_macro = fcolor_resolve(fcolor_id(defcolor_macro));
|
|
||||||
|
|
||||||
Token_Iterator_Array it = token_iterator_pos(0, &token_array, visible_range.first);
|
Token_Iterator_Array it = token_iterator_pos(0, &token_array, visible_range.first);
|
||||||
|
it.count = Min(it.count, visible_range.one_past_last - visible_range.first);
|
||||||
for (;;){
|
for (;;){
|
||||||
if (!token_it_inc_non_whitespace(&it)){
|
if (!token_it_inc_non_whitespace(&it)){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ARGB_Color token_color = color_default;
|
||||||
Token *token = token_it_read(&it);
|
Token *token = token_it_read(&it);
|
||||||
String_Const_u8 lexeme = push_token_lexeme(app, scratch, buffer, token);
|
if (token->kind == TokenBaseKind_Operator ||
|
||||||
Code_Index_Note *note = code_index_note_from_string(lexeme);
|
|
||||||
if (note != 0)
|
|
||||||
{
|
|
||||||
switch (note->note_kind)
|
|
||||||
{
|
|
||||||
case CodeIndexNote_Type:
|
|
||||||
{
|
|
||||||
paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), color_type);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case CodeIndexNote_Function:
|
|
||||||
{
|
|
||||||
paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), color_function);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case CodeIndexNote_Macro:
|
|
||||||
{
|
|
||||||
paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), color_macro);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
default: {} break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (token->kind == TokenBaseKind_Operator ||
|
|
||||||
token->kind == TokenBaseKind_ScopeOpen ||
|
token->kind == TokenBaseKind_ScopeOpen ||
|
||||||
token->kind == TokenBaseKind_ScopeClose ||
|
token->kind == TokenBaseKind_ScopeClose ||
|
||||||
token->kind == TokenBaseKind_ParentheticalOpen ||
|
token->kind == TokenBaseKind_ParentheticalOpen ||
|
||||||
token->kind == TokenBaseKind_ParentheticalClose ||
|
token->kind == TokenBaseKind_ParentheticalClose ||
|
||||||
token->kind == TokenBaseKind_StatementClose)
|
token->kind == TokenBaseKind_StatementClose)
|
||||||
{
|
{
|
||||||
paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), color_operator);
|
token_color = color_operator;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String_Const_u8 lexeme = push_token_lexeme(app, scratch, buffer, token);
|
||||||
|
Code_Index_Note *note = code_index_note_from_string(lexeme);
|
||||||
|
if (note != 0)
|
||||||
|
{
|
||||||
|
switch (note->note_kind)
|
||||||
|
{
|
||||||
|
case CodeIndexNote_Type: token_color = color_type; break;
|
||||||
|
case CodeIndexNote_Function: token_color = color_function; break;
|
||||||
|
case CodeIndexNote_Macro: token_color = color_macro; break;
|
||||||
|
default: {} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), token_color);
|
||||||
paint_text_color_fcolor(app, text_layout_id, visible_range, fcolor_id(defcolor_text_default));
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
paint_text_color(app, text_layout_id, visible_range, color_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 cursor_pos = view_correct_cursor(app, view_id);
|
i64 cursor_pos = view_correct_cursor(app, view_id);
|
||||||
|
|
Loading…
Reference in New Issue