SLOW_BUILD, 2 additional build targets, improve word complete

This commit is contained in:
Krzosa Karol
2026-01-25 08:54:00 +01:00
parent 863f140edc
commit 7ae4e74f50
9 changed files with 78 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ for %%a in (%*) do set "%%~a=1"
if not "%release%"=="1" set debug=1
if "%debug%"=="1" set release=0 && echo [debug mode]
if "%release%"=="1" set debug=0 && echo [release mode]
if "%slow%"=="1" echo [slow mode]
if "%package%"=="1" echo [package zip]
if not exist "src\external\SDL" (
@@ -28,6 +29,7 @@ pushd build
set flags=/EHsc- /MT /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column
if "%release%"=="1" set flags=%flags% -O2 -DDEBUG_BUILD=0
if "%slow%"=="1" set flags=%flags% -DSLOW_BUILD=1
set libs=%sdllib%/SDL3-static.lib %sdllib%/SDL_uclibc.lib kernel32.lib gdi32.lib user32.lib Imm32.lib ole32.lib Shell32.lib OleAut32.lib Cfgmgr32.lib Setupapi.lib Advapi32.lib version.lib winmm.lib
rem rc ..\data\icon.rc

View File

@@ -165,7 +165,7 @@ Slice<T> GetSlice(Slice<T> &arr, int64_t first_index = 0, int64_t one_past_last_
}
// Make arrays resize on every item
#define ARRAY_DEBUG 0
#define ARRAY_DEBUG BUILD_SLOW
#if ARRAY_DEBUG
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF
#else
@@ -310,6 +310,16 @@ bool Contains(Array<T> &arr, T item) {
return false;
}
template<class T>
int64_t FindValueIndex(Array<T> &arr, T item) {
for (int64_t i = 0; i < arr.len; i += 1) {
if (arr.data[i] == item) {
return i;
}
}
return -1;
}
template <class T>
int64_t GetIndex(Array<T> &arr, const T &item) {
ptrdiff_t index = (ptrdiff_t)(&item - arr.data);

View File

@@ -9,7 +9,6 @@
#include <stddef.h>
#include <stdlib.h>
#if defined(__APPLE__) && defined(__MACH__)
#define OS_POSIX 1
#define OS_MAC 1
@@ -70,6 +69,16 @@
#define DEBUG_BUILD 1
#endif
#ifndef SLOW_BUILD
#define SLOW_BUILD 0
#endif
#if SLOW_BUILD
#define IF_SLOW_BUILD(x) x
#else
#define IF_SLOW_BUILD(x)
#endif
#if DEBUG_BUILD
#define IF_DEBUG(x) x
#else

View File

@@ -1,4 +1,4 @@
#define BUFFER_DEBUG DEBUG_BUILD
#define BUFFER_DEBUG SLOW_BUILD
API bool AreEqual(XY a, XY b) {
bool result = a.x == b.x && a.y == b.y;

View File

@@ -62,7 +62,7 @@ void CoUpdate(Event *event) {
}
}
#if DEBUG_BUILD
#if SLOW_BUILD
//:CoroutineLeakCheck
// Make sure we don't leak scratch arenas between coroutine boundaries.
// it leads to memory corruption! If you hit Assert here make sure you

View File

@@ -10,10 +10,9 @@ bool SearchCaseSensitive = false;
bool SearchWordBoundary = false;
bool BreakOnError = false;
Int ErrorCount;
#if 1
String16 InitialScratchContent;
#else
String16 InitialScratchContent = uR"==(C:/text_editor/src/text_editor/text_editor.cpp
#if DEBUG_BUILD
String16 InitialScratchContent = uR"==(:OpenProject
C:/text_editor/src/text_editor/text_editor.cpp
0
1
2
@@ -21,6 +20,8 @@ String16 InitialScratchContent = uR"==(C:/text_editor/src/text_editor/text_edito
4
5
6)==";
#else
String16 InitialScratchContent;
#endif
Allocator SysAllocator = {SystemAllocatorProc};
@@ -187,10 +188,15 @@ RegisterVariable(Int, TrimTrailingWhitespace, 1);
RegisterVariable(String, ProjectDirectory, "");
// PLUGIN_BUILD_WINDOW
RegisterVariable(String, Build1OnWindows, "build.bat");
RegisterVariable(String, Build1OnUnix, "sh build.sh");
RegisterVariable(String, Build2OnWindows, "build.bat release");
RegisterVariable(String, Build2OnUnix, "sh build.sh release");
RegisterVariable(String, Build1OnWindows, "build.bat slow");
RegisterVariable(String, Build1OnUnix, "sh build.sh slow");
RegisterVariable(String, Build2OnWindows, "build.bat");
RegisterVariable(String, Build2OnUnix, "sh build.sh");
RegisterVariable(String, Build3OnWindows, "build.bat release");
RegisterVariable(String, Build3OnUnix, "sh build.sh release");
RegisterVariable(String, Build4OnWindows, "build.bat release");
RegisterVariable(String, Build4OnUnix, "sh build.sh release");
// PLUGIN_LOAD_VCVARS
RegisterVariable(String, VCVarsPath, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");

View File

@@ -56,6 +56,14 @@ void CMD_Build2() {
ExecBuild(Build2OnWindows, Build2OnUnix);
} RegisterCommand(CMD_Build2, "f2", "Run Build2OnWindows or OnUnix in working directory, output is printed in a popup console and a special build buffer");
void CMD_Build3() {
ExecBuild(Build3OnWindows, Build3OnUnix);
} RegisterCommand(CMD_Build3, "f3", "Run Build3OnWindows or OnUnix in working directory, output is printed in a popup console and a special build buffer");
void CMD_Build4() {
ExecBuild(Build4OnWindows, Build4OnUnix);
} RegisterCommand(CMD_Build4, "f4", "Run Build4OnWindows or OnUnix in working directory, output is printed in a popup console and a special build buffer");
void CMD_RunFile() {
Scratch scratch;
BSet primary = GetBSet(PrimaryWindowID);

View File

@@ -26,11 +26,13 @@ struct StringAndDistance {
Int distance;
};
bool Contains(Array<StringAndDistance> *arr, String16 string) {
For (*arr) {
if (it.string == string) return true;
Int FindValueIndex(Array<StringAndDistance> *arr, String16 string) {
for (int64_t i = 0; i < arr->len; i += 1) {
if (arr->data[i].string == string) {
return i;
}
}
return false;
return -1;
}
inline bool MergeSortCompare(StringAndDistance *EntryA, StringAndDistance *EntryB) {
@@ -58,10 +60,17 @@ void CWSLexIdentifiers(Array<StringAndDistance> *out_idents, Buffer *buffer) {
if (token.len <= 0) {
break;
}
if (StartsWith(token, CWS.prefix_string) && token != CWS.prefix_string && !Contains(&idents, token)) {
if (StartsWith(token, CWS.prefix_string) && token != CWS.prefix_string) {
Int pos = token.data - buffer->str;
Int distance = Absolute(CWS.original_caret_pos - pos);
Add(&idents, {Copy16(CWS.arena, token), distance});
int64_t value_index = FindValueIndex(&idents, token);
if (value_index != -1) {
if (idents[value_index].distance > distance) {
idents[value_index].distance = distance;
}
} else {
Add(&idents, {Copy16(CWS.arena, token), distance});
}
}
}
@@ -70,11 +79,11 @@ void CWSLexIdentifiers(Array<StringAndDistance> *out_idents, Buffer *buffer) {
MergeSort(idents.len, idents.data, temp.data);
}
For (idents) {
if (!Contains(out_idents, it.string)) Add(out_idents, it);
if (FindValueIndex(out_idents, it.string) == -1) Add(out_idents, it);
}
}
void CompleteWord2(mco_coro *co) {
void WordComplete(mco_coro *co) {
Array<BufferID> buffers = {CWS.arena};
{
Add(&buffers, CWS.buffer->id);
@@ -132,10 +141,14 @@ void CompleteWord2(mco_coro *co) {
}
}
void CompleteWord(View *view, Int pos) {
void WordComplete(View *view, Int pos) {
Buffer *buffer = GetBuffer(view->active_buffer);
Range prefix_string_range = {GetWordStart(buffer, pos), pos};
String16 prefix = GetString(buffer, prefix_string_range);
if (prefix == u"") {
return;
}
bool continue_with_previous = CWS.co && CWS.last_string == prefix && CWS.buffer == buffer;
if (!continue_with_previous) {
if (CWS.co) {
@@ -151,7 +164,7 @@ void CompleteWord(View *view, Int pos) {
CWS.original_caret_pos = pos;
CWS.prefix_string = Copy16(CWS.arena, prefix);
mco_desc desc = mco_desc_init(CompleteWord2, NULL);
mco_desc desc = mco_desc_init(WordComplete, NULL);
mco_result res = mco_create(&CWS.co, &desc);
Assert(res == MCO_SUCCESS);
}
@@ -185,14 +198,14 @@ void CompletePrevWord(View *view, Int pos) {
}
}
void CMD_CompleteWord() {
void CMD_WordComplete() {
BSet active = GetBSet(ActiveWindowID);
bool ok = active.view->carets.len == 1 && GetSize(active.view->carets[0].range) == 0;
if (!ok) {
return;
}
CompleteWord(active.view, active.view->carets[0].range.min);
} RegisterCommand(CMD_CompleteWord, "", "Completes the current word");
WordComplete(active.view, active.view->carets[0].range.min);
} RegisterCommand(CMD_WordComplete, "", "Completes the current word");
void CMD_CompletePrevWord() {
BSet active = GetBSet(ActiveWindowID);
@@ -212,11 +225,11 @@ void CMD_CompletePrevWordOrDedent() {
}
} RegisterCommand(CMD_CompletePrevWordOrDedent, "shift-tab", "Completes the current word or it indents it, when single caret with no selection it goes for word complete");
void CMD_CompleteWordOrIndent() {
void CMD_WordCompleteOrIndent() {
BSet active = GetBSet(ActiveWindowID);
if (active.view->carets.len == 1 && GetSize(active.view->carets[0].range) == 0) {
CMD_CompleteWord();
CMD_WordComplete();
} else {
IndentSelectedLines(active.view);
}
} RegisterCommand(CMD_CompleteWordOrIndent, "tab", "Completes the current word or it indents it, when single caret with no selection it goes for word complete");
} RegisterCommand(CMD_WordCompleteOrIndent, "tab", "Completes the current word or it indents it, when single caret with no selection it goes for word complete");

View File

@@ -459,8 +459,8 @@ void OnCommand(Event event) {
}
}
IF_DEBUG(AssertRanges(main.view->carets));
IF_DEBUG(AssertRanges(active.view->carets));
IF_SLOW_BUILD(AssertRanges(main.view->carets));
IF_SLOW_BUILD(AssertRanges(active.view->carets));
}
void EvalCommand(String command) {