Incrementally update global_code_index.name_hash

This commit is contained in:
Peter Slattery 2025-08-03 18:03:40 -07:00
parent a92e364e37
commit 8ad2b5bbff
10 changed files with 506 additions and 193 deletions

View File

@ -257,6 +257,7 @@ get_active_edit_behaviors(Models *models, Editing_File *file){
api(custom) function b32
buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range_i64 range, String_Const_u8 string)
{
ProfileScope(app, "buffer_replace_range");
Models *models = (Models*)app->cmd_context;
Editing_File *file = imp_get_file(models, buffer_id);
b32 result = false;

View File

@ -15,6 +15,87 @@ delims_are_open_close_pair(Code_Index_Scope_Delim_Kind a, Code_Index_Scope_Delim
return false;
}
////////////////////////////////
// NOTE(allen): Code_Index_Note_List
function void
code_index_note_list_init(Code_Index_Note_List_New* list)
{
list->sentinel_first.next = &list->sentinel_last;
list->sentinel_last.next = 0;
list->count = 0;
}
function void
code_index_note_list_hash_init(Code_Index_Note_List_New* list)
{
list->sentinel_first.next_in_hash = &list->sentinel_last;
list->sentinel_first.prev_in_hash = 0;
list->sentinel_last.next_in_hash = 0;
list->sentinel_last.prev_in_hash = &list->sentinel_first;
list->count = 0;
}
function void
code_index_note_list_insert(Code_Index_Note_List_New* list, Code_Index_Note* prev, Code_Index_Note* note)
{
Assert(prev != 0);
Code_Index_Note* next = prev->next;
prev->next = note;
note->next = next;
list->count += 1;
}
function void
code_index_note_list_hash_insert(Code_Index_Note_List_New* list, Code_Index_Note* prev, Code_Index_Note* note)
{
Assert(prev != 0);
Code_Index_Note* next = prev->next_in_hash;
prev->next_in_hash = note;
note->prev_in_hash = prev;
note->next_in_hash = next;
next->prev_in_hash = note;
list->count += 1;
}
function void
code_index_note_list_hash_append(Code_Index_Note_List_New* list, Code_Index_Note* note)
{
Code_Index_Note* prev = list->sentinel_last.prev_in_hash;
Code_Index_Note* next = &list->sentinel_last;
prev->next_in_hash = note;
note->prev_in_hash = prev;
note->next_in_hash = next;
next->prev_in_hash = note;
list->count += 1;
}
function void
code_index_note_list_remove(Code_Index_Note_List_New* list, Code_Index_Note* prev, Code_Index_Note* note)
{
Assert(note->next != 0);
Assert(list->count > 0);
Code_Index_Note* next = note->next;
prev->next = next;
list->count -= 1;
note->next = 0;
}
function void
code_index_note_list_hash_remove(Code_Index_Note_List_New* list, Code_Index_Note* note)
{
Assert(note->prev_in_hash != 0 && note->next_in_hash != 0);
Assert(list->count > 0);
Code_Index_Note* prev = note->prev_in_hash;
Code_Index_Note* next = note->next_in_hash;
prev->next_in_hash = next;
next->prev_in_hash = prev;
list->count -= 1;
note->prev_in_hash = 0;
note->next_in_hash = 0;
}
////////////////////////////////
// NOTE(allen): Lookups
@ -49,19 +130,21 @@ code_index_get_nest(Code_Index_File *file, i64 pos)
return result;
}
function Code_Index_Note_List*
code_index__list_from_string(String_Const_u8 string){
function Code_Index_Note_List_New*
code_index__list_from_string(String_Const_u8 string)
{
u64 hash = table_hash_u8(string.str, string.size);
Code_Index_Note_List *result = &global_code_index.name_hash[hash % ArrayCount(global_code_index.name_hash)];
u64 index = hash % ArrayCount(global_code_index.name_hash);
Code_Index_Note_List_New *result = &global_code_index.name_hash[index];
return(result);
}
function Code_Index_Note*
code_index_note_from_string(String_Const_u8 string){
Code_Index_Note_List *list = code_index__list_from_string(string);
Code_Index_Note_List_New *list = code_index__list_from_string(string);
Code_Index_Note *result = 0;
for (Code_Index_Note *node = list->first;
node != 0;
for (Code_Index_Note *node = list->sentinel_first.next_in_hash;
node != &list->sentinel_last;
node = node->next_in_hash){
if (string_match(string, node->text)){
result = node;
@ -76,10 +159,16 @@ code_index_note_from_string(String_Const_u8 string){
// NOTE(allen): Global Code Index
function void
code_index_init(void){
code_index_init(void)
{
global_code_index.mutex = system_mutex_make();
global_code_index.node_arena = make_arena_system(KB(4));
global_code_index.buffer_to_index_file = make_table_u64_u64(global_code_index.node_arena.base_allocator, 500);
for (int i = 0; i < ArrayCount(global_code_index.name_hash); i++)
{
code_index_note_list_hash_init(&global_code_index.name_hash[i]);
}
}
function Code_Index_File_Storage*
@ -121,13 +210,16 @@ code_index_unlock(void){
function void
code_index__hash_file(Code_Index_File *file){
// TODO(PS): @RemoveWholeFileHashing - this isn't necessary since, to support incremental updates
// we insert nodes into the hash table when the node is created
#if 0
for (Code_Index_Note *node = file->note_list.first;
node != 0;
node = node->next){
Code_Index_Note_List *list = code_index__list_from_string(node->text);
zdll_push_back_NP_(list->first, list->last, node, next_in_hash, prev_in_hash);
list->count += 1;
Code_Index_Note_List_New *list = code_index__list_from_string(node->text);
code_index_note_list_hash_insert(list, list->sentinel_last.prev_in_hash, node);
}
#endif
}
function void
@ -135,9 +227,8 @@ code_index__clear_file(Code_Index_File *file){
for (Code_Index_Note *node = file->note_list.first;
node != 0;
node = node->next){
Code_Index_Note_List *list = code_index__list_from_string(node->text);
zdll_remove_NP_(list->first, list->last, node, next_in_hash, prev_in_hash);
list->count -= 1;
Code_Index_Note_List_New *list = code_index__list_from_string(node->text);
code_index_note_list_hash_remove(list, node);
}
}
@ -261,12 +352,45 @@ code_index_shift_list(Code_Index_Scope_Delim_List *list, Range_i64 old_range, u6
}
}
function void
code_index_shift_list(Code_Index_Note_List *list, Range_i64 old_range, u64 new_size)
{
i32 count = list->count;
Code_Index_Note *note = list->first;
for (i32 i = 0; i < count; i += 1, note = note->next)
{
if (old_range.min == old_range.max)
{
if (old_range.max <= note->pos.min)
{
note->pos.min = note->pos.min + new_size - (old_range.max - old_range.min);
note->pos.max = note->pos.max + new_size - (old_range.max - old_range.min);
}
}
else
{
if (old_range.min <= note->pos.min && note->pos.min < old_range.max) {
note->pos.min = old_range.first;
} else if (old_range.max <= note->pos.min) {
note->pos.min = note->pos.min + new_size - (old_range.max - old_range.min);
}
if (old_range.min < note->pos.max && note->pos.max <= old_range.max) {
note->pos.max = old_range.first;
} else if (old_range.max <= note->pos.max) {
note->pos.max = note->pos.max + new_size - (old_range.max - old_range.min);
}
}
}
}
function void
code_index_shift(Code_Index_File *file, Range_i64 old_range, u64 new_size)
{
// TODO(PS): @DontShiftNestList - This is unnecessary now that nest_list just gets fully rebuilt each edit
code_index_shift_list(&file->nest_list, old_range, new_size);
code_index_shift_list(&file->scope_delim_list, old_range, new_size);
code_index_shift_list(&file->note_list, old_range, new_size);
}
////////////////////////////////

View File

@ -89,6 +89,12 @@ struct Code_Index_Note_List{
i32 count;
};
struct Code_Index_Note_List_New {
Code_Index_Note sentinel_first;
Code_Index_Note sentinel_last;
i32 count;
};
struct Code_Index_File{
Code_Index_Scope_Delim_List scope_delim_list;
Code_Index_Nest_List nest_list;
@ -96,6 +102,7 @@ struct Code_Index_File{
Buffer_ID buffer;
Code_Index_Scope_Delim* scope_delim_free;
Code_Index_Note* note_free;
String_Pool string_pool;
};
struct Code_Index_File_Storage{
@ -114,7 +121,7 @@ struct Code_Index{
Code_Index_File_Storage *storage_last;
i32 storage_count;
Code_Index_Note_List name_hash[10000];
Code_Index_Note_List_New name_hash[10000];
};
////////////////////////////////

View File

@ -92,7 +92,7 @@ BUFFER_HOOK_SIG(custom_end_buffer){
///////////////////////////////////////////////////////////////////////////
BUFFER_EDIT_RANGE_SIG(custom_buffer_edit_range){
ProfileScope(app, "default edit range");
ProfileScope(app, "custom edit range");
Scratch_Block scratch(app);
Managed_Scope scope = buffer_get_managed_scope(app, buffer_id);
@ -101,6 +101,7 @@ BUFFER_EDIT_RANGE_SIG(custom_buffer_edit_range){
b8 trigger_code_index_update = false;
{ // Tree Sitter
ProfileScope(app, "Tree Sitter Shift");
Buffer_Tree_Sitter_Data* tree_data = scope_attachment(app, scope, buffer_tree_sitter_data_id, Buffer_Tree_Sitter_Data);
// TODO(PS): if there's not tree_data, we actually want to block
@ -142,6 +143,7 @@ BUFFER_EDIT_RANGE_SIG(custom_buffer_edit_range){
buffer_shift_fade_ranges(buffer_id, old_range.max, (new_range.max - old_range.max));
{
ProfileScope(app, "Code Index Shift");
code_index_lock();
Code_Index_File *file = code_index_get_file(buffer_id);
if (file != 0) {

View File

@ -45,10 +45,10 @@ go_to_definition(Application_Links* app, String_Const_u8 lexeme, View_ID view)
// and then loop
if (string_match(go_to_definition_last_lexeme, lexeme))
{
Code_Index_Note_List* list = code_index__list_from_string(lexeme);
Code_Index_Note_List_New* list = code_index__list_from_string(lexeme);
u64 i = 0;
for (Code_Index_Note *it = list->first;
it != 0;
for (Code_Index_Note *it = list->sentinel_first.next_in_hash;
it != &list->sentinel_last;
it = it->next_in_hash, i++){
if (string_match(lexeme, it->text) && i > go_to_definition_last_lexeme_index){
note = it;

View File

@ -19,6 +19,7 @@
#include "4coder_table.h"
#include "4coder_events.h"
#include "4coder_types.h"
#include "4coder_string_pool.h"
#include "4coder_doc_content_types.h"
#include "4coder_default_colors.h"
#define DYNAMIC_LINK_API
@ -30,6 +31,7 @@
#include "generated/command_metadata.h"
#endif
#include "4coder_token.h"
#include "generated/lexer_cpp.h"
@ -73,7 +75,7 @@
#include "4coder_stringf.cpp"
#include "4coder_app_links_allocator.cpp"
#include "4coder_system_allocator.cpp"
#include "4coder_string_pool.cpp"
#include "4coder_file.cpp"
#define DYNAMIC_LINK_API

View File

@ -0,0 +1,129 @@
function void
string_pool_init(String_Pool* pool)
{
pool->free_first.next = &pool->free_last;
pool->free_last.prev = &pool->free_first;
}
function String_Pool_Free_List*
free_string_inner(String_Pool* pool, String_Const_u8 str)
{
String_Pool_Free_List* free_at = (String_Pool_Free_List*)str.str;
free_at->next = 0; free_at->prev = 0;
free_at->size = str.size;
String_Pool_Free_List* prev = 0;
for (String_Pool_Free_List* at = pool->free_first.next; at != &pool->free_last; at = prev->next)
{
u8* addr = (u8*)at;
if (addr < (u8*)free_at) prev = at;
else break;
}
if (prev)
{
String_Pool_Free_List* next = prev->next;
prev->next = free_at;
free_at->prev = prev;
free_at->next = next;
next->prev = free_at;
b8 should_merge = (u8*)prev + prev->size == (u8*)free_at;
if (should_merge) free_at = prev;
}
else
{
String_Pool_Free_List* prev = &pool->free_first;
String_Pool_Free_List* next = pool->free_first.next;
prev->next = free_at;
free_at->prev = prev;
free_at->next = next;
next->prev = free_at;
}
while ((u8*)free_at + free_at->size == (u8*)free_at->next)
{
String_Pool_Free_List* next = free_at->next;
free_at->size += next->size;
next->next->prev = free_at;
free_at->next = next->next;
}
return free_at;
}
function String_Pool_Free_List*
string_pool_push_buffer(String_Pool* pool, int size_provided, Arena* backing_arena)
{
u64 next_buffer_size = pool->last_buffer_size * 2;
if (next_buffer_size == 0) next_buffer_size = KB(4);
String_Const_u8 buffer_data = string_const_u8_push(backing_arena, next_buffer_size);
pool->last_buffer_size = next_buffer_size;
String_Pool_Buffer* buffer = (String_Pool_Buffer*)buffer_data.str;
buffer_data.str += sizeof(String_Pool_Buffer);
buffer_data.size -= sizeof(String_Pool_Buffer);
buffer->data = buffer_data;
buffer->next = pool->buffers;
pool->buffers = buffer;
return free_string_inner(pool, buffer_data);
}
function String_Const_u8
alloc_string(String_Pool* pool, int size_provided, Arena* backing_arena)
{
int size = ((size_provided + STRING_POOL_ALLOC_SIZE - 1) / STRING_POOL_ALLOC_SIZE) * STRING_POOL_ALLOC_SIZE;
String_Pool_Free_List* free_at = pool->free_first.next;
while (free_at != &pool->free_last && free_at->size < size) free_at = free_at->next;
if (free_at == &pool->free_last || free_at->size < size)
{
free_at = string_pool_push_buffer(pool, size, backing_arena);
}
Assert(free_at->size >= size);
String_Const_u8 result;
result.str = (u8*)free_at;
result.size = size;
String_Pool_Free_List* prev = free_at->prev;
String_Pool_Free_List* next = free_at->next;
if (free_at->size - size > 0)
{
u8* new_free_at_ptr = (u8*)free_at;
String_Pool_Free_List* new_free_at = (String_Pool_Free_List*)(new_free_at_ptr + size);
new_free_at->size = free_at->size - size;
prev->next = new_free_at;
new_free_at->prev = prev;
new_free_at->next = next;
next->prev = new_free_at;
}
else
{
prev->next = next;
next->prev = prev;
}
block_zero(result.str, result.size);
return result;
}
function String_Const_u8
alloc_string_copy(String_Pool* pool, String_Const_u8 src, Arena* backing_arena)
{
String_Const_u8 dst = alloc_string(pool, src.size+1, backing_arena);
dst.size = src.size;
block_copy_dynamic_array(dst.str, src.str, src.size);
dst.str[src.size] = 0;
return dst;
}
function void
free_string(String_Pool* pool, String_Const_u8 str)
{
free_string_inner(pool, str);
}

View File

@ -0,0 +1,29 @@
/* date = August 3rd 2025 5:01 pm */
#ifndef FCODER_STRING_POOL_H
#define FCODER_STRING_POOL_H
#define STRING_POOL_ALLOC_SIZE 64
struct String_Pool_Free_List
{
i64 size;
String_Pool_Free_List* next;
String_Pool_Free_List* prev;
};
struct String_Pool_Buffer
{
String_Const_u8 data;
String_Pool_Buffer* next;
};
struct String_Pool
{
String_Pool_Buffer* buffers;
String_Pool_Free_List free_first;
String_Pool_Free_List free_last;
u64 last_buffer_size;
};
#endif //FCODER_STRING_POOL_H

View File

@ -482,6 +482,8 @@ tree_sitter_code_index_update_state_create(
} else {
state.index_arena = make_arena_system(KB(16));
state.index = push_array_zero(&state.index_arena, Code_Index_File, 1);
string_pool_init(&state.index->string_pool);
state.index->buffer = buffer_id;
}
state.buffer_contents = push_whole_buffer(app, scratch, state.buffer_id);
@ -489,9 +491,10 @@ tree_sitter_code_index_update_state_create(
state.nest_stack_last = 0;
state.last_note = 0;
state.last_note_match_id = max_u32;
code_index_note_list_hash_init(&state.new_notes);
state.ok = true;
/* Freeing all delims is undesired for incremental updates, and unnecessary if
/* @RemoveOldFreeingCode = Freeing all delims is undesired for incremental updates, and unnecessary if
we're working with a wholly new index. The same will be true for notes soon.
if (state.index->scope_delim_list.last) {
state.index->scope_delim_list.last->next = state.index->scope_delim_free;
@ -548,40 +551,24 @@ tree_sitter_code_index_update_process_query_match(
state->last_delim = delim;
}
}
else if (string_match(capture_name, SCu8("definition.class")))
{
Code_Index_Note* note = code_index_new_note(state->index, &state->index_arena, CodeIndexNote_Type, type_range, state->nest_stack_last);
state->last_note_match_id = query_match.id;
code_index_note_insert(&state->index->note_list, state->last_note, note);
state->last_note = note;
}
else if (string_match(capture_name, SCu8("definition.function")))
{
Code_Index_Note* note = code_index_new_note(state->index, &state->index_arena, CodeIndexNote_Function, type_range, state->nest_stack_last);
state->last_note_match_id = query_match.id;
code_index_note_insert(&state->index->note_list, state->last_note, note);
state->last_note = note;
}
else if (string_match(capture_name, SCu8("definition.method")))
{
Code_Index_Note* note = code_index_new_note(state->index, &state->index_arena, CodeIndexNote_Function, type_range, state->nest_stack_last);;
state->last_note_match_id = query_match.id;
code_index_note_insert(&state->index->note_list, state->last_note, note);
state->last_note = note;
}
else if (string_match(capture_name, SCu8("definition.type")))
{
Code_Index_Note* note = code_index_new_note(state->index, &state->index_arena, CodeIndexNote_Type, type_range, state->nest_stack_last);
state->last_note_match_id = query_match.id;
code_index_note_insert(&state->index->note_list, state->last_note, note);
state->last_note = note;
}
else if (string_match(capture_name, SCu8("name")))
{
if (state->last_note != 0 && state->last_note_match_id == query_match.id)
{
state->last_note->pos = Ii64_size(type_range.start, type_range.end - type_range.start);
}
Range_i64 range = Ii64_size(type_range.start, type_range.end - type_range.start);
bool apply_name_to_last_note = state->new_notes.sentinel_last.prev_in_hash != 0;
apply_name_to_last_note &= state->last_note_match_id == query_match.id;
if (apply_name_to_last_note) state->new_notes.sentinel_last.prev_in_hash->pos = range;
}
else
{
Code_Index_Note_Kind kind;
if (string_match(capture_name, SCu8("definition.class"))) kind = CodeIndexNote_Type;
else if (string_match(capture_name, SCu8("definition.function"))) kind = CodeIndexNote_Function;
else if (string_match(capture_name, SCu8("definition.method"))) kind = CodeIndexNote_Function;
else if (string_match(capture_name, SCu8("definition.type"))) kind = CodeIndexNote_Type;
Code_Index_Note* note = code_index_new_note(state->index, &state->index_arena, kind, type_range, state->nest_stack_last);
code_index_note_list_hash_append(&state->new_notes, note);
state->last_note_match_id = query_match.id;
}
}
@ -592,6 +579,7 @@ tree_sitter_code_index_update_complete(
Arena* scratch,
bool update_was_incremental
){
ProfileScope(app, "Complete Code Index Update");
if (state->ok)
{
Code_Index_Nest* free_nests = state->index->nest_list.first;
@ -667,11 +655,34 @@ tree_sitter_code_index_update_complete(
delim_at = delim_at->next;
}
// TODO(PS): this should just be for the new notes - if a note wasn't
// updated incrementally this frame, then it already has it's text
for (Code_Index_Note* note = state->index->note_list.first; note != 0 && note->next != note; note = note->next)
{
note->text = push_string_copy(&state->index_arena, string_substring(state->buffer_contents, note->pos));
ProfileScope(app, "Update Global Name Table");
Code_Index_Note* note = state->new_notes.sentinel_first.next_in_hash;
Code_Index_Note* next = 0;
for (int i = 0; i < state->new_notes.count; i++)
{
next = note->next_in_hash;
note->next = 0; note->next_in_hash = 0; note->prev_in_hash = 0;
String_Const_u8 source = string_substring(
state->buffer_contents,
note->pos
);
note->text = alloc_string_copy(
&state->index->string_pool,
source,
&state->index_arena
);
note->file = state->index;
Code_Index_Note_List_New* hash_list = code_index__list_from_string(note->text);
code_index_note_list_hash_append(hash_list, note);
code_index_note_insert(&state->index->note_list, state->last_note, note);
state->last_note = note;
note = next;
}
}
if (!update_was_incremental)
@ -771,14 +782,12 @@ tree_sitter_code_index_update_tick(Application_Links* app)
modified_node != 0;
modified_node = modified_node->next
){
ProfileScope(app, "Incremental Parse");
Buffer_ID buffer_id = modified_node->buffer;
Managed_Scope buffer_scope = buffer_get_managed_scope(app, buffer_id);
Buffer_Tree_Sitter_Data* tree_data = scope_attachment(app, buffer_scope, buffer_tree_sitter_data_id, Buffer_Tree_Sitter_Data);
if (!tree_data || !tree_data->tree) continue;
Buffer_ID out_buffer = get_buffer_by_name(app, string_u8_litexpr("*tree*"), Access_Always);
buffer_replace_range(app, out_buffer, Ii64(0,buffer_get_size(app, out_buffer)), SCu8(""));
Range_i64 old_range = tree_data->last_update_old_range;
Range_i64 new_range = tree_data->last_update_new_range;
if (old_range == new_range) continue;
@ -877,94 +886,102 @@ tree_sitter_code_index_update_tick(Application_Links* app)
tree_data->last_update_node_range = edit_range; // TODO(PS): TEMP - remove me once debugging is done
// Free Scope Delimiters that fall within old_range
Code_Index_Scope_Delim* delim = state.index->scope_delim_list.first;
Code_Index_Scope_Delim* delim_before_range = 0;
Code_Index_Scope_Delim* after_range = 0;
while (delim)
{
Code_Index_Scope_Delim* next = delim->next;
if (delim->pos.min < edit_range.min && delim->pos.max <= edit_range.min)
ProfileScope(app, "Free Scope Delimiters");
Code_Index_Scope_Delim* delim = state.index->scope_delim_list.first;
Code_Index_Scope_Delim* delim_before_range = 0;
Code_Index_Scope_Delim* after_range = 0;
while (delim)
{
delim_before_range = delim;
Code_Index_Scope_Delim* next = delim->next;
if (delim->pos.min < edit_range.min && delim->pos.max <= edit_range.min)
{
delim_before_range = delim;
}
if (range_overlap(delim->pos, edit_range))
{
state.index->scope_delim_list.count -= 1;
zdll_remove(
state.index->scope_delim_list.first,
state.index->scope_delim_list.last,
delim
);
code_index_free_scope_delim(state.index, delim);
}
if (delim->pos.min >= edit_range.max) break;
delim = next;
}
if (range_overlap(delim->pos, edit_range))
{
state.index->scope_delim_list.count -= 1;
zdll_remove(
state.index->scope_delim_list.first,
state.index->scope_delim_list.last,
delim
);
code_index_free_scope_delim(state.index, delim);
}
if (delim->pos.min >= edit_range.max) break;
delim = next;
state.last_delim = delim_before_range;
}
state.last_delim = delim_before_range;
// Free Scope Notes that fall within old_range
Code_Index_Note* note = state.index->note_list.first;
Code_Index_Note* prev = 0;
Code_Index_Note* note_before_range = 0;
while (note)
{
Code_Index_Note* next = note->next;
if (note->pos.min < edit_range.min && note->pos.max <= edit_range.min)
ProfileScope(app, "Free Notes");
Code_Index_Note* note = state.index->note_list.first;
Code_Index_Note* prev = 0;
Code_Index_Note* note_before_range = 0;
while (note)
{
note_before_range = note;
}
if (range_overlap(note->pos, edit_range))
{
Code_Index_Note* new_first = state.index->note_list.first;
Code_Index_Note* new_last = state.index->note_list.last;
Code_Index_Note* new_next = next;
if (note == state.index->note_list.first) new_first = next;
if (note == state.index->note_list.last)
Code_Index_Note* next = note->next;
if (note->pos.min < edit_range.min && note->pos.max <= edit_range.min)
{
if (prev) new_last = prev;
else new_last = 0;
note_before_range = note;
}
if (range_overlap(note->pos, edit_range))
{
Code_Index_Note* new_first = state.index->note_list.first;
Code_Index_Note* new_last = state.index->note_list.last;
Code_Index_Note* new_next = next;
if (new_first == 0) Assert(new_last == 0 && state.index->note_list.count == 1);
if (note == state.index->note_list.first) new_first = next;
if (note == state.index->note_list.last)
{
if (prev) new_last = prev;
else new_last = 0;
}
state.index->note_list.count -= 1;
state.index->note_list.first = new_first;
state.index->note_list.last = new_last;
if (prev) prev->next = new_next;
code_index_free_note(state.index, note);
if (new_first == 0) Assert(new_last == 0 && state.index->note_list.count == 1);
Code_Index_Note_List_New* list = code_index__list_from_string(note->text);
code_index_note_list_hash_remove(list, note);
free_string(&state.index->string_pool, note->text);
state.index->note_list.count -= 1;
state.index->note_list.first = new_first;
state.index->note_list.last = new_last;
if (prev) prev->next = new_next;
code_index_free_note(state.index, note);
}
else
{
prev = note;
}
if (note->pos.min >= edit_range.max) break;
note = next;
}
else
{
prev = note;
}
if (note->pos.min >= edit_range.max) break;
note = next;
state.last_note = note_before_range;
if (state.index->note_list.count == 0) Assert(state.index->note_list.first == 0 && state.index->note_list.first == 0);
}
state.last_note = note_before_range;
if (state.index->note_list.count == 0) Assert(state.index->note_list.first == 0 && state.index->note_list.first == 0);
for (int i = 0; i < query_count; i++)
{
Tree_Sitter_Query_Cursor query = queries[i];
TSQueryMatch query_match;
u32 capture_index;
while (state.ok && tree_sitter_query_continue(&query, &query_match, &capture_index))
ProfileScope(app, "Perform Query");
for (int i = 0; i < query_count; i++)
{
tree_sitter_code_index_update_process_query_match(
&state, query, query_match, capture_index, scratch
);
Tree_Sitter_Query_Cursor query = queries[i];
TSQueryMatch query_match;
u32 capture_index;
while (state.ok && tree_sitter_query_continue(&query, &query_match, &capture_index))
{
tree_sitter_code_index_update_process_query_match(
&state, query, query_match, capture_index, scratch
);
}
tree_sitter_query_end(&query);
}
tree_sitter_query_end(&query);
}
tree_sitter_code_index_update_complete(app, &state, scratch, true);
// @Report
for (Code_Index_Note* note = state.index->note_list.first; note != 0; note = note->next)
{
String_Const_u8 string = push_stringf(scratch, "Note: '%.*s'\n", string_expand(note->text));
buffer_replace_range(app, out_buffer, Ii64(buffer_get_size(app, out_buffer)), string);
}
}
buffer_modified_set_clear();

View File

@ -92,6 +92,8 @@ struct Tree_Sitter_Code_Index_Update_State
Arena index_arena;
Code_Index_File* index;
Code_Index_Note_List_New new_notes;
Code_Index_Nest_Stack* nest_stack_first = 0;
Code_Index_Nest_Stack* nest_stack_last = 0;