Make OpenCode into coroutine
This commit is contained in:
@@ -646,34 +646,51 @@ void Command_SetWorkDir() {
|
||||
} RegisterCommand(Command_SetWorkDir, "");
|
||||
|
||||
String CodeEndings[] = { ".c", ".cpp", ".h", ".hpp", ".py", ".lua", ".cxx", ".hxx", };
|
||||
String Coro_OpenCodeDir;
|
||||
|
||||
void OpenCodeRecursive(String dir) {
|
||||
ProfileFunction();
|
||||
Scratch scratch;
|
||||
for (FileIter it = IterateFiles(scratch, dir); IsValid(it); Advance(&it)) {
|
||||
if (it.filename == ".git") {
|
||||
continue;
|
||||
}
|
||||
void Coro_OpenCode(mco_coro *co) {
|
||||
BlockArena arena = {};
|
||||
Array<String> dirs = {arena};
|
||||
Add(&dirs, Coro_OpenCodeDir);
|
||||
int i = 0;
|
||||
for (int diri = 0; diri < dirs.len; diri += 1) {
|
||||
for (FileIter it = IterateFiles(arena, dirs[diri]); IsValid(it); Advance(&it)) {
|
||||
if (it.filename == ".git") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (it.is_directory) {
|
||||
OpenCodeRecursive(it.absolute_path);
|
||||
} else {
|
||||
bool match = false;
|
||||
ForItem (ending, CodeEndings) {
|
||||
if (EndsWith(it.absolute_path, ending)) {
|
||||
match = true;
|
||||
break;
|
||||
if (it.is_directory) {
|
||||
Add(&dirs, it.absolute_path);
|
||||
} else {
|
||||
bool match = false;
|
||||
ForItem (ending, CodeEndings) {
|
||||
if (EndsWith(it.absolute_path, ending)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
BufferOpenFile(it.absolute_path);
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
BufferOpenFile(it.absolute_path);
|
||||
|
||||
|
||||
if ((i%16) == 0) {
|
||||
CoYield(co);
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
Release(&arena);
|
||||
}
|
||||
|
||||
void OpenCode(String dir) {
|
||||
Coro_OpenCodeDir = dir;
|
||||
CoAdd(Coro_OpenCode);
|
||||
}
|
||||
|
||||
void Command_OpenCode() {
|
||||
OpenCodeRecursive(WorkDir);
|
||||
OpenCode(WorkDir);
|
||||
} RegisterCommand(Command_OpenCode, "");
|
||||
|
||||
void Command_KillProcess() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
typedef void CoroutineProc(mco_coro *co);
|
||||
typedef void CoroutineProc(mco_coro *co);
|
||||
Array<mco_coro *> ActiveCoroutines;
|
||||
|
||||
mco_coro *CoAdd(CoroutineProc *proc) {
|
||||
@@ -18,6 +18,7 @@ mco_coro *CoAdd(CoroutineProc *proc) {
|
||||
|
||||
void CoUpdate(Event *event) {
|
||||
ProfileFunction();
|
||||
double start = GetTimeSeconds();
|
||||
IterRemove(ActiveCoroutines) {
|
||||
IterRemovePrepare(ActiveCoroutines);
|
||||
|
||||
@@ -34,6 +35,11 @@ void CoUpdate(Event *event) {
|
||||
remove_item = true;
|
||||
}
|
||||
}
|
||||
|
||||
double took = GetTimeSeconds() - start;
|
||||
if (took > 0.01) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,3 +53,8 @@ Event *CoYield(mco_coro *co) {
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
void CoRemove(mco_coro *co) {
|
||||
UnorderedRemove(&ActiveCoroutines, co);
|
||||
mco_destroy(co);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "text_editor.h"
|
||||
|
||||
#include "globals.cpp"
|
||||
#include "coroutines.cpp"
|
||||
#include "buffer.cpp"
|
||||
#include "view.cpp"
|
||||
#include "window.cpp"
|
||||
@@ -39,7 +40,6 @@
|
||||
#include "commands_clipboard.cpp"
|
||||
|
||||
#include "draw.cpp"
|
||||
#include "coroutines.cpp"
|
||||
#include "test/tests.cpp"
|
||||
|
||||
|
||||
|
||||
@@ -186,3 +186,4 @@ struct Register_Variable {
|
||||
#define RegisterVariable(type, name, ...) \
|
||||
type name = __VA_ARGS__; \
|
||||
Register_Variable var_##name(&Variables, VariableType_##type, #name, &name)
|
||||
|
||||
|
||||
@@ -24,10 +24,9 @@ void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) {
|
||||
rect = ©_rect;
|
||||
}
|
||||
Int barsize = Clamp((Int)n->font->line_spacing*10, (Int)0, (Int)wx - 100);
|
||||
n->document_rect = n->total_rect = CutTop(rect, barsize);
|
||||
n->document_rect = n->total_rect = CutBottom(rect, barsize);
|
||||
}
|
||||
|
||||
|
||||
const Int FuzzyCloserWordBegin = 5;
|
||||
const Int FuzzyConsecutiveMultiplier = 3;
|
||||
Int FuzzyRate(String16 string, String16 with) {
|
||||
|
||||
Reference in New Issue
Block a user