Remove Code_Index_Note_Ptr_Array from the codebase, use Code_Index_Note_List instead

This commit is contained in:
Peter Slattery 2025-07-30 16:42:27 -07:00
parent 76863fc03a
commit 69dc4f8e04
4 changed files with 43 additions and 66 deletions

View File

@ -109,21 +109,6 @@ code_index_push_nest(Code_Index_Nest_List *list, Code_Index_Nest *nest){
list->count += 1; list->count += 1;
} }
function Code_Index_Note_Ptr_Array
code_index_note_ptr_array_from_list(Arena *arena, Code_Index_Note_List *list){
Code_Index_Note_Ptr_Array array = {};
array.ptrs = push_array_zero(arena, Code_Index_Note*, list->count);
array.count = list->count;
i32 counter = 0;
for (Code_Index_Note *node = list->first;
node != 0;
node = node->next){
array.ptrs[counter] = node;
counter += 1;
}
return(array);
}
function void function void
code_index_lock(void){ code_index_lock(void){
system_mutex_acquire(global_code_index.mutex); system_mutex_acquire(global_code_index.mutex);
@ -805,10 +790,6 @@ generic_parse_full_input_breaks(Code_Index_File *index, Generic_Parse_State *sta
} }
} }
if (result){
index->note_array = code_index_note_ptr_array_from_list(state->arena, &index->note_list);
}
return(result); return(result);
} }

View File

@ -93,17 +93,11 @@ struct Code_Index_Note_List{
i32 count; i32 count;
}; };
struct Code_Index_Note_Ptr_Array{
Code_Index_Note **ptrs;
i32 count;
};
struct Code_Index_File{ struct Code_Index_File{
Code_Index_Scope_Delim_List scope_delim_list; Code_Index_Scope_Delim_List scope_delim_list;
Code_Index_Scope_Delim_Ptr_Array scope_delim_array; Code_Index_Scope_Delim_Ptr_Array scope_delim_array;
Code_Index_Nest_List nest_list; Code_Index_Nest_List nest_list;
Code_Index_Note_List note_list; Code_Index_Note_List note_list;
Code_Index_Note_Ptr_Array note_array;
Buffer_ID buffer; Buffer_ID buffer;
}; };

View File

@ -13,24 +13,24 @@ CUSTOM_UI_COMMAND_SIG(jump_to_definition)
CUSTOM_DOC("List all definitions in the code index and jump to one chosen by the user.") CUSTOM_DOC("List all definitions in the code index and jump to one chosen by the user.")
{ {
char *query = "Definition:"; char *query = "Definition:";
Scratch_Block scratch(app); Scratch_Block scratch(app);
Lister_Block lister(app, scratch); Lister_Block lister(app, scratch);
lister_set_query(lister, query); lister_set_query(lister, query);
lister_set_default_handlers(lister); lister_set_default_handlers(lister);
code_index_lock(); code_index_lock();
for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always); for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always);
buffer != 0; buffer != 0;
buffer = get_buffer_next(app, buffer, Access_Always)){ buffer = get_buffer_next(app, buffer, Access_Always)){
Code_Index_File *file = code_index_get_file(buffer); Code_Index_File *file = code_index_get_file(buffer);
if (file != 0){ if (file != 0){
for (i32 i = 0; i < file->note_array.count; i += 1){ Code_Index_Note* note = file->note_list.first;
Code_Index_Note *note = file->note_array.ptrs[i]; for (i32 i = 0; i < file->note_list.count; i += 1, note = note->next){
Tiny_Jump *jump = push_array(scratch, Tiny_Jump, 1); Tiny_Jump *jump = push_array(scratch, Tiny_Jump, 1);
jump->buffer = buffer; jump->buffer = buffer;
jump->pos = note->pos.first; jump->pos = note->pos.first;
String_Const_u8 sort = {}; String_Const_u8 sort = {};
switch (note->note_kind){ switch (note->note_kind){
case CodeIndexNote_Type: case CodeIndexNote_Type:
@ -51,13 +51,13 @@ CUSTOM_DOC("List all definitions in the code index and jump to one chosen by the
} }
} }
code_index_unlock(); code_index_unlock();
Lister_Result l_result = run_lister(app, lister); Lister_Result l_result = run_lister(app, lister);
Tiny_Jump result = {}; Tiny_Jump result = {};
if (!l_result.canceled && l_result.user_data != 0){ if (!l_result.canceled && l_result.user_data != 0){
block_copy_struct(&result, (Tiny_Jump*)l_result.user_data); block_copy_struct(&result, (Tiny_Jump*)l_result.user_data);
} }
if (result.buffer != 0){ if (result.buffer != 0){
View_ID view = get_this_ctx_view(app, Access_Always); View_ID view = get_this_ctx_view(app, Access_Always);
point_stack_push_view_cursor(app, view); point_stack_push_view_cursor(app, view);
@ -68,31 +68,36 @@ CUSTOM_DOC("List all definitions in the code index and jump to one chosen by the
CUSTOM_UI_COMMAND_SIG(jump_to_definition_at_cursor) CUSTOM_UI_COMMAND_SIG(jump_to_definition_at_cursor)
CUSTOM_DOC("Jump to the first definition in the code index matching an identifier at the cursor") CUSTOM_DOC("Jump to the first definition in the code index matching an identifier at the cursor")
{ {
View_ID view = get_active_view(app, Access_Visible); View_ID view = get_active_view(app, Access_Visible);
if (view != 0){ if (view != 0)
Scratch_Block scratch(app); {
String_Const_u8 query = push_token_or_word_under_active_cursor(app, scratch); Scratch_Block scratch(app);
String_Const_u8 query = push_token_or_word_under_active_cursor(app, scratch);
code_index_lock();
for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always); code_index_lock();
buffer != 0; for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always);
buffer = get_buffer_next(app, buffer, Access_Always)){ buffer != 0;
Code_Index_File *file = code_index_get_file(buffer); buffer = get_buffer_next(app, buffer, Access_Always)
if (file != 0){ ){
for (i32 i = 0; i < file->note_array.count; i += 1){ Code_Index_File *file = code_index_get_file(buffer);
Code_Index_Note *note = file->note_array.ptrs[i]; if (file != 0)
if (string_match(note->text, query)){ {
point_stack_push_view_cursor(app, view); Code_Index_Note *note = file->note_list.first;
jump_to_location(app, view, buffer, note->pos.first); for (i32 i = 0; i < file->note_list.count; i += 1, note = note->next)
goto done; {
} if (string_match(note->text, query))
} {
} point_stack_push_view_cursor(app, view);
jump_to_location(app, view, buffer, note->pos.first);
goto done;
}
} }
done:; }
code_index_unlock();
} }
done:;
code_index_unlock();
}
} }
global String_Const_u8 code_index_note_strs[] = { global String_Const_u8 code_index_note_strs[] = {
@ -122,20 +127,20 @@ lister_add_from_buffer_code_index_filtered(Lister* lister, Buffer_ID buffer, Are
{ {
Code_Index_File* file_notes = code_index_get_file(buffer); Code_Index_File* file_notes = code_index_get_file(buffer);
if (!file_notes) return; if (!file_notes) return;
for (Code_Index_Note* note = file_notes->note_list.first; for (Code_Index_Note* note = file_notes->note_list.first;
note != 0; note != 0;
note = note->next) note = note->next)
{ {
if (!note_is_of_kind(kinds, kinds_count, note)) continue; if (!note_is_of_kind(kinds, kinds_count, note)) continue;
if (filter_all_but_last && note->next_in_hash) continue; if (filter_all_but_last && note->next_in_hash) continue;
String_Const_u8 sort = code_index_note_strs[note->note_kind]; String_Const_u8 sort = code_index_note_strs[note->note_kind];
Tiny_Jump *jump = push_array(scratch, Tiny_Jump, 1); Tiny_Jump *jump = push_array(scratch, Tiny_Jump, 1);
jump->buffer = buffer; jump->buffer = buffer;
jump->pos = note->pos.start; jump->pos = note->pos.start;
lister_add_item(lister, note->text, sort, jump, 0); lister_add_item(lister, note->text, sort, jump, 0);
} }
} }
@ -148,7 +153,7 @@ run_jump_lister(Application_Links* app, Lister* lister)
if (!l_result.canceled && l_result.user_data != 0){ if (!l_result.canceled && l_result.user_data != 0){
block_copy_struct(&result, (Tiny_Jump*)l_result.user_data); block_copy_struct(&result, (Tiny_Jump*)l_result.user_data);
} }
if (result.buffer != 0) if (result.buffer != 0)
{ {
View_ID view = get_this_ctx_view(app, Access_Always); View_ID view = get_this_ctx_view(app, Access_Always);
@ -164,7 +169,7 @@ lister_search_filtered(Application_Links* app, char* query, Code_Index_Note_Kind
Lister_Block lister(app, scratch); Lister_Block lister(app, scratch);
lister_set_query(lister, query); lister_set_query(lister, query);
lister_set_default_handlers(lister); lister_set_default_handlers(lister);
for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always); for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always);
buffer != 0; buffer = get_buffer_next(app, buffer, Access_Always)) buffer != 0; buffer = get_buffer_next(app, buffer, Access_Always))
{ {

View File

@ -552,9 +552,6 @@ tree_sitter_code_index_update_complete(
note->text = push_string_copy(&state->index_arena, string_substring(state->buffer_contents, note->pos)); note->text = push_string_copy(&state->index_arena, string_substring(state->buffer_contents, note->pos));
} }
// Finish the Index
state->index->note_array = code_index_note_ptr_array_from_list(&state->index_arena, &state->index->note_list);
code_index_lock(); code_index_lock();
code_index_set_file(state->buffer_id, state->index_arena, state->index); code_index_set_file(state->buffer_id, state->index_arena, state->index);
code_index_unlock(); code_index_unlock();
@ -891,9 +888,9 @@ tree_sitter_list_all_query_results(
Code_Index_File* file = code_index_get_file(buffer); Code_Index_File* file = code_index_get_file(buffer);
if (file != 0) if (file != 0)
{ {
for (i32 i = 0; i < file->note_array.count; i += 1) Code_Index_Note *note = file->note_list.first;
for (i32 i = 0; i < file->note_list.count; i += 1, note = note->next)
{ {
Code_Index_Note *note = file->note_array.ptrs[i];
if (note->note_kind == note_kind) if (note->note_kind == note_kind)
{ {
print_position( print_position(