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