From b98d14f9dd79b044f1bc9b67a18f8a449269621d Mon Sep 17 00:00:00 2001 From: krzosa Date: Wed, 24 Dec 2025 11:19:23 +0100 Subject: [PATCH] Build panel and reworking Open paths, not compiling --- src/backup/todo.txt | 4 +- src/basic/basic_string.cpp | 7 +++ src/basic/basic_string16.cpp | 8 ++- src/text_editor/buffer.cpp | 3 ++ src/text_editor/commands.cpp | 83 ++++++++++++++++++++++++------ src/text_editor/globals.cpp | 4 +- src/text_editor/text_editor.cpp | 2 +- src/text_editor/window_command.cpp | 2 +- src/text_editor/window_search.cpp | 2 +- src/text_editor/window_status.cpp | 2 +- 10 files changed, 94 insertions(+), 23 deletions(-) diff --git a/src/backup/todo.txt b/src/backup/todo.txt index e7d257c..291323b 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -1,9 +1,9 @@ - What precise workflow do I need for me to be viable to use this? - From a user (novice) point of view, how does it look like? +- build console window +- Use WorkDir (raname to Workspace?) to shorten file names - Show what process/coroutines are running and allow to kill (active process buffer?) -- ctrl + p like in VSCode (without special buffers) - - Maybe 2 windows? - Database idea: use special buffers to store information - Editing the buffer doesn't seem to be the slow part rather, accessing the data and putting it into the buffer (potentially hitting many different memory locations) I have a crazy idea to use buffers in order to store the names in a serialized format - non editable buffers (raw ops ok, non-raw no op) diff --git a/src/basic/basic_string.cpp b/src/basic/basic_string.cpp index 75113d6..18e2340 100644 --- a/src/basic/basic_string.cpp +++ b/src/basic/basic_string.cpp @@ -84,6 +84,13 @@ API String GetPrefix(String a, int64_t len) { return result; } +API char At(String a, int64_t idx) { + if (idx < a.len) { + return a.data[idx]; + } + return 0; +} + API String GetSlice(String arr, int64_t first_index, int64_t one_past_last_index) { // Negative indexes work in python style, they return you the index counting from end of list if (one_past_last_index == SLICE_LAST) one_past_last_index = arr.len; diff --git a/src/basic/basic_string16.cpp b/src/basic/basic_string16.cpp index a904582..739ecdf 100644 --- a/src/basic/basic_string16.cpp +++ b/src/basic/basic_string16.cpp @@ -69,7 +69,6 @@ API bool IsParen(char16_t c) { return result; } - API String16 Chop(String16 a, int64_t len) { len = ClampTop(len, a.len); String16 result = {a.data, a.len - len}; @@ -95,6 +94,13 @@ API String16 GetPrefix(String16 a, int64_t len) { return result; } +API char16_t At(String16 a, int64_t idx) { + if (idx < a.len) { + return a.data[idx]; + } + return 0; +} + API String16 GetSlice(String16 arr, int64_t first_index, int64_t one_past_last_index) { // Negative indexes work in python style, they return you the index counting from end of list if (one_past_last_index == SLICE_LAST) one_past_last_index = arr.len; diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index 697075a..3db7cc9 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -1437,6 +1437,9 @@ void InitBuffers() { EventBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "events")); EventBuffer->no_history = true; EventBuffer->special = true; + BuildBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "build")); + BuildBuffer->no_history = true; + BuildBuffer->special = true; } Int ConvertUTF8ToUTF16UnixLine(String string, char16_t *buffer, Int buffer_cap) { diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 04fc593..f1fa077 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -379,7 +379,7 @@ void GotoNextInList(Window *window, Int line_offset = 1) { continue; } - BSet set = Open(line, "goto_build"); + BSet set = Open(line, "dont_error"); if (set.window == NULL) { continue; } @@ -445,6 +445,32 @@ BSet Exec(String cmd, String working_dir, bool set_active = true) { return main; } +BSet ExecBuild(String cmd) { + BSet main = GetBSet(LastActiveLayoutWindowID); + ActiveWindowID = main.window->id; + CheckpointBeforeGoto(main.window); + View *view = WindowOpenBufferView(main.window, BuildBuffer->name); + ResetBuffer(BuildBuffer); + Exec(view->id, true, cmd, WorkDir); + main.window->active_goto_list = view->id; + main.window->goto_list_pos = 0; + return main; +} + +void Command_Build() { + ExecBuild("build.bat"); +} RegisterCommand(Command_Build, "f1"); + +void Command_GotoNextInList() { + BSet main = GetBSet(LastActiveLayoutWindowID); + GotoNextInList(main.window, 1); +} RegisterCommand(Command_GotoNextInList, "ctrl-e"); + +void Command_GotoPrevInList() { + BSet main = GetBSet(LastActiveLayoutWindowID); + GotoNextInList(main.window, -1); +} RegisterCommand(Command_GotoPrevInList, "alt-e"); + enum OpenKind { OpenKind_Invalid, OpenKind_Skip, @@ -460,6 +486,11 @@ struct ResolvedOpen { Int line, col; }; +bool IsOpenBoundary(char c) { + bool result = c == 0 || IsParen(c) || IsBrace(c) || c == ':' || c == '\t' || c == '\n' || c == '"' || c == '\''; + return result; +} + ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { ResolvedOpen result = {}; @@ -500,24 +531,42 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { } } - // Parse ":line:column" { - path = NormalizePath(scratch, path); - String p = path; - Int a = ChopNumber(&p); - if (a != -1 && Chop(&p, ":")) { - path = p; - Int b = ChopNumber(&p); - if (b != -1 && Chop(&p, ":")) { - path = p; - result.col = a; - result.line = b; - } else { - result.line = a; - } + String p = NormalizePath(scratch, path); + String pstart = p; +asd + bool is_absolute = false; + if (IsAlphabetic(ToLowerCase(At(p, 0))) && At(p, 1) == ':' && At(p, 2) == '/') { + is_absolute = true; + p = Skip(p, 3); + } else if (At(p, 0) == '/') { + is_absolute = true; + p = Skip(p, 1); + } + + while (!IsOpenBoundary(At(p, 0))) { + p = Skip(p, 1); } } + // Parse ":line:column" + // { + // path = NormalizePath(scratch, path); + // String p = path; + // Int a = ChopNumber(&p); + // if (a != -1 && Chop(&p, ":")) { + // path = p; + // Int b = ChopNumber(&p); + // if (b != -1 && Chop(&p, ":")) { + // path = p; + // result.col = a; + // result.line = b; + // } else { + // result.line = a; + // } + // } + // } + Buffer *existing_buffer = GetBuffer(path, NULL); if (existing_buffer != NULL) { result.path = path; @@ -540,6 +589,10 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { } } + if (meta == "dont_error") { + result.kind = OpenKind_Skip; + } + return result; } diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index bdb3fd3..970dadc 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -15,11 +15,12 @@ Array Windows; Array Views; Array Buffers; -// console +// First window BufferID NullBufferID; ViewID NullViewID; WindowID NullWindowID; + // hidden floating window WindowID DebugWindowID; ViewID DebugViewID; @@ -39,6 +40,7 @@ WindowID ResizerSelected = {-1}; WindowID ResizerHover = {-1}; Caret DocumentAnchor; +Buffer *BuildBuffer; Buffer *GCInfoBuffer; Buffer *EventBuffer; Buffer *TraceBuffer; diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index b68e48f..4228faa 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -326,7 +326,7 @@ void OnCommand(Event event) { Assert(DocumentSelected.id == -1); BSet active = GetBSet(ActiveWindowID); // using next to make sure mouse works on first click after switching the window - bool mouse_in_document = AreOverlapping(mouse, active.window->document_rect); + bool mouse_in_document = AreOverlapping(mouse, active.window->document_rect); bool mouse_in_line_numbers = AreOverlapping(mouse, active.window->line_numbers_rect); if (mouse_in_document || mouse_in_line_numbers) { DocumentSelected = active.window->id; diff --git a/src/text_editor/window_command.cpp b/src/text_editor/window_command.cpp index 82a5aa4..a84ac9e 100644 --- a/src/text_editor/window_command.cpp +++ b/src/text_editor/window_command.cpp @@ -1,7 +1,7 @@ void CommandWindowInit() { Window *window = CreateWind(); CommandWindowID = window->id; - Buffer *buffer = CreateBuffer(SysAllocator, "command_bar"); + Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "command_bar")); buffer->special = true; View *view = CreateView(buffer->id); view->special = true; diff --git a/src/text_editor/window_search.cpp b/src/text_editor/window_search.cpp index 0bbf822..5ed478b 100644 --- a/src/text_editor/window_search.cpp +++ b/src/text_editor/window_search.cpp @@ -1,7 +1,7 @@ void SearchWindowInit() { Window *window = CreateWind(); SearchWindowID = window->id; - Buffer *buffer = CreateBuffer(SysAllocator, "search_bar"); + Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "search")); buffer->special = true; SearchBufferID = buffer->id; View *view = CreateView(buffer->id); diff --git a/src/text_editor/window_status.cpp b/src/text_editor/window_status.cpp index bff0e41..d5154ec 100644 --- a/src/text_editor/window_status.cpp +++ b/src/text_editor/window_status.cpp @@ -1,7 +1,7 @@ void StatusWindowInit() { Window *window = CreateWind(); StatusBarWindowID = window->id; - Buffer *buffer = CreateBuffer(SysAllocator, "status_bar"); + Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "status_bar")); buffer->special = true; View *view = CreateView(buffer->id); view->special = true;