sketch out view rule schemas; use them to determine autocompletion lister flags via partial parse of view rule input & matching to cursor; expand autocompletion lister to support lists of various things used in view rule arguments

This commit is contained in:
Ryan Fleury
2024-05-13 15:45:35 -07:00
parent 036d94fff0
commit 7c0f92ab3d
6 changed files with 191 additions and 40 deletions
+140
View File
@@ -4218,6 +4218,7 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
//- rjf: gather lister items
DF_AutoCompListerItemChunkList item_list = {0};
{
//- rjf: gather locals
if(ws->autocomp_lister_flags & DF_AutoCompListerFlag_Locals)
{
EVAL_String2NumMap *locals_map = df_query_cached_locals_map_from_binary_voff(binary, thread_rip_voff);
@@ -4235,6 +4236,8 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
}
}
}
//- rjf: gather registers
if(ws->autocomp_lister_flags & DF_AutoCompListerFlag_Registers)
{
Architecture arch = df_architecture_from_entity(thread);
@@ -4275,6 +4278,8 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
}
}
}
//- rjf: gather view rules
if(ws->autocomp_lister_flags & DF_AutoCompListerFlag_ViewRules)
{
for(U64 slot_idx = 0; slot_idx < df_state->view_rule_spec_table_size; slot_idx += 1)
@@ -4294,6 +4299,60 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
}
}
}
//- rjf: gather languages
if(ws->autocomp_lister_flags & DF_AutoCompListerFlag_Languages)
{
for(EachNonZeroEnumVal(TXT_LangKind, lang))
{
DF_AutoCompListerItem item = {0};
{
item.string = txt_extension_from_lang_kind(lang);
item.kind_string = str8_lit("Language");
item.matches = fuzzy_match_find(scratch.arena, query, item.string);
}
if(query.size == 0 || item.matches.count != 0)
{
df_autocomp_lister_item_chunk_list_push(scratch.arena, &item_list, 256, &item);
}
}
}
//- rjf: gather architectures
if(ws->autocomp_lister_flags & DF_AutoCompListerFlag_Architectures)
{
for(EachNonZeroEnumVal(Architecture, arch))
{
DF_AutoCompListerItem item = {0};
{
item.string = string_from_architecture(arch);
item.kind_string = str8_lit("Architecture");
item.matches = fuzzy_match_find(scratch.arena, query, item.string);
}
if(query.size == 0 || item.matches.count != 0)
{
df_autocomp_lister_item_chunk_list_push(scratch.arena, &item_list, 256, &item);
}
}
}
//- rjf: gather tex2dformats
if(ws->autocomp_lister_flags & DF_AutoCompListerFlag_Tex2DFormats)
{
for(EachNonZeroEnumVal(R_Tex2DFormat, fmt))
{
DF_AutoCompListerItem item = {0};
{
item.string = lower_from_str8(scratch.arena, r_tex2d_format_display_string_table[fmt]);
item.kind_string = str8_lit("Format");
item.matches = fuzzy_match_find(scratch.arena, query, item.string);
}
if(query.size == 0 || item.matches.count != 0)
{
df_autocomp_lister_item_chunk_list_push(scratch.arena, &item_list, 256, &item);
}
}
}
}
//- rjf: lister item list -> sorted array
@@ -8716,6 +8775,87 @@ df_autocomp_query_word_from_input_string_off(String8 input, U64 cursor_off)
return query;
}
internal DF_AutoCompListerFlags
df_view_rule_autocomp_lister_flags_from_input_cursor(String8 string, U64 cursor_off)
{
DF_AutoCompListerFlags flags = 0;
{
Temp scratch = scratch_begin(0, 0);
//- rjf: do partial parse of input
MD_TokenizeResult input_tokenize = md_tokenize_from_text(scratch.arena, string);
//- rjf: find descension steps to cursor
typedef struct DescendStep DescendStep;
struct DescendStep
{
DescendStep *next;
String8 string;
};
DescendStep *first_step = 0;
DescendStep *last_step = 0;
DescendStep *free_step = 0;
for(U64 idx = 0; idx < input_tokenize.tokens.count; idx += 1)
{
MD_Token *token = &input_tokenize.tokens.v[idx];
if(token->range.min < cursor_off && token->flags & (MD_TokenFlag_Identifier|MD_TokenFlag_StringLiteral))
{
DescendStep *step = free_step;
if(step != 0)
{
SLLStackPop(free_step);
MemoryZeroStruct(step);
}
else
{
step = push_array(scratch.arena, DescendStep, 1);
}
step->string = str8_substr(string, token->range);
SLLQueuePush(first_step, last_step, step);
}
}
//- rjf: map view rule root to spec
DF_CoreViewRuleSpec *spec = df_core_view_rule_spec_from_string(first_step ? first_step->string : str8_zero());
//- rjf: do parse of schema
MD_TokenizeResult schema_tokenize = md_tokenize_from_text(scratch.arena, spec->info.schema);
MD_ParseResult schema_parse = md_parse_from_text_tokens(scratch.arena, str8_zero(), spec->info.schema, schema_tokenize.tokens);
MD_Node *schema_rule_root = md_child_from_string(schema_parse.root, str8_lit("x"), 0);
//- rjf: follow schema according to descend steps, gather flags from schema node matching cursor node
if(first_step != 0)
{
MD_Node *schema_node = schema_rule_root;
for(DescendStep *step = first_step->next;;)
{
if(md_node_is_nil(schema_node->first))
{
if(str8_match(schema_node->string, str8_lit("expr"), StringMatchFlag_CaseInsensitive)) {flags |= DF_AutoCompListerFlag_Locals;}
if(str8_match(schema_node->string, str8_lit("member"), StringMatchFlag_CaseInsensitive)) {flags |= DF_AutoCompListerFlag_Members;}
if(str8_match(schema_node->string, str8_lit("lang"), StringMatchFlag_CaseInsensitive)) {flags |= DF_AutoCompListerFlag_Languages;}
if(str8_match(schema_node->string, str8_lit("arch"), StringMatchFlag_CaseInsensitive)) {flags |= DF_AutoCompListerFlag_Architectures;}
if(str8_match(schema_node->string, str8_lit("tex2dformat"), StringMatchFlag_CaseInsensitive)) {flags |= DF_AutoCompListerFlag_Tex2DFormats;}
break;
}
if(step != 0)
{
MD_Node *next_node = md_child_from_string(schema_node, step->string, StringMatchFlag_CaseInsensitive);
schema_node = next_node;
step = step->next;
}
else
{
schema_node = schema_node->first;
}
}
}
scratch_end(scratch);
}
return flags;
}
internal void
df_set_autocomp_lister_query(DF_Window *ws, UI_Key root_key, DF_CtrlCtx ctrl_ctx, DF_AutoCompListerFlags flags, String8 input, U64 cursor_off)
{
+8 -3
View File
@@ -442,9 +442,13 @@ struct DF_CodeSliceSignal
typedef U32 DF_AutoCompListerFlags;
enum
{
DF_AutoCompListerFlag_Locals = (1<<0),
DF_AutoCompListerFlag_Registers = (1<<1),
DF_AutoCompListerFlag_ViewRules = (1<<2),
DF_AutoCompListerFlag_Locals = (1<<0),
DF_AutoCompListerFlag_Registers = (1<<1),
DF_AutoCompListerFlag_ViewRules = (1<<2),
DF_AutoCompListerFlag_Members = (1<<3),
DF_AutoCompListerFlag_Languages = (1<<4),
DF_AutoCompListerFlag_Architectures = (1<<5),
DF_AutoCompListerFlag_Tex2DFormats = (1<<6),
};
typedef struct DF_AutoCompListerItem DF_AutoCompListerItem;
@@ -932,6 +936,7 @@ internal int df_autocomp_lister_item_qsort_compare(DF_AutoCompListerItem *a, DF_
internal void df_autocomp_lister_item_array_sort__in_place(DF_AutoCompListerItemArray *array);
internal String8 df_autocomp_query_word_from_input_string_off(String8 input, U64 cursor_off);
internal DF_AutoCompListerFlags df_view_rule_autocomp_lister_flags_from_input_cursor(String8 string, U64 cursor_off);
internal void df_set_autocomp_lister_query(DF_Window *ws, UI_Key root_key, DF_CtrlCtx ctrl_ctx, DF_AutoCompListerFlags flags, String8 input, U64 cursor_off);
////////////////////////////////
+6 -1
View File
@@ -1481,7 +1481,12 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW
if(rule_editing_active && !edit_end && txt_pt_match(ewv->input_cursor, ewv->input_mark))
{
String8 input = str8(ewv->input_buffer, ewv->input_size);
df_set_autocomp_lister_query(ws, sig.box->key, ctrl_ctx, DF_AutoCompListerFlag_ViewRules|DF_AutoCompListerFlag_Locals, input, ewv->input_cursor.column-1);
DF_AutoCompListerFlags flags = df_view_rule_autocomp_lister_flags_from_input_cursor(input, ewv->input_cursor.column-1);
if(flags == 0)
{
flags = DF_AutoCompListerFlag_ViewRules;
}
df_set_autocomp_lister_query(ws, sig.box->key, ctrl_ctx, flags, input, ewv->input_cursor.column-1);
}
}
}