diff --git a/code/custom/4coder_code_index.cpp b/code/custom/4coder_code_index.cpp index 45243e26..58e9186b 100644 --- a/code/custom/4coder_code_index.cpp +++ b/code/custom/4coder_code_index.cpp @@ -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); } diff --git a/code/custom/4coder_code_index.h b/code/custom/4coder_code_index.h index 9c431598..fa7c35a8 100644 --- a/code/custom/4coder_code_index.h +++ b/code/custom/4coder_code_index.h @@ -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; }; diff --git a/code/custom/4coder_code_index_listers.cpp b/code/custom/4coder_code_index_listers.cpp index d6c61417..b62d1eb4 100644 --- a/code/custom/4coder_code_index_listers.cpp +++ b/code/custom/4coder_code_index_listers.cpp @@ -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.") { char *query = "Definition:"; - + Scratch_Block scratch(app); Lister_Block lister(app, scratch); lister_set_query(lister, query); lister_set_default_handlers(lister); - + 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]; + 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; - + String_Const_u8 sort = {}; switch (note->note_kind){ 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(); - + Lister_Result l_result = run_lister(app, lister); Tiny_Jump result = {}; if (!l_result.canceled && l_result.user_data != 0){ block_copy_struct(&result, (Tiny_Jump*)l_result.user_data); } - + if (result.buffer != 0){ View_ID view = get_this_ctx_view(app, Access_Always); 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_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); - - 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; - } - } - } + 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); + + 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[] = { @@ -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); if (!file_notes) return; - + for (Code_Index_Note* note = file_notes->note_list.first; note != 0; note = note->next) { if (!note_is_of_kind(kinds, kinds_count, note)) continue; if (filter_all_but_last && note->next_in_hash) continue; - + String_Const_u8 sort = code_index_note_strs[note->note_kind]; - + Tiny_Jump *jump = push_array(scratch, Tiny_Jump, 1); jump->buffer = buffer; jump->pos = note->pos.start; - + 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){ block_copy_struct(&result, (Tiny_Jump*)l_result.user_data); } - + if (result.buffer != 0) { 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_set_query(lister, query); lister_set_default_handlers(lister); - + for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always); buffer != 0; buffer = get_buffer_next(app, buffer, Access_Always)) { diff --git a/code/custom/4coder_tree_sitter.cpp b/code/custom/4coder_tree_sitter.cpp index 8ec88ee9..abad0e7d 100644 --- a/code/custom/4coder_tree_sitter.cpp +++ b/code/custom/4coder_tree_sitter.cpp @@ -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(