SLOW_BUILD, 2 additional build targets, improve word complete
This commit is contained in:
@@ -6,6 +6,7 @@ for %%a in (%*) do set "%%~a=1"
|
|||||||
if not "%release%"=="1" set debug=1
|
if not "%release%"=="1" set debug=1
|
||||||
if "%debug%"=="1" set release=0 && echo [debug mode]
|
if "%debug%"=="1" set release=0 && echo [debug mode]
|
||||||
if "%release%"=="1" set debug=0 && echo [release mode]
|
if "%release%"=="1" set debug=0 && echo [release mode]
|
||||||
|
if "%slow%"=="1" echo [slow mode]
|
||||||
if "%package%"=="1" echo [package zip]
|
if "%package%"=="1" echo [package zip]
|
||||||
|
|
||||||
if not exist "src\external\SDL" (
|
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
|
set flags=/EHsc- /MT /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column
|
||||||
if "%release%"=="1" set flags=%flags% -O2 -DDEBUG_BUILD=0
|
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
|
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
|
rem rc ..\data\icon.rc
|
||||||
|
|||||||
@@ -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
|
// Make arrays resize on every item
|
||||||
#define ARRAY_DEBUG 0
|
#define ARRAY_DEBUG BUILD_SLOW
|
||||||
#if ARRAY_DEBUG
|
#if ARRAY_DEBUG
|
||||||
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF
|
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF
|
||||||
#else
|
#else
|
||||||
@@ -310,6 +310,16 @@ bool Contains(Array<T> &arr, T item) {
|
|||||||
return false;
|
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>
|
template <class T>
|
||||||
int64_t GetIndex(Array<T> &arr, const T &item) {
|
int64_t GetIndex(Array<T> &arr, const T &item) {
|
||||||
ptrdiff_t index = (ptrdiff_t)(&item - arr.data);
|
ptrdiff_t index = (ptrdiff_t)(&item - arr.data);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
#define OS_POSIX 1
|
#define OS_POSIX 1
|
||||||
#define OS_MAC 1
|
#define OS_MAC 1
|
||||||
@@ -70,6 +69,16 @@
|
|||||||
#define DEBUG_BUILD 1
|
#define DEBUG_BUILD 1
|
||||||
#endif
|
#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
|
#if DEBUG_BUILD
|
||||||
#define IF_DEBUG(x) x
|
#define IF_DEBUG(x) x
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#define BUFFER_DEBUG DEBUG_BUILD
|
#define BUFFER_DEBUG SLOW_BUILD
|
||||||
|
|
||||||
API bool AreEqual(XY a, XY b) {
|
API bool AreEqual(XY a, XY b) {
|
||||||
bool result = a.x == b.x && a.y == b.y;
|
bool result = a.x == b.x && a.y == b.y;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ void CoUpdate(Event *event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_BUILD
|
#if SLOW_BUILD
|
||||||
//:CoroutineLeakCheck
|
//:CoroutineLeakCheck
|
||||||
// Make sure we don't leak scratch arenas between coroutine boundaries.
|
// Make sure we don't leak scratch arenas between coroutine boundaries.
|
||||||
// it leads to memory corruption! If you hit Assert here make sure you
|
// it leads to memory corruption! If you hit Assert here make sure you
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ bool SearchCaseSensitive = false;
|
|||||||
bool SearchWordBoundary = false;
|
bool SearchWordBoundary = false;
|
||||||
bool BreakOnError = false;
|
bool BreakOnError = false;
|
||||||
Int ErrorCount;
|
Int ErrorCount;
|
||||||
#if 1
|
#if DEBUG_BUILD
|
||||||
String16 InitialScratchContent;
|
String16 InitialScratchContent = uR"==(:OpenProject
|
||||||
#else
|
C:/text_editor/src/text_editor/text_editor.cpp
|
||||||
String16 InitialScratchContent = uR"==(C:/text_editor/src/text_editor/text_editor.cpp
|
|
||||||
0
|
0
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
@@ -21,6 +20,8 @@ String16 InitialScratchContent = uR"==(C:/text_editor/src/text_editor/text_edito
|
|||||||
4
|
4
|
||||||
5
|
5
|
||||||
6)==";
|
6)==";
|
||||||
|
#else
|
||||||
|
String16 InitialScratchContent;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Allocator SysAllocator = {SystemAllocatorProc};
|
Allocator SysAllocator = {SystemAllocatorProc};
|
||||||
@@ -187,10 +188,15 @@ RegisterVariable(Int, TrimTrailingWhitespace, 1);
|
|||||||
RegisterVariable(String, ProjectDirectory, "");
|
RegisterVariable(String, ProjectDirectory, "");
|
||||||
|
|
||||||
// PLUGIN_BUILD_WINDOW
|
// PLUGIN_BUILD_WINDOW
|
||||||
RegisterVariable(String, Build1OnWindows, "build.bat");
|
RegisterVariable(String, Build1OnWindows, "build.bat slow");
|
||||||
RegisterVariable(String, Build1OnUnix, "sh build.sh");
|
RegisterVariable(String, Build1OnUnix, "sh build.sh slow");
|
||||||
RegisterVariable(String, Build2OnWindows, "build.bat release");
|
RegisterVariable(String, Build2OnWindows, "build.bat");
|
||||||
RegisterVariable(String, Build2OnUnix, "sh build.sh release");
|
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
|
// PLUGIN_LOAD_VCVARS
|
||||||
RegisterVariable(String, VCVarsPath, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
|
RegisterVariable(String, VCVarsPath, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
|
||||||
|
|||||||
@@ -56,6 +56,14 @@ void CMD_Build2() {
|
|||||||
ExecBuild(Build2OnWindows, Build2OnUnix);
|
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");
|
} 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() {
|
void CMD_RunFile() {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
BSet primary = GetBSet(PrimaryWindowID);
|
BSet primary = GetBSet(PrimaryWindowID);
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ struct StringAndDistance {
|
|||||||
Int distance;
|
Int distance;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Contains(Array<StringAndDistance> *arr, String16 string) {
|
Int FindValueIndex(Array<StringAndDistance> *arr, String16 string) {
|
||||||
For (*arr) {
|
for (int64_t i = 0; i < arr->len; i += 1) {
|
||||||
if (it.string == string) return true;
|
if (arr->data[i].string == string) {
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool MergeSortCompare(StringAndDistance *EntryA, StringAndDistance *EntryB) {
|
inline bool MergeSortCompare(StringAndDistance *EntryA, StringAndDistance *EntryB) {
|
||||||
@@ -58,23 +60,30 @@ void CWSLexIdentifiers(Array<StringAndDistance> *out_idents, Buffer *buffer) {
|
|||||||
if (token.len <= 0) {
|
if (token.len <= 0) {
|
||||||
break;
|
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 pos = token.data - buffer->str;
|
||||||
Int distance = Absolute(CWS.original_caret_pos - pos);
|
Int distance = Absolute(CWS.original_caret_pos - pos);
|
||||||
|
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});
|
Add(&idents, {Copy16(CWS.arena, token), distance});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (idents.len > 1) {
|
if (idents.len > 1) {
|
||||||
Array<StringAndDistance> temp = TightCopy(CWS.arena, idents);
|
Array<StringAndDistance> temp = TightCopy(CWS.arena, idents);
|
||||||
MergeSort(idents.len, idents.data, temp.data);
|
MergeSort(idents.len, idents.data, temp.data);
|
||||||
}
|
}
|
||||||
For (idents) {
|
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};
|
Array<BufferID> buffers = {CWS.arena};
|
||||||
{
|
{
|
||||||
Add(&buffers, CWS.buffer->id);
|
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);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
Range prefix_string_range = {GetWordStart(buffer, pos), pos};
|
Range prefix_string_range = {GetWordStart(buffer, pos), pos};
|
||||||
String16 prefix = GetString(buffer, prefix_string_range);
|
String16 prefix = GetString(buffer, prefix_string_range);
|
||||||
|
if (prefix == u"") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool continue_with_previous = CWS.co && CWS.last_string == prefix && CWS.buffer == buffer;
|
bool continue_with_previous = CWS.co && CWS.last_string == prefix && CWS.buffer == buffer;
|
||||||
if (!continue_with_previous) {
|
if (!continue_with_previous) {
|
||||||
if (CWS.co) {
|
if (CWS.co) {
|
||||||
@@ -151,7 +164,7 @@ void CompleteWord(View *view, Int pos) {
|
|||||||
CWS.original_caret_pos = pos;
|
CWS.original_caret_pos = pos;
|
||||||
CWS.prefix_string = Copy16(CWS.arena, prefix);
|
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);
|
mco_result res = mco_create(&CWS.co, &desc);
|
||||||
Assert(res == MCO_SUCCESS);
|
Assert(res == MCO_SUCCESS);
|
||||||
}
|
}
|
||||||
@@ -185,14 +198,14 @@ void CompletePrevWord(View *view, Int pos) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMD_CompleteWord() {
|
void CMD_WordComplete() {
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
bool ok = active.view->carets.len == 1 && GetSize(active.view->carets[0].range) == 0;
|
bool ok = active.view->carets.len == 1 && GetSize(active.view->carets[0].range) == 0;
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CompleteWord(active.view, active.view->carets[0].range.min);
|
WordComplete(active.view, active.view->carets[0].range.min);
|
||||||
} RegisterCommand(CMD_CompleteWord, "", "Completes the current word");
|
} RegisterCommand(CMD_WordComplete, "", "Completes the current word");
|
||||||
|
|
||||||
void CMD_CompletePrevWord() {
|
void CMD_CompletePrevWord() {
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
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");
|
} 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);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
if (active.view->carets.len == 1 && GetSize(active.view->carets[0].range) == 0) {
|
if (active.view->carets.len == 1 && GetSize(active.view->carets[0].range) == 0) {
|
||||||
CMD_CompleteWord();
|
CMD_WordComplete();
|
||||||
} else {
|
} else {
|
||||||
IndentSelectedLines(active.view);
|
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");
|
||||||
@@ -459,8 +459,8 @@ void OnCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IF_DEBUG(AssertRanges(main.view->carets));
|
IF_SLOW_BUILD(AssertRanges(main.view->carets));
|
||||||
IF_DEBUG(AssertRanges(active.view->carets));
|
IF_SLOW_BUILD(AssertRanges(active.view->carets));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalCommand(String command) {
|
void EvalCommand(String command) {
|
||||||
|
|||||||
Reference in New Issue
Block a user