diff --git a/code/custom/4coder_custom_hooks.cpp b/code/custom/4coder_custom_hooks.cpp index 83fd358a..fa94de59 100644 --- a/code/custom/4coder_custom_hooks.cpp +++ b/code/custom/4coder_custom_hooks.cpp @@ -35,9 +35,8 @@ BUFFER_HOOK_SIG(custom_begin_buffer){ if (treat_as_code) { - // TODO(PS): @AsyncrifyThis??? - tree_sitter_parse_incremental(app, buffer_id); - tree_sitter_code_index_update_full_file(app, buffer_id); + Async_Task* parse_task_ptr = scope_attachment(app, scope, buffer_parse_task, Async_Task); + *parse_task_ptr = async_task_no_dep(&global_async_system, tree_sitter_parse_full_file_async, make_data_struct(&buffer_id)); } String_Const_u8 buffer_name = push_buffer_base_name(app, scratch, buffer_id); diff --git a/code/custom/4coder_tree_sitter.cpp b/code/custom/4coder_tree_sitter.cpp index 82e35dfc..72231c95 100644 --- a/code/custom/4coder_tree_sitter.cpp +++ b/code/custom/4coder_tree_sitter.cpp @@ -325,6 +325,10 @@ tree_sitter_parse_full_file_async(Async_Context* actx, String_Const_u8 data) ts_tree_delete(old_buffer_tree); } tree_sitter_parse_state_destroy(&parse_state); + + Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); + Async_Task* code_index_update_task_ptr = scope_attachment(app, scope, buffer_update_code_index_task, Async_Task); + *code_index_update_task_ptr = async_task_no_dep(&global_async_system, tree_sitter_code_index_update_async, make_data_struct(&buffer_id)); } function void @@ -779,6 +783,16 @@ tree_sitter_code_index_update_tick(Application_Links* app) ProfileScope(app, "Incremental Parse"); Buffer_ID buffer_id = modified_node->buffer; Managed_Scope buffer_scope = buffer_get_managed_scope(app, buffer_id); + + Async_Task* async_parse_task = scope_attachment(app, buffer_scope, buffer_parse_task, Async_Task); + Async_Task* async_code_index_update_task = scope_attachment(app, buffer_scope, buffer_update_code_index_task, Async_Task); + if (async_task_is_running_or_pending(&global_async_system, *async_parse_task)) { + async_task_wait(app, &global_async_system, *async_parse_task); + } + if (async_task_is_running_or_pending(&global_async_system, *async_code_index_update_task)) { + async_task_wait(app, &global_async_system, *async_code_index_update_task); + } + 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; diff --git a/code/custom/4coder_tree_sitter.h b/code/custom/4coder_tree_sitter.h index 72fdb6e0..700233bb 100644 --- a/code/custom/4coder_tree_sitter.h +++ b/code/custom/4coder_tree_sitter.h @@ -105,8 +105,8 @@ struct Tree_Sitter_Code_Index_Update_State global Tree_Sitter_Languages tree_sitter_languages; CUSTOM_ID(attachment, buffer_tree_sitter_data_id); -CUSTOM_ID(attachment, buffer_tree_sitter_parse_task_id); -CUSTOM_ID(attachment, buffer_tree_sitter_update_code_index_task_id); +CUSTOM_ID(attachment, buffer_parse_task); +CUSTOM_ID(attachment, buffer_update_code_index_task); b8 use_tree_sitter_code_indexing = true; b8 use_tree_sitter_token_coloring = true;