Build panel and reworking Open paths, not compiling

This commit is contained in:
krzosa
2025-12-24 11:19:23 +01:00
parent ceb6747fcd
commit b98d14f9dd
10 changed files with 94 additions and 23 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -15,11 +15,12 @@ Array<Window *> Windows;
Array<View *> Views;
Array<Buffer *> 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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;