From 001cf5fa576556c4fb01a4451a1a029dc86fd85a Mon Sep 17 00:00:00 2001 From: PS Date: Mon, 13 May 2024 17:10:09 -0700 Subject: [PATCH] Buffer name resolution simply appends a project relative path for files inside the project and a global path for files outside. --- .gitignore | 1 + TODO.md | 2 + code/custom/4coder_default_hooks.cpp | 362 ++++++++++++++++----------- 3 files changed, 216 insertions(+), 149 deletions(-) diff --git a/.gitignore b/.gitignore index ee3b4331..7d15db09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ current_dist*/ distributions/ +build_stable/ diff --git a/TODO.md b/TODO.md index 1bd26681..828df4dd 100644 --- a/TODO.md +++ b/TODO.md @@ -10,11 +10,13 @@ PRIME DIRECTIVE: SIMPLIFY [] Look into removing *keyboard* buffer - seems like over long sessions, that could get out of hand - good first step: print out the memory footprint of this buffer when we exit 4coder, just so we can see what it's taking up [] multi cursor editing +[] matching curly brace highlight ## Investigations [] What are fade ranges? Do we need them? # DONE +[x] when buffers have the same filename, a short name is appended. I'd prefer to append the path relative to the project, and if the file is outside the project, append the full path. [x] reload dirty files if there are no local edits to them automatically [x] remove audio (search @Remove) [x] backspace through entire filename in navigation strip at top diff --git a/code/custom/4coder_default_hooks.cpp b/code/custom/4coder_default_hooks.cpp index 17c61100..ba0ba387 100644 --- a/code/custom/4coder_default_hooks.cpp +++ b/code/custom/4coder_default_hooks.cpp @@ -13,25 +13,25 @@ CUSTOM_DOC("Default command for responding to a startup event") String_Const_u8_Array file_names = input.event.core.file_names; load_themes_default_folder(app); default_4coder_initialize(app, file_names); - + // Setup Default Layout Buffer_ID comp_buffer = create_buffer(app, str8_lit("*compilation*"), BufferCreate_NeverAttachToFile | BufferCreate_AlwaysNew); buffer_set_setting(app, comp_buffer, BufferSetting_Unimportant, true); buffer_set_setting(app, comp_buffer, BufferSetting_ReadOnly, true); - + Buffer_Identifier comp_name = buffer_identifier(str8_lit("*compilation*")); Buffer_Identifier code_left_name = buffer_identifier(str8_lit("*scratch*")); Buffer_Identifier code_right_name = buffer_identifier(str8_lit("*messages*")); - + Buffer_ID comp_id = buffer_identifier_to_id(app, comp_name); Buffer_ID code_left_id = buffer_identifier_to_id(app, code_left_name); Buffer_ID code_right_id = buffer_identifier_to_id(app, code_right_name); - + // Left Panel View_ID left_view = get_active_view(app, Access_Always); new_view_settings(app, left_view); view_set_buffer(app, left_view, code_left_id, 0); - + // Bottom panel View_ID compilation_view = 0; compilation_view = open_view(app, left_view, ViewSplit_Bottom); @@ -43,20 +43,20 @@ CUSTOM_DOC("Default command for responding to a startup event") view_set_passive(app, compilation_view, true); global_compilation_view = compilation_view; view_set_buffer(app, compilation_view, comp_id, 0); - + // Right Panel view_set_active(app, left_view); open_panel_vsplit(app); View_ID right_view = get_active_view(app, Access_Always); - view_set_buffer(app, right_view, code_right_id, 0); + view_set_buffer(app, right_view, code_right_id, 0); view_set_active(app, left_view); } - + { def_enable_virtual_whitespace = def_get_config_b32(vars_save_string_lit("enable_virtual_whitespace")); clear_all_layouts(app); } - + system_set_fullscreen(false); } @@ -91,18 +91,18 @@ CUSTOM_DOC("Default command for responding to a try-exit event") function Implicit_Map_Result default_implicit_map(Application_Links *app, String_ID lang, String_ID mode, Input_Event *event){ Implicit_Map_Result result = {}; - + View_ID view = get_this_ctx_view(app, Access_Always); - + Command_Map_ID map_id = default_get_map_id(app, view); Modal_Mode* mode_curr = modal_get_mode_curr(); Mapping* mode_map = &mode_curr->map; Command_Binding binding = map_get_binding_recursive(mode_map, map_id, event); - + // TODO(allen): map_id <-> map name? result.map = 0; result.command = binding.custom; - + return(result); } @@ -111,24 +111,24 @@ CUSTOM_DOC("Input consumption loop for default view behavior") { Scratch_Block scratch(app); default_input_handler_init(app, scratch); - + View_ID view = get_this_ctx_view(app, Access_Always); Managed_Scope scope = view_get_managed_scope(app, view); - + for (;;){ User_Input input = get_next_input(app, EventPropertyGroup_Any, 0); if (input.abort){ break; } - + ProfileScopeNamed(app, "before view input", view_input_profile); - + // NOTE(allen): Mouse Suppression Event_Property event_properties = get_event_properties(&input.event); if (suppressing_mouse && (event_properties & EventPropertyGroup_AnyMouseEvent) != 0){ continue; } - + // NOTE(allen): Get binding if (implicit_map_function == 0){ implicit_map_function = default_implicit_map; @@ -138,7 +138,7 @@ CUSTOM_DOC("Input consumption loop for default view behavior") leave_current_input_unhandled(app); continue; } - + // NOTE(allen): Run the command and pre/post command stuff default_pre_command(app, scope); ProfileCloseNow(view_input_profile); @@ -156,17 +156,17 @@ code_index_update_tick(Application_Links *app){ node = node->next){ Temp_Memory_Block temp(scratch); Buffer_ID buffer_id = node->buffer; - + String_Const_u8 contents = push_whole_buffer(app, scratch, buffer_id); Token_Array tokens = get_token_array_from_buffer(app, buffer_id); if (tokens.count == 0){ continue; } - + Arena arena = make_arena_system(KB(16)); Code_Index_File *index = push_array_zero(&arena, Code_Index_File, 1); index->buffer = buffer_id; - + Generic_Parse_State state = {}; generic_parse_init(app, &arena, contents, &tokens, &state); // TODO(allen): Actually determine this in a fair way. @@ -174,13 +174,13 @@ code_index_update_tick(Application_Links *app){ // Actually probably a pointer to a struct that defines the language. state.do_cpp_parse = true; generic_parse_full_input_breaks(index, &state, max_i32); - + code_index_lock(); code_index_set_file(buffer_id, arena, index); code_index_unlock(); buffer_clear_layout_cache(app, buffer_id); } - + buffer_modified_set_clear(); } @@ -189,10 +189,10 @@ function void reload_clean_buffers_on_filesystem_change(Application_Links *app, Frame_Info frame_info) { time_since_last_dirty_buffers_check += frame_info.literal_dt; - if (time_since_last_dirty_buffers_check > 1) + if (time_since_last_dirty_buffers_check > 1) { time_since_last_dirty_buffers_check = 0; - 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)) { Dirty_State dirty = buffer_get_dirty_state(app, buffer); @@ -206,11 +206,11 @@ reload_clean_buffers_on_filesystem_change(Application_Links *app, Frame_Info fra function void default_tick(Application_Links *app, Frame_Info frame_info){ code_index_update_tick(app); - + if (tick_all_fade_ranges(app, frame_info.animation_dt)){ animate_in_n_milliseconds(app, 0); } - + { // Clear layouts if virtual whitespace setting changed b32 enable_virtual_whitespace = def_get_config_b32(vars_save_string_lit("enable_virtual_whitespace")); if (enable_virtual_whitespace != def_enable_virtual_whitespace){ @@ -218,7 +218,7 @@ default_tick(Application_Links *app, Frame_Info frame_info){ clear_all_layouts(app); } } - + reload_clean_buffers_on_filesystem_change(app, frame_info); } @@ -229,10 +229,10 @@ default_buffer_region(Application_Links *app, View_ID view_id, Rect_f32 region){ Face_Metrics metrics = get_face_metrics(app, face_id); f32 line_height = metrics.line_height; f32 digit_advance = metrics.decimal_digit_advance; - + // NOTE(allen): margins region = rect_inner(region, 3.f); - + // NOTE(allen): file bar b64 showing_file_bar = false; if (view_get_setting(app, view_id, ViewSetting_ShowFileBar, &showing_file_bar) && @@ -240,7 +240,7 @@ default_buffer_region(Application_Links *app, View_ID view_id, Rect_f32 region){ Rect_f32_Pair pair = layout_file_bar_on_top(region, line_height); region = pair.max; } - + // NOTE(allen): query bars { Query_Bar *space[32]; @@ -251,20 +251,20 @@ default_buffer_region(Application_Links *app, View_ID view_id, Rect_f32 region){ region = pair.max; } } - + // NOTE(allen): FPS hud if (show_fps_hud){ Rect_f32_Pair pair = layout_fps_hud_on_bottom(region, line_height); region = pair.min; } - + // NOTE(allen): line numbers b32 show_line_number_margins = def_get_config_b32(vars_save_string_lit("show_line_number_margins")); if (show_line_number_margins){ Rect_f32_Pair pair = layout_line_number_margin(app, buffer, region, digit_advance); region = pair.max; } - + return(region); } @@ -273,7 +273,7 @@ recursive_nest_highlight(Application_Links *app, Text_Layout_ID layout_id, Range Code_Index_Nest_Ptr_Array *array, i32 counter){ Code_Index_Nest **ptr = array->ptrs; Code_Index_Nest **ptr_end = ptr + array->count; - + for (;ptr < ptr_end; ptr += 1){ Code_Index_Nest *nest = *ptr; if (!nest->is_closed){ @@ -283,15 +283,15 @@ recursive_nest_highlight(Application_Links *app, Text_Layout_ID layout_id, Range break; } } - + ARGB_Color argb = finalize_color(defcolor_text_cycle, counter); - + for (;ptr < ptr_end; ptr += 1){ Code_Index_Nest *nest = *ptr; if (range.max <= nest->open.min){ break; } - + paint_text_color(app, layout_id, nest->open, argb); if (nest->is_closed){ paint_text_color(app, layout_id, nest->close, argb); @@ -311,24 +311,24 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, Buffer_ID buffer, Text_Layout_ID text_layout_id, Rect_f32 rect){ ProfileScope(app, "render buffer"); - + View_ID active_view = get_active_view(app, Access_Always); b32 is_active_view = (active_view == view_id); Rect_f32 prev_clip = draw_set_clip(app, rect); - + Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id); - + // NOTE(allen): Cursor shape Face_Metrics metrics = get_face_metrics(app, face_id); u64 cursor_roundness_100 = def_get_config_u64(app, vars_save_string_lit("cursor_roundness")); f32 cursor_roundness = metrics.normal_advance*cursor_roundness_100*0.01f; f32 mark_thickness = (f32)def_get_config_u64(app, vars_save_string_lit("mark_thickness")); - + // NOTE(allen): Token colorizing Token_Array token_array = get_token_array_from_buffer(app, buffer); if (token_array.tokens != 0){ draw_cpp_token_colors(app, text_layout_id, &token_array); - + // NOTE(allen): Scan for TODOs and NOTEs b32 use_comment_keyword = def_get_config_b32(vars_save_string_lit("use_comment_keyword")); if (use_comment_keyword){ @@ -338,15 +338,15 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, }; draw_comment_highlights(app, buffer, text_layout_id, &token_array, pairs, ArrayCount(pairs)); } - + // NOTE(allen): Color functions Scratch_Block scratch(app); - + ARGB_Color color_function = fcolor_resolve(fcolor_id(defcolor_function)); ARGB_Color color_operator = fcolor_resolve(fcolor_id(defcolor_operator)); ARGB_Color color_type = fcolor_resolve(fcolor_id(defcolor_type)); ARGB_Color color_macro = fcolor_resolve(fcolor_id(defcolor_macro)); - + Token_Iterator_Array it = token_iterator_pos(0, &token_array, visible_range.first); for (;;){ if (!token_it_inc_non_whitespace(&it)){ @@ -363,21 +363,21 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, { paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), color_type); } break; - + case CodeIndexNote_Function: { paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), color_function); } break; - + case CodeIndexNote_Macro: { paint_text_color(app, text_layout_id, Ii64_size(token->pos, token->size), color_macro); } break; - + default: {} break; } } - + else if (token->kind == TokenBaseKind_Operator || token->kind == TokenBaseKind_ScopeOpen || token->kind == TokenBaseKind_ScopeClose || @@ -392,17 +392,17 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, else{ paint_text_color_fcolor(app, text_layout_id, visible_range, fcolor_id(defcolor_text_default)); } - + i64 cursor_pos = view_correct_cursor(app, view_id); view_correct_mark(app, view_id); - + // NOTE(allen): Scope highlight b32 use_scope_highlight = def_get_config_b32(vars_save_string_lit("use_scope_highlight")); if (use_scope_highlight){ Color_Array colors = finalize_color_array(defcolor_back_cycle); draw_scope_highlight(app, buffer, text_layout_id, cursor_pos, colors.vals, colors.count); } - + b32 use_error_highlight = def_get_config_b32(vars_save_string_lit("use_error_highlight")); b32 use_jump_highlight = def_get_config_b32(vars_save_string_lit("use_jump_highlight")); if (use_error_highlight || use_jump_highlight){ @@ -413,7 +413,7 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, draw_jump_highlights(app, buffer, text_layout_id, compilation_buffer, fcolor_id(defcolor_highlight_junk)); } - + // NOTE(allen): Search highlight if (use_jump_highlight){ Buffer_ID jump_buffer = get_locked_jump_buffer(app); @@ -423,21 +423,21 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, } } } - + // NOTE(allen): Color parens b32 use_paren_helper = def_get_config_b32(vars_save_string_lit("use_paren_helper")); if (use_paren_helper){ Color_Array colors = finalize_color_array(defcolor_text_cycle); draw_paren_highlight(app, buffer, text_layout_id, cursor_pos, colors.vals, colors.count); } - + // NOTE(allen): Line highlight b32 highlight_line_at_cursor = def_get_config_b32(vars_save_string_lit("highlight_line_at_cursor")); if (highlight_line_at_cursor && is_active_view){ i64 line_number = get_line_number_from_pos(app, buffer, cursor_pos); draw_line_highlight(app, text_layout_id, line_number, fcolor_id(defcolor_highlight_cursor_line)); } - + // NOTE(allen): Whitespace highlight b64 show_whitespace = false; view_get_setting(app, view_id, ViewSetting_ShowWhitespace, &show_whitespace); @@ -449,7 +449,7 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, draw_whitespace_highlight(app, text_layout_id, &token_array, cursor_roundness); } } - + // NOTE(allen): Cursor switch (fcoder_mode){ case FCoderMode_Original: @@ -461,13 +461,13 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, draw_notepad_style_cursor_highlight(app, view_id, buffer, text_layout_id, cursor_roundness); }break; } - + // NOTE(allen): Fade ranges paint_fade_ranges(app, text_layout_id, buffer); - + // NOTE(allen): put the actual text on the actual screen draw_text_layout_default(app, text_layout_id); - + draw_set_clip(app, prev_clip); } @@ -475,7 +475,7 @@ function Rect_f32 default_draw_query_bars(Application_Links *app, Rect_f32 region, View_ID view_id, Face_ID face_id){ Face_Metrics face_metrics = get_face_metrics(app, face_id); f32 line_height = face_metrics.line_height; - + Query_Bar *space[32]; Query_Bar_Ptr_Array query_bars = {}; query_bars.ptrs = space; @@ -494,16 +494,16 @@ default_render_caller(Application_Links *app, Frame_Info frame_info, View_ID vie ProfileScope(app, "default render caller"); View_ID active_view = get_active_view(app, Access_Always); b32 is_active_view = (active_view == view_id); - + Rect_f32 region = draw_background_and_margin(app, view_id, is_active_view); Rect_f32 prev_clip = draw_set_clip(app, region); - + Buffer_ID buffer = view_get_buffer(app, view_id, Access_Always); Face_ID face_id = get_face_id(app, buffer); Face_Metrics face_metrics = get_face_metrics(app, face_id); f32 line_height = face_metrics.line_height; f32 digit_advance = face_metrics.decimal_digit_advance; - + // NOTE(allen): file bar b64 showing_file_bar = false; if (view_get_setting(app, view_id, ViewSetting_ShowFileBar, &showing_file_bar) && showing_file_bar){ @@ -511,9 +511,9 @@ default_render_caller(Application_Links *app, Frame_Info frame_info, View_ID vie draw_file_bar(app, view_id, buffer, face_id, pair.min); region = pair.max; } - + Buffer_Scroll scroll = view_get_buffer_scroll(app, view_id); - + Buffer_Point_Delta_Result delta = delta_apply(app, view_id, frame_info.animation_dt, scroll); if (!block_match_struct(&scroll.position, &delta.point)){ @@ -523,10 +523,10 @@ default_render_caller(Application_Links *app, Frame_Info frame_info, View_ID vie if (delta.still_animating){ animate_in_n_milliseconds(app, 0); } - + // NOTE(allen): query bars region = default_draw_query_bars(app, region, view_id, face_id); - + // NOTE(allen): FPS hud if (show_fps_hud){ Rect_f32_Pair pair = layout_fps_hud_on_bottom(region, line_height); @@ -534,7 +534,7 @@ default_render_caller(Application_Links *app, Frame_Info frame_info, View_ID vie region = pair.min; animate_in_n_milliseconds(app, 1000); } - + // NOTE(allen): layout line numbers b32 show_line_number_margins = def_get_config_b32(vars_save_string_lit("show_line_number_margins")); Rect_f32 line_number_rect = {}; @@ -543,19 +543,19 @@ default_render_caller(Application_Links *app, Frame_Info frame_info, View_ID vie line_number_rect = pair.min; region = pair.max; } - + // NOTE(allen): begin buffer render Buffer_Point buffer_point = scroll.position; Text_Layout_ID text_layout_id = text_layout_create(app, buffer, region, buffer_point); - + // NOTE(allen): draw line numbers if (show_line_number_margins){ draw_line_number_margin(app, view_id, buffer, face_id, text_layout_id, line_number_rect); } - + // NOTE(allen): draw the buffer default_render_buffer(app, view_id, face_id, buffer, text_layout_id, region); - + text_layout_free(app, text_layout_id); draw_set_clip(app, prev_clip); } @@ -574,13 +574,13 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ if (conflict_count > 1){ // List of unresolved conflicts Scratch_Block scratch(app); - + i32 *unresolved = push_array(scratch, i32, conflict_count); i32 unresolved_count = conflict_count; for (i32 i = 0; i < conflict_count; ++i){ unresolved[i] = i; } - + // Resolution Loop i32 x = 0; for (;;){ @@ -589,16 +589,16 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ for (i32 i = 0; i < unresolved_count; ++i){ i32 conflict_index = unresolved[i]; Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index]; - + u64 size = conflict->base_name.size; size = clamp_top(size, conflict->unique_name_capacity); conflict->unique_name_len_in_out = size; block_copy(conflict->unique_name_in_out, conflict->base_name.str, size); - + if (conflict->file_name.str != 0){ Temp_Memory_Block temp(scratch); String_Const_u8 uniqueifier = {}; - + String_Const_u8 file_name = string_remove_last_folder(conflict->file_name); if (file_name.size > 0){ file_name = string_chop(file_name, 1); @@ -617,7 +617,7 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ } } u8 *start = file_name.str + file_name.size; - + uniqueifier = SCu8(start, end); if (past_the_end){ uniqueifier = push_u8_stringf(scratch, "%.*s~%d", @@ -627,7 +627,7 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ else{ uniqueifier = push_u8_stringf(scratch, "%d", i); } - + String_u8 builder = Su8(conflict->unique_name_in_out, conflict->unique_name_len_in_out, conflict->unique_name_capacity); @@ -637,7 +637,7 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ conflict->unique_name_len_in_out = builder.size; } } - + // Conflict Check Pass b32 has_conflicts = false; for (i32 i = 0; i < unresolved_count; ++i){ @@ -645,25 +645,25 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index]; String_Const_u8 conflict_name = SCu8(conflict->unique_name_in_out, conflict->unique_name_len_in_out); - + b32 hit_conflict = false; if (conflict->file_name.str != 0){ for (i32 j = 0; j < unresolved_count; ++j){ if (i == j) continue; - + i32 conflict_j_index = unresolved[j]; Buffer_Name_Conflict_Entry *conflict_j = &conflicts[conflict_j_index]; - + String_Const_u8 conflict_name_j = SCu8(conflict_j->unique_name_in_out, conflict_j->unique_name_len_in_out); - + if (string_match(conflict_name, conflict_name_j)){ hit_conflict = true; break; } } } - + if (hit_conflict){ has_conflicts = true; } @@ -673,7 +673,7 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ --i; } } - + if (!has_conflicts){ break; } @@ -681,21 +681,85 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){ } } +BUFFER_NAME_RESOLVER_SIG(gs_buffer_name_resolution) +{ + if (conflict_count <= 1) return; + Scratch_Block scratch(app); + + Variable_Handle prj_var = vars_read_key(vars_get_root(), vars_save_string_lit("prj_config")); + String8 prj_dir = prj_path_from_project(scratch, prj_var); + u8 path_divider = '\\'; + u64 prj_dir_slash_index = string_find_first_slash(prj_dir); + if (prj_dir_slash_index < prj_dir.size) path_divider = prj_dir.str[prj_dir_slash_index]; + + for (int i = 0; i < conflict_count; i++) + { + Buffer_Name_Conflict_Entry *conflict = &conflicts[i]; + String_Const_u8 file_name = conflict->file_name; + String_Const_u8 uniqueifier; + + // Convert the file_name_prefix to have the same path divider as prj_dir + String_Const_u8 file_name_prefix = push_string_copy(scratch, string_prefix(file_name, prj_dir.size)); + for (int j = 0; j < file_name_prefix.size; j++) + { + if (character_is_slash(file_name_prefix.str[j])) file_name_prefix.str[j] = path_divider; + } + + // If the full path to the file matches the project path, + // append a project local unique identifier to the filename + // otherwise, simply add on the full path to the file + if (string_match(file_name_prefix, prj_dir)) + { + String_Const_u8 file_name_minus_prj_dir = string_skip(file_name, prj_dir.size); + uniqueifier = file_name_minus_prj_dir; + } + else + { + uniqueifier = file_name; + } + + String_u8 builder = Su8(conflict->unique_name_in_out, + conflict->unique_name_len_in_out, + conflict->unique_name_capacity); + string_append(&builder, string_u8_litexpr(" <")); + string_append(&builder, uniqueifier); + string_append(&builder, string_u8_litexpr(">")); + conflict->unique_name_len_in_out = builder.size; + } + + // double check that each previously conflicting filename is unique + // on a conflict, fall back to the full system path + for (int i = 0; i < conflict_count - 1; i++) + { + String_Const_u8 unique_name_i = SCu8(conflicts[i].unique_name_in_out, conflicts[i].unique_name_len_in_out); + for (int j = i + 1; j < conflict_count; j++) + { + String_Const_u8 unique_name_j = SCu8(conflicts[j].unique_name_in_out, conflicts[j].unique_name_len_in_out); + if (string_match(unique_name_i, unique_name_j)) + { + print_message(app, string_u8_litexpr("Unable to provide a unique name for a file. Falling back to its full system path")); + Assert(conflicts[j].file_name.size <= conflicts[j].unique_name_capacity); + block_copy(conflicts[j].unique_name_in_out, conflicts[j].file_name.str, conflicts[j].file_name.size); + } + } + } +} + function void parse_async__inner(Async_Context *actx, Buffer_ID buffer_id, String_Const_u8 contents, Token_Array *tokens, i32 limit_factor){ Application_Links *app = actx->app; ProfileBlock(app, "async parse"); - + Arena arena = make_arena_system(KB(16)); Code_Index_File *index = push_array_zero(&arena, Code_Index_File, 1); index->buffer = buffer_id; - + Generic_Parse_State state = {}; generic_parse_init(app, &arena, contents, tokens, &state); - + b32 canceled = false; - + for (;;){ if (generic_parse_full_input_breaks(index, &state, limit_factor)){ break; @@ -705,7 +769,7 @@ parse_async__inner(Async_Context *actx, Buffer_ID buffer_id, break; } } - + if (!canceled){ acquire_global_frame_mutex(app); code_index_lock(); @@ -724,7 +788,7 @@ do_full_lex_async__inner(Async_Context *actx, Buffer_ID buffer_id){ Application_Links *app = actx->app; ProfileScope(app, "async lex"); Scratch_Block scratch(app); - + String_Const_u8 contents = {}; { ProfileBlock(app, "async lex contents (before mutex)"); @@ -733,12 +797,12 @@ do_full_lex_async__inner(Async_Context *actx, Buffer_ID buffer_id){ contents = push_whole_buffer(app, scratch, buffer_id); release_global_frame_mutex(app); } - + i32 limit_factor = 10000; - + Token_List list = {}; b32 canceled = false; - + Lex_State_Cpp state = {}; lex_full_input_cpp_init(&state, contents); for (;;){ @@ -751,7 +815,7 @@ do_full_lex_async__inner(Async_Context *actx, Buffer_ID buffer_id){ break; } } - + if (!canceled){ ProfileBlock(app, "async lex save results (before mutex)"); acquire_global_frame_mutex(app); @@ -783,9 +847,9 @@ do_full_lex_async(Async_Context *actx, String_Const_u8 data){ BUFFER_HOOK_SIG(default_begin_buffer){ ProfileScope(app, "begin buffer"); - + Scratch_Block scratch(app); - + b32 treat_as_code = false; String_Const_u8 file_name = push_buffer_file_name(app, scratch, buffer_id); if (file_name.size > 0){ @@ -799,19 +863,19 @@ BUFFER_HOOK_SIG(default_begin_buffer){ } } } - + String_ID file_map_id = vars_save_string_lit("keys_file"); String_ID code_map_id = vars_save_string_lit("keys_code"); - + Command_Map_ID map_id = (treat_as_code)?(code_map_id):(file_map_id); Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); Command_Map_ID *map_id_ptr = scope_attachment(app, scope, buffer_map_id, Command_Map_ID); *map_id_ptr = map_id; - + Line_Ending_Kind setting = guess_line_ending_kind_from_buffer(app, buffer_id); Line_Ending_Kind *eol_setting = scope_attachment(app, scope, buffer_eol_setting, Line_Ending_Kind); *eol_setting = setting; - + // NOTE(allen): Decide buffer settings b32 wrap_lines = true; b32 use_lexer = false; @@ -820,23 +884,23 @@ BUFFER_HOOK_SIG(default_begin_buffer){ // TODO(PS): @Remove - consider removing the lexer for now? later, replace in favor of tree-sitter use_lexer = true; } - + String_Const_u8 buffer_name = push_buffer_base_name(app, scratch, buffer_id); if (buffer_name.size > 0 && buffer_name.str[0] == '*' && buffer_name.str[buffer_name.size - 1] == '*'){ wrap_lines = def_get_config_b32(vars_save_string_lit("enable_output_wrapping")); } - + if (use_lexer){ ProfileBlock(app, "begin buffer kick off lexer"); Async_Task *lex_task_ptr = scope_attachment(app, scope, buffer_lex_task, Async_Task); *lex_task_ptr = async_task_no_dep(&global_async_system, do_full_lex_async, make_data_struct(&buffer_id)); } - + { b32 *wrap_lines_ptr = scope_attachment(app, scope, buffer_wrap_lines, b32); *wrap_lines_ptr = wrap_lines; } - + if (use_lexer){ buffer_set_layout(app, buffer_id, layout_virt_indent_index_generic); } @@ -848,7 +912,7 @@ BUFFER_HOOK_SIG(default_begin_buffer){ buffer_set_layout(app, buffer_id, layout_generic); } } - + // no meaning for return return(0); } @@ -859,7 +923,7 @@ BUFFER_HOOK_SIG(default_new_file){ if (!string_match(string_postfix(file_name, 2), string_u8_litexpr(".h"))) { return(0); } - + List_String_Const_u8 guard_list = {}; for (u64 i = 0; i < file_name.size; ++i){ u8 c[2] = {}; @@ -883,11 +947,11 @@ BUFFER_HOOK_SIG(default_new_file){ string_list_push(scratch, &guard_list, part); } String_Const_u8 guard = string_list_flatten(scratch, guard_list); - + Date_Time date_time = system_now_date_time_universal(); date_time = system_local_date_time_from_universal(&date_time); String_Const_u8 date_string = date_time_format(scratch, "month day yyyy h:mimi ampm", &date_time); - + Buffer_Insertion insert = begin_buffer_insertion_at_buffered(app, buffer_id, 0, scratch, KB(16)); insertf(&insert, "/* date = %.*s */\n" @@ -902,24 +966,24 @@ BUFFER_HOOK_SIG(default_new_file){ string_expand(guard), string_expand(guard)); end_buffer_insertion(&insert); - + return(0); } BUFFER_HOOK_SIG(default_file_save){ // buffer_id ProfileScope(app, "default file save"); - + b32 auto_indent = def_get_config_b32(vars_save_string_lit("automatically_indent_text_on_save")); b32 is_virtual = def_get_config_b32(vars_save_string_lit("enable_virtual_whitespace")); if (auto_indent && is_virtual){ auto_indent_buffer(app, buffer_id, buffer_range(app, buffer_id)); } - + Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); Line_Ending_Kind *eol = scope_attachment(app, scope, buffer_eol_setting, Line_Ending_Kind); - + clean_all_lines_buffer(app, buffer_id, CleanAllLinesMode_RemoveBlankLines); switch (*eol){ case LineEndingKind_LF: @@ -931,7 +995,7 @@ BUFFER_HOOK_SIG(default_file_save){ rewrite_lines_to_crlf(app, buffer_id); }break; } - + // no meaning for return return(0); } @@ -939,11 +1003,11 @@ BUFFER_HOOK_SIG(default_file_save){ BUFFER_EDIT_RANGE_SIG(default_buffer_edit_range){ // buffer_id, new_range, original_size ProfileScope(app, "default edit range"); - + Range_i64 old_range = Ii64(old_cursor_range.min.pos, old_cursor_range.max.pos); - + buffer_shift_fade_ranges(buffer_id, old_range.max, (new_range.max - old_range.max)); - + { code_index_lock(); Code_Index_File *file = code_index_get_file(buffer_id); @@ -952,70 +1016,70 @@ BUFFER_EDIT_RANGE_SIG(default_buffer_edit_range){ } code_index_unlock(); } - + i64 insert_size = range_size(new_range); i64 text_shift = replace_range_shift(old_range, insert_size); - + Scratch_Block scratch(app); - + Managed_Scope scope = buffer_get_managed_scope(app, buffer_id); Async_Task *lex_task_ptr = scope_attachment(app, scope, buffer_lex_task, Async_Task); - + Base_Allocator *allocator = managed_scope_allocator(app, scope); b32 do_full_relex = false; - + if (async_task_is_running_or_pending(&global_async_system, *lex_task_ptr)){ async_task_cancel(app, &global_async_system, *lex_task_ptr); buffer_unmark_as_modified(buffer_id); do_full_relex = true; *lex_task_ptr = 0; } - + Token_Array *ptr = scope_attachment(app, scope, attachment_tokens, Token_Array); if (ptr != 0 && ptr->tokens != 0){ ProfileBlockNamed(app, "attempt resync", profile_attempt_resync); - + i64 token_index_first = token_relex_first(ptr, old_range.first, 1); i64 token_index_resync_guess = token_relex_resync(ptr, old_range.one_past_last, 16); - + if (token_index_resync_guess - token_index_first >= 4000){ do_full_relex = true; } else{ Token *token_first = ptr->tokens + token_index_first; Token *token_resync = ptr->tokens + token_index_resync_guess; - + Range_i64 relex_range = Ii64(token_first->pos, token_resync->pos + token_resync->size + text_shift); String_Const_u8 partial_text = push_buffer_range(app, scratch, buffer_id, relex_range); - + Token_List relex_list = lex_full_input_cpp(scratch, partial_text); if (relex_range.one_past_last < buffer_get_size(app, buffer_id)){ token_drop_eof(&relex_list); } - + Token_Relex relex = token_relex(relex_list, relex_range.first - text_shift, ptr->tokens, token_index_first, token_index_resync_guess); - + ProfileCloseNow(profile_attempt_resync); - + if (!relex.successful_resync){ do_full_relex = true; } else{ ProfileBlock(app, "apply resync"); - + i64 token_index_resync = relex.first_resync_index; - + Range_i64 head = Ii64(0, token_index_first); Range_i64 replaced = Ii64(token_index_first, token_index_resync); Range_i64 tail = Ii64(token_index_resync, ptr->count); i64 resynced_count = (token_index_resync_guess + 1) - token_index_resync; i64 relexed_count = relex_list.total_count - resynced_count; i64 tail_shift = relexed_count - (token_index_resync - token_index_first); - + i64 new_tokens_count = ptr->count + tail_shift; Token *new_tokens = base_array(allocator, Token, new_tokens_count); - + Token *old_tokens = ptr->tokens; block_copy_array_shift(new_tokens, old_tokens, head, 0); token_fill_memory_from_list(new_tokens + replaced.first, &relex_list, relexed_count); @@ -1026,23 +1090,23 @@ BUFFER_EDIT_RANGE_SIG(default_buffer_edit_range){ old_tokens[i].pos += text_shift; } block_copy_array_shift(new_tokens, ptr->tokens, tail, tail_shift); - + base_free(allocator, ptr->tokens); - + ptr->tokens = new_tokens; ptr->count = new_tokens_count; ptr->max = new_tokens_count; - + buffer_mark_as_modified(buffer_id); } } } - + if (do_full_relex){ *lex_task_ptr = async_task_no_dep(&global_async_system, do_full_lex_async, make_data_struct(&buffer_id)); } - + // no meaning for return return(0); } @@ -1074,18 +1138,18 @@ default_view_change_buffer(Application_Links *app, View_ID view_id, internal void set_all_default_hooks(Application_Links *app){ set_custom_hook(app, HookID_BufferViewerUpdate, default_view_adjust); - + set_custom_hook(app, HookID_ViewEventHandler, default_view_input_handler); set_custom_hook(app, HookID_Tick, default_tick); set_custom_hook(app, HookID_RenderCaller, default_render_caller); set_custom_hook(app, HookID_WholeScreenRenderCaller, default_whole_screen_render_caller); - + set_custom_hook(app, HookID_DeltaRule, fixed_time_cubic_delta); set_custom_hook_memory_size(app, HookID_DeltaRule, delta_ctx_size(fixed_time_cubic_delta_memory_size)); - - set_custom_hook(app, HookID_BufferNameResolver, default_buffer_name_resolution); - + + set_custom_hook(app, HookID_BufferNameResolver, gs_buffer_name_resolution); + set_custom_hook(app, HookID_BeginBuffer, default_begin_buffer); set_custom_hook(app, HookID_EndBuffer, end_buffer_close_jump_list); set_custom_hook(app, HookID_NewFile, default_new_file); @@ -1093,7 +1157,7 @@ set_all_default_hooks(Application_Links *app){ set_custom_hook(app, HookID_BufferEditRange, default_buffer_edit_range); set_custom_hook(app, HookID_BufferRegion, default_buffer_region); set_custom_hook(app, HookID_ViewChangeBuffer, default_view_change_buffer); - + set_custom_hook(app, HookID_Layout, layout_unwrapped); //set_custom_hook(app, HookID_Layout, layout_wrap_anywhere); //set_custom_hook(app, HookID_Layout, layout_wrap_whitespace);