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;
}
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
code_index_lock(void){
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);
}

View File

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

View File

@ -25,8 +25,8 @@ CUSTOM_DOC("List all definitions in the code index and jump to one chosen by the
buffer = get_buffer_next(app, buffer, Access_Always)){
Code_Index_File *file = code_index_get_file(buffer);
if (file != 0){
for (i32 i = 0; i < file->note_array.count; i += 1){
Code_Index_Note *note = file->note_array.ptrs[i];
Code_Index_Note* note = file->note_list.first;
for (i32 i = 0; i < file->note_list.count; i += 1, note = note->next){
Tiny_Jump *jump = push_array(scratch, Tiny_Jump, 1);
jump->buffer = buffer;
jump->pos = note->pos.first;
@ -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_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){
Scratch_Block scratch(app);
String_Const_u8 query = push_token_or_word_under_active_cursor(app, scratch);
if (view != 0)
{
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);
buffer != 0;
buffer = get_buffer_next(app, buffer, Access_Always)){
Code_Index_File *file = code_index_get_file(buffer);
if (file != 0){
for (i32 i = 0; i < file->note_array.count; i += 1){
Code_Index_Note *note = file->note_array.ptrs[i];
if (string_match(note->text, query)){
point_stack_push_view_cursor(app, view);
jump_to_location(app, view, buffer, note->pos.first);
goto done;
}
}
}
code_index_lock();
for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always);
buffer != 0;
buffer = get_buffer_next(app, buffer, Access_Always)
){
Code_Index_File *file = code_index_get_file(buffer);
if (file != 0)
{
Code_Index_Note *note = file->note_list.first;
for (i32 i = 0; i < file->note_list.count; i += 1, note = note->next)
{
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[] = {

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));
}
// 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_set_file(state->buffer_id, state->index_arena, state->index);
code_index_unlock();
@ -891,9 +888,9 @@ tree_sitter_list_all_query_results(
Code_Index_File* file = code_index_get_file(buffer);
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)
{
print_position(