Toying with the new plugin idea
This commit is contained in:
@@ -11,11 +11,11 @@
|
|||||||
- Maybe IPC for te.exe when it's already open and file arguments are passed it should perhaps open a buffer in current window??
|
- Maybe IPC for te.exe when it's already open and file arguments are passed it should perhaps open a buffer in current window??
|
||||||
|
|
||||||
Use session 4
|
Use session 4
|
||||||
- Add <<File>> <<WorkDir>> template strings to Open (Then remove SEtWorkdirhere)
|
- Add <<File>> <<ProjectDirectory>> template strings to Open (Then remove SEtWorkdirhere)
|
||||||
- :Set Filename to name current buffer ??? :O and others like that!!
|
- :Set Filename to name current buffer ??? :O and others like that!!
|
||||||
|
|
||||||
- Make a fuzzy command !> grep and fuzzy over it??? (doesn't seem very useful for grep)
|
- Make a fuzzy command !> grep and fuzzy over it??? (doesn't seem very useful for grep)
|
||||||
- Make the equivalent of SearchProject but for cmds like !@git grep -n "@>"
|
- Make the equivalent of SearchOpenBuffers but for cmds like !@git grep -n "@>"
|
||||||
- Add Bool variable
|
- Add Bool variable
|
||||||
- RegisterCommand should_appear_in_listing variable
|
- RegisterCommand should_appear_in_listing variable
|
||||||
|
|
||||||
|
|||||||
@@ -1408,24 +1408,26 @@ String GetUniqueBufferName(String working_dir, String prepend_name, String exten
|
|||||||
void InitBuffers() {
|
void InitBuffers() {
|
||||||
Allocator sys_allocator = GetSystemAllocator();
|
Allocator sys_allocator = GetSystemAllocator();
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Buffer *null_buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "logs", ""));
|
Buffer *null_buffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "logs", ""));
|
||||||
null_buffer->special = true;
|
null_buffer->special = true;
|
||||||
View *null_view = CreateView(null_buffer->id);
|
View *null_view = CreateView(null_buffer->id);
|
||||||
null_view->special = true;
|
null_view->special = true;
|
||||||
Assert(null_buffer->id == NullBufferID && null_view->id == NullViewID);
|
Assert(null_buffer->id == NullBufferID && null_view->id == NullViewID);
|
||||||
TraceBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "trace"));
|
TraceBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "trace"));
|
||||||
TraceBuffer->special = true;
|
TraceBuffer->special = true;
|
||||||
TraceBuffer->no_history = true;
|
TraceBuffer->no_history = true;
|
||||||
GCInfoBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "gc"));
|
GCInfoBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "gc"));
|
||||||
GCInfoBuffer->special = true;
|
GCInfoBuffer->special = true;
|
||||||
GCInfoBuffer->no_history = true;
|
GCInfoBuffer->no_history = true;
|
||||||
EventBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "events"));
|
EventBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "events"));
|
||||||
EventBuffer->no_history = true;
|
EventBuffer->no_history = true;
|
||||||
EventBuffer->special = true;
|
EventBuffer->special = true;
|
||||||
Buffer *search_project = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "search_project"));
|
Buffer *search_project = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "search_project"));
|
||||||
search_project->no_history = true;
|
search_project->no_history = true;
|
||||||
search_project->special = true;
|
search_project->special = true;
|
||||||
SearchProjectBufferID = search_project->id;
|
#ifdef PLUGIN_SEARCH_OPEN_BUFFERS
|
||||||
|
SearchOpenBuffersBufferID = search_project->id;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Int ConvertUTF8ToUTF16UnixLine(String string, char16_t *buffer, Int buffer_cap) {
|
Int ConvertUTF8ToUTF16UnixLine(String string, char16_t *buffer, Int buffer_cap) {
|
||||||
|
|||||||
@@ -501,17 +501,6 @@ bool IsOpenBoundary(char c) {
|
|||||||
return; \
|
return; \
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWorkDirHere(String dir) {
|
|
||||||
WorkDir = Intern(&GlobalInternTable, dir);
|
|
||||||
Scratch scratch;
|
|
||||||
For (Buffers) {
|
|
||||||
if (it->special) {
|
|
||||||
String name = SkipToLastSlash(it->name);
|
|
||||||
it->name = Intern(&GlobalInternTable, Format(scratch, "%S/%S", dir, name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Set(String string) {
|
void Set(String string) {
|
||||||
String name = SkipIdent(&string);
|
String name = SkipIdent(&string);
|
||||||
ExpectP(name.len != 0, "expected a variable name, instead got '%S'", string);
|
ExpectP(name.len != 0, "expected a variable name, instead got '%S'", string);
|
||||||
@@ -558,9 +547,13 @@ void Set(String string) {
|
|||||||
|
|
||||||
if (name == "FontSize" || name == "PathToFont") {
|
if (name == "FontSize" || name == "PathToFont") {
|
||||||
ReloadFont(PathToFont, (U32)FontSize);
|
ReloadFont(PathToFont, (U32)FontSize);
|
||||||
} else if (name == "WorkDir") {
|
|
||||||
SetWorkDirHere(*var->string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PLUGIN_PROJECT_MANAGEMENT
|
||||||
|
if (name == "ProjectDirectory") {
|
||||||
|
SetProjectDirectory(*var->string);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,7 +696,9 @@ ResolvedOpen ResolveOpen(Allocator alo, String path, ResolveOpenMeta meta) {
|
|||||||
result.kind = OpenKind_Goto;
|
result.kind = OpenKind_Goto;
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
String workspace_path = Format(alo, "%S/%S", WorkDir, path);
|
|
||||||
|
#ifdef PLUGIN_PROJECT_MANAGEMENT
|
||||||
|
String workspace_path = Format(alo, "%S/%S", ProjectDirectory, path);
|
||||||
bool existing_buffer = GetBuffer(workspace_path, NULL);
|
bool existing_buffer = GetBuffer(workspace_path, NULL);
|
||||||
if (existing_buffer || FileExists(workspace_path)) {
|
if (existing_buffer || FileExists(workspace_path)) {
|
||||||
result.existing_buffer = existing_buffer;
|
result.existing_buffer = existing_buffer;
|
||||||
@@ -711,6 +706,7 @@ ResolvedOpen ResolveOpen(Allocator alo, String path, ResolveOpenMeta meta) {
|
|||||||
result.kind = OpenKind_Goto;
|
result.kind = OpenKind_Goto;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
String rel_path = Format(alo, "%S/%S", GetMainDir(), path);
|
String rel_path = Format(alo, "%S/%S", GetMainDir(), path);
|
||||||
existing_buffer = GetBuffer(rel_path, NULL);
|
existing_buffer = GetBuffer(rel_path, NULL);
|
||||||
@@ -828,67 +824,6 @@ void CMD_ToggleFullscreen() {
|
|||||||
IsInFullscreen = !IsInFullscreen;
|
IsInFullscreen = !IsInFullscreen;
|
||||||
} RegisterCommand(CMD_ToggleFullscreen, "f11");
|
} RegisterCommand(CMD_ToggleFullscreen, "f11");
|
||||||
|
|
||||||
void CMD_SetWorkDirHere() {
|
|
||||||
BSet main = GetBSet(PrimaryWindowID);
|
|
||||||
SetWorkDirHere(GetDir(main.buffer));
|
|
||||||
} RegisterCommand(CMD_SetWorkDirHere, "", "Sets work directory to the directory of the current buffer, it also renames couple special buffers to make them accomodate the new WorkDir");
|
|
||||||
|
|
||||||
void Coro_OpenCode(mco_coro *co) {
|
|
||||||
Array<String> patterns = SplitWhitespace(CoCurr->arena, OpenCodePatterns);
|
|
||||||
Array<String> exclude_patterns = SplitWhitespace(CoCurr->arena, OpenCodeExcludePatterns);
|
|
||||||
Array<String> dirs = {CoCurr->arena};
|
|
||||||
String *param_dir = (String *)CoCurr->user_ctx;
|
|
||||||
Add(&dirs, *param_dir);
|
|
||||||
for (int diri = 0; diri < dirs.len; diri += 1) {
|
|
||||||
for (FileIter it = IterateFiles(CoCurr->arena, dirs[diri]); IsValid(it); Advance(&it)) {
|
|
||||||
bool should_open = true;
|
|
||||||
if (!it.is_directory) {
|
|
||||||
should_open = false;
|
|
||||||
ForItem (ending, patterns) {
|
|
||||||
if (EndsWith(it.absolute_path, ending)) {
|
|
||||||
should_open = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ForItem (ending, exclude_patterns) {
|
|
||||||
if (EndsWith(it.absolute_path, ending)) {
|
|
||||||
should_open = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!should_open) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (it.is_directory) {
|
|
||||||
Add(&dirs, it.absolute_path);
|
|
||||||
} else {
|
|
||||||
BufferOpenFile(it.absolute_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
CoYield(co);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenCode(String dir) {
|
|
||||||
CoRemove("Coro_OpenCode");
|
|
||||||
CoData *data = CoAdd(Coro_OpenCode);
|
|
||||||
String *string_param = AllocType(data->arena, String);
|
|
||||||
*string_param = Copy(data->arena, dir);
|
|
||||||
data->user_ctx = string_param;
|
|
||||||
data->dont_wait_until_resolved = true;
|
|
||||||
CoResume(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMD_OpenCode() {
|
|
||||||
OpenCode(WorkDir);
|
|
||||||
} RegisterCommand(CMD_OpenCode, "", "Open all code files in current WorkDir, the code files are determined through NonCodePatterns_EndsWith config variable list");
|
|
||||||
|
|
||||||
void CMD_KillProcess() {
|
void CMD_KillProcess() {
|
||||||
BSet main = GetBSet(PrimaryWindowID);
|
BSet main = GetBSet(PrimaryWindowID);
|
||||||
KillProcess(main.view);
|
KillProcess(main.view);
|
||||||
@@ -1539,95 +1474,58 @@ void CMD_ReplaceAll() {
|
|||||||
CoResume(data);
|
CoResume(data);
|
||||||
} RegisterCommand(CMD_ReplaceAll, "ctrl-shift-r", "Search and replace over the entire project, you need to select a text with format like this 'FindAnd@>ReplaceWith' and executing the command will change all occurences of FindAnd to ReplaceWith");
|
} RegisterCommand(CMD_ReplaceAll, "ctrl-shift-r", "Search and replace over the entire project, you need to select a text with format like this 'FindAnd@>ReplaceWith' and executing the command will change all occurences of FindAnd to ReplaceWith");
|
||||||
|
|
||||||
struct SearchProjectParams {
|
void Coro_OpenCode(mco_coro *co) {
|
||||||
String16 needle;
|
Array<String> patterns = SplitWhitespace(CoCurr->arena, OpenCodePatterns);
|
||||||
BufferID buffer;
|
Array<String> exclude_patterns = SplitWhitespace(CoCurr->arena, OpenCodeExcludePatterns);
|
||||||
};
|
Array<String> dirs = {CoCurr->arena};
|
||||||
|
String *param_dir = (String *)CoCurr->user_ctx;
|
||||||
void Coro_SearchProject(mco_coro *co) {
|
Add(&dirs, *param_dir);
|
||||||
SearchProjectParams *param = (SearchProjectParams *)CoCurr->user_ctx;
|
for (int diri = 0; diri < dirs.len; diri += 1) {
|
||||||
|
for (FileIter it = IterateFiles(CoCurr->arena, dirs[diri]); IsValid(it); Advance(&it)) {
|
||||||
Array<BufferID> buffers = {CoCurr->arena};
|
bool should_open = true;
|
||||||
For (Buffers) {
|
if (!it.is_directory) {
|
||||||
Add(&buffers, it->id);
|
should_open = false;
|
||||||
}
|
ForItem (ending, patterns) {
|
||||||
|
if (EndsWith(it.absolute_path, ending)) {
|
||||||
ForItem (id, buffers) {
|
should_open = true;
|
||||||
Buffer *it = GetBuffer(id, NULL);
|
break;
|
||||||
if (it == NULL || it->special || it->is_dir || it->temp || it->dont_try_to_save_in_bulk_ops) {
|
}
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
Scratch scratch;
|
|
||||||
Array<Caret> occurences = FindAll(scratch, it, param->needle);
|
|
||||||
Buffer *out_buffer = GetBuffer(param->buffer);
|
|
||||||
ForItem (caret, occurences) {
|
|
||||||
Int pos = caret.range.min;
|
|
||||||
Int line = PosToLine(it, pos);
|
|
||||||
Range range = GetLineRangeWithoutNL(it, line);
|
|
||||||
Int column = pos - range.min;
|
|
||||||
String16 line_string = GetString(it, range);
|
|
||||||
String line_string8 = ToString(scratch, line_string);
|
|
||||||
RawAppendf(out_buffer, "%S ||> %S:%lld:%lld\n", line_string8, it->name, (long long)line + 1, (long long)column + 1);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
CoYield(co);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateSearchProjectView() {
|
ForItem (ending, exclude_patterns) {
|
||||||
Scratch scratch;
|
if (EndsWith(it.absolute_path, ending)) {
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
should_open = false;
|
||||||
String16 line_string = GetLineStringWithoutNL(active.buffer, 0);
|
break;
|
||||||
uint64_t hash = HashBytes(line_string.data, line_string.len * sizeof(char16_t));
|
}
|
||||||
if (active.view->prev_search_line_hash != hash) {
|
}
|
||||||
active.view->prev_search_line_hash = hash;
|
|
||||||
if (line_string.len > 0) {
|
|
||||||
// @todo: do we reintroduce history here? like in fuzzy search view
|
|
||||||
Caret caret = active.view->carets[0];
|
|
||||||
SelectEntireBuffer(active.view);
|
|
||||||
Replace(active.view, line_string);
|
|
||||||
Append(active.view, "\n", false);
|
|
||||||
|
|
||||||
CoRemove("Coro_SearchProject");
|
if (!should_open) {
|
||||||
CoData *dat = CoAdd(Coro_SearchProject);
|
continue;
|
||||||
SearchProjectParams *param = AllocType(dat->arena, SearchProjectParams);
|
}
|
||||||
param->needle = Copy16(dat->arena, line_string);
|
|
||||||
param->buffer = active.buffer->id;
|
|
||||||
dat->user_ctx = param;
|
|
||||||
dat->dont_wait_until_resolved = true;
|
|
||||||
CoResume(dat);
|
|
||||||
|
|
||||||
active.view->carets[0] = caret;
|
|
||||||
|
if (it.is_directory) {
|
||||||
|
Add(&dirs, it.absolute_path);
|
||||||
|
} else {
|
||||||
|
BufferOpenFile(it.absolute_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
CoYield(co);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMD_SearchProject() {
|
void OpenCode(String dir) {
|
||||||
BSet main = GetBSet(PrimaryWindowID);
|
CoRemove("Coro_OpenCode");
|
||||||
String16 string = {};
|
CoData *data = CoAdd(Coro_OpenCode);
|
||||||
if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) {
|
String *string_param = AllocType(data->arena, String);
|
||||||
string = GetString(main.buffer, main.view->carets[0].range);
|
*string_param = Copy(data->arena, dir);
|
||||||
}
|
data->user_ctx = string_param;
|
||||||
|
data->dont_wait_until_resolved = true;
|
||||||
|
CoResume(data);
|
||||||
|
}
|
||||||
|
|
||||||
NextActiveWindowID = main.window->id;
|
void CMD_OpenCode() {
|
||||||
Buffer *search_project_buffer = GetBuffer(SearchProjectBufferID);
|
OpenCode(ProjectDirectory);
|
||||||
View *view = WindowOpenBufferView(main.window, search_project_buffer->name);
|
} RegisterCommand(CMD_OpenCode, "", "Open all code files in current ProjectDirectory, the code files are determined through NonCodePatterns_EndsWith config variable list");
|
||||||
view->special = true;
|
|
||||||
AddCommand(&view->commands, "Open", "ctrl-q | enter | f12", []() {
|
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
|
||||||
BSet main = GetBSet(PrimaryWindowID);
|
|
||||||
NextActiveWindowID = main.window->id;
|
|
||||||
String16 string = FetchFuzzyViewLoadLine(active.view);
|
|
||||||
main.window->active_goto_list = active.view->id;
|
|
||||||
main.window->goto_list_pos = active.view->carets[0].range.min;
|
|
||||||
Open(string);
|
|
||||||
});
|
|
||||||
view->update_hook = UpdateSearchProjectView;
|
|
||||||
SelectRange(view, GetLineRangeWithoutNL(search_project_buffer, 0));
|
|
||||||
if (string.len) {
|
|
||||||
Replace(view, string);
|
|
||||||
SelectEntireBuffer(view);
|
|
||||||
}
|
|
||||||
} RegisterCommand(CMD_SearchProject, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view");
|
|
||||||
|
|||||||
@@ -59,7 +59,10 @@ WindowID NullWindowID;
|
|||||||
BufferID BuildBufferID;
|
BufferID BuildBufferID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BufferID SearchProjectBufferID;
|
#ifdef PLUGIN_SEARCH_OPEN_BUFFERS
|
||||||
|
BufferID SearchOpenBuffersBufferID;
|
||||||
|
#endif
|
||||||
|
|
||||||
BufferID GlobalConfigBufferID;
|
BufferID GlobalConfigBufferID;
|
||||||
|
|
||||||
WindowID NextActiveWindowID;
|
WindowID NextActiveWindowID;
|
||||||
@@ -180,7 +183,6 @@ RegisterVariable(Int, DrawScrollbar, 1);
|
|||||||
RegisterVariable(Int, IndentSize, 4);
|
RegisterVariable(Int, IndentSize, 4);
|
||||||
RegisterVariable(String, IndentKindWhichIsTabsOrSpaces, "spaces");
|
RegisterVariable(String, IndentKindWhichIsTabsOrSpaces, "spaces");
|
||||||
RegisterVariable(Int, FontSize, 15);
|
RegisterVariable(Int, FontSize, 15);
|
||||||
RegisterVariable(String, WorkDir, "");
|
|
||||||
RegisterVariable(String, PathToFont, "");
|
RegisterVariable(String, PathToFont, "");
|
||||||
RegisterVariable(String, WindowsVCVarsPathToLoadDevEnviroment, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
|
RegisterVariable(String, WindowsVCVarsPathToLoadDevEnviroment, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
|
||||||
RegisterVariable(Float, UndoMergeTime, 0.3);
|
RegisterVariable(Float, UndoMergeTime, 0.3);
|
||||||
@@ -190,7 +192,9 @@ RegisterVariable(String, OpenCodePatterns, ".c .h .cpp .hpp .cc .cxx .rs .go .zi
|
|||||||
RegisterVariable(String, OpenCodeExcludePatterns, "");
|
RegisterVariable(String, OpenCodeExcludePatterns, "");
|
||||||
RegisterVariable(Int, TrimTrailingWhitespace, 1);
|
RegisterVariable(Int, TrimTrailingWhitespace, 1);
|
||||||
|
|
||||||
// BEGIN PLUGIN_REMEDYBG
|
// PROJECT_MANAGEMENT
|
||||||
|
RegisterVariable(String, ProjectDirectory, "");
|
||||||
|
|
||||||
|
// PLUGIN_REMEDYBG
|
||||||
RegisterVariable(String, BinaryUnderDebug, "build/te.exe");
|
RegisterVariable(String, BinaryUnderDebug, "build/te.exe");
|
||||||
RegisterVariable(String, RemedyBGPath, "remedybg.exe");
|
RegisterVariable(String, RemedyBGPath, "remedybg.exe");
|
||||||
// END PLUGIN_REMEDYBG
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
void InitBuildWindow() {
|
void InitBuildWindow() {
|
||||||
Window *window = CreateWind();
|
Window *window = CreateWind();
|
||||||
BuildWindowID = window->id;
|
BuildWindowID = window->id;
|
||||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "build"));
|
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "build"));
|
||||||
buffer->special = true;
|
buffer->special = true;
|
||||||
buffer->no_history = true;
|
buffer->no_history = true;
|
||||||
BuildBufferID = buffer->id;
|
BuildBufferID = buffer->id;
|
||||||
@@ -32,7 +32,7 @@ BSet ExecBuild(String cmd) {
|
|||||||
BSet main = GetBSet(PrimaryWindowID);
|
BSet main = GetBSet(PrimaryWindowID);
|
||||||
SelectRange(build.view, Range{});
|
SelectRange(build.view, Range{});
|
||||||
ResetBuffer(build.buffer);
|
ResetBuffer(build.buffer);
|
||||||
Exec(build.view->id, true, cmd, WorkDir);
|
Exec(build.view->id, true, cmd, ProjectDirectory);
|
||||||
main.window->active_goto_list = build.view->id;
|
main.window->active_goto_list = build.view->id;
|
||||||
main.window->goto_list_pos = 0;
|
main.window->goto_list_pos = 0;
|
||||||
return build;
|
return build;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void LayoutCommandWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
|||||||
void InitCommandWindow() {
|
void InitCommandWindow() {
|
||||||
Window *window = CreateWind();
|
Window *window = CreateWind();
|
||||||
CommandWindowID = window->id;
|
CommandWindowID = window->id;
|
||||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "command_bar"));
|
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "command_bar"));
|
||||||
buffer->special = true;
|
buffer->special = true;
|
||||||
buffer->no_history = true;
|
buffer->no_history = true;
|
||||||
View *view = CreateView(buffer->id);
|
View *view = CreateView(buffer->id);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ void InitDebugWindow() {
|
|||||||
window->primary = false;
|
window->primary = false;
|
||||||
window->jump_history = false;
|
window->jump_history = false;
|
||||||
|
|
||||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "debug"));
|
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "debug"));
|
||||||
DebugBufferID = buffer->id;
|
DebugBufferID = buffer->id;
|
||||||
buffer->no_history = true;
|
buffer->no_history = true;
|
||||||
buffer->special = true;
|
buffer->special = true;
|
||||||
|
|||||||
15
src/text_editor/plugin_project_management.cpp
Normal file
15
src/text_editor/plugin_project_management.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
void SetProjectDirectory(String dir) {
|
||||||
|
ProjectDirectory = Intern(&GlobalInternTable, dir);
|
||||||
|
Scratch scratch;
|
||||||
|
For (Buffers) {
|
||||||
|
if (it->special) {
|
||||||
|
String name = SkipToLastSlash(it->name);
|
||||||
|
it->name = Intern(&GlobalInternTable, Format(scratch, "%S/%S", dir, name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMD_SetProjectDirectoryHere() {
|
||||||
|
BSet main = GetBSet(PrimaryWindowID);
|
||||||
|
SetProjectDirectory(GetDir(main.buffer));
|
||||||
|
} RegisterCommand(CMD_SetProjectDirectoryHere, "", "Sets work directory to the directory of the current buffer, it also renames couple special buffers to make them accomodate the new ProjectDirectory");
|
||||||
3
src/text_editor/plugin_project_management.h
Normal file
3
src/text_editor/plugin_project_management.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#define PLUGIN_PROJECT_MANAGEMENT
|
||||||
|
|
||||||
|
void SetProjectDirectory(String name);
|
||||||
@@ -2135,9 +2135,9 @@ bool RDBG_InitConnection() {
|
|||||||
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
MemoryZero(RDBG_Ctx.last_error, sizeof(RDBG_Ctx.last_error));
|
||||||
|
|
||||||
rdbg_Id cfg_id;
|
rdbg_Id cfg_id;
|
||||||
char *exe = Format(scratch, "%S/%S", WorkDir, BinaryUnderDebug).data;
|
char *exe = Format(scratch, "%S/%S", ProjectDirectory, BinaryUnderDebug).data;
|
||||||
char *args = NULL;
|
char *args = NULL;
|
||||||
char *work_dir = WorkDir.data;
|
char *work_dir = ProjectDirectory.data;
|
||||||
char *env = NULL;
|
char *env = NULL;
|
||||||
AddSessionConfig(&RDBG_Ctx, exe, args, work_dir, env, true, true, &res, &cfg_id);
|
AddSessionConfig(&RDBG_Ctx, exe, args, work_dir, env, true, true, &res, &cfg_id);
|
||||||
if (ContextHadError(&RDBG_Ctx)) {
|
if (ContextHadError(&RDBG_Ctx)) {
|
||||||
|
|||||||
92
src/text_editor/plugin_search_open_buffers.cpp
Normal file
92
src/text_editor/plugin_search_open_buffers.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
struct SearchOpenBuffersParams {
|
||||||
|
String16 needle;
|
||||||
|
BufferID buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
void Coro_SearchOpenBuffers(mco_coro *co) {
|
||||||
|
SearchOpenBuffersParams *param = (SearchOpenBuffersParams *)CoCurr->user_ctx;
|
||||||
|
|
||||||
|
Array<BufferID> buffers = {CoCurr->arena};
|
||||||
|
For (Buffers) {
|
||||||
|
Add(&buffers, it->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ForItem (id, buffers) {
|
||||||
|
Buffer *it = GetBuffer(id, NULL);
|
||||||
|
if (it == NULL || it->special || it->is_dir || it->temp || it->dont_try_to_save_in_bulk_ops) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Scratch scratch;
|
||||||
|
Array<Caret> occurences = FindAll(scratch, it, param->needle);
|
||||||
|
Buffer *out_buffer = GetBuffer(param->buffer);
|
||||||
|
ForItem (caret, occurences) {
|
||||||
|
Int pos = caret.range.min;
|
||||||
|
Int line = PosToLine(it, pos);
|
||||||
|
Range range = GetLineRangeWithoutNL(it, line);
|
||||||
|
Int column = pos - range.min;
|
||||||
|
String16 line_string = GetString(it, range);
|
||||||
|
String line_string8 = ToString(scratch, line_string);
|
||||||
|
RawAppendf(out_buffer, "%S ||> %S:%lld:%lld\n", line_string8, it->name, (long long)line + 1, (long long)column + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CoYield(co);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateSearchOpenBuffersView() {
|
||||||
|
Scratch scratch;
|
||||||
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
String16 line_string = GetLineStringWithoutNL(active.buffer, 0);
|
||||||
|
uint64_t hash = HashBytes(line_string.data, line_string.len * sizeof(char16_t));
|
||||||
|
if (active.view->prev_search_line_hash != hash) {
|
||||||
|
active.view->prev_search_line_hash = hash;
|
||||||
|
if (line_string.len > 0) {
|
||||||
|
// @todo: do we reintroduce history here? like in fuzzy search view
|
||||||
|
Caret caret = active.view->carets[0];
|
||||||
|
SelectEntireBuffer(active.view);
|
||||||
|
Replace(active.view, line_string);
|
||||||
|
Append(active.view, "\n", false);
|
||||||
|
|
||||||
|
CoRemove("Coro_SearchOpenBuffers");
|
||||||
|
CoData *dat = CoAdd(Coro_SearchOpenBuffers);
|
||||||
|
SearchOpenBuffersParams *param = AllocType(dat->arena, SearchOpenBuffersParams);
|
||||||
|
param->needle = Copy16(dat->arena, line_string);
|
||||||
|
param->buffer = active.buffer->id;
|
||||||
|
dat->user_ctx = param;
|
||||||
|
dat->dont_wait_until_resolved = true;
|
||||||
|
CoResume(dat);
|
||||||
|
|
||||||
|
active.view->carets[0] = caret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMD_SearchOpenBuffers() {
|
||||||
|
BSet main = GetBSet(PrimaryWindowID);
|
||||||
|
String16 string = {};
|
||||||
|
if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) {
|
||||||
|
string = GetString(main.buffer, main.view->carets[0].range);
|
||||||
|
}
|
||||||
|
|
||||||
|
NextActiveWindowID = main.window->id;
|
||||||
|
Buffer *search_project_buffer = GetBuffer(SearchOpenBuffersBufferID);
|
||||||
|
View *view = WindowOpenBufferView(main.window, search_project_buffer->name);
|
||||||
|
view->special = true;
|
||||||
|
AddCommand(&view->commands, "Open", "ctrl-q | enter | f12", []() {
|
||||||
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
BSet main = GetBSet(PrimaryWindowID);
|
||||||
|
NextActiveWindowID = main.window->id;
|
||||||
|
String16 string = FetchFuzzyViewLoadLine(active.view);
|
||||||
|
main.window->active_goto_list = active.view->id;
|
||||||
|
main.window->goto_list_pos = active.view->carets[0].range.min;
|
||||||
|
Open(string);
|
||||||
|
});
|
||||||
|
view->update_hook = UpdateSearchOpenBuffersView;
|
||||||
|
SelectRange(view, GetLineRangeWithoutNL(search_project_buffer, 0));
|
||||||
|
if (string.len) {
|
||||||
|
Replace(view, string);
|
||||||
|
SelectEntireBuffer(view);
|
||||||
|
}
|
||||||
|
} RegisterCommand(CMD_SearchOpenBuffers, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view");
|
||||||
1
src/text_editor/plugin_search_open_buffers.h
Normal file
1
src/text_editor/plugin_search_open_buffers.h
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#define PLUGIN_SEARCH_OPEN_BUFFERS
|
||||||
@@ -58,7 +58,7 @@ void CMD_ToggleSearchWordBoundary() {
|
|||||||
void InitSearchWindow() {
|
void InitSearchWindow() {
|
||||||
Window *window = CreateWind();
|
Window *window = CreateWind();
|
||||||
SearchWindowID = window->id;
|
SearchWindowID = window->id;
|
||||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "search"));
|
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "search"));
|
||||||
buffer->special = true;
|
buffer->special = true;
|
||||||
SearchBufferID = buffer->id;
|
SearchBufferID = buffer->id;
|
||||||
View *view = CreateView(buffer->id);
|
View *view = CreateView(buffer->id);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
void InitStatusWindow() {
|
void InitStatusWindow() {
|
||||||
Window *window = CreateWind();
|
Window *window = CreateWind();
|
||||||
StatusWindowID = window->id;
|
StatusWindowID = window->id;
|
||||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "status_bar"));
|
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectDirectory, "status_bar"));
|
||||||
buffer->special = true;
|
buffer->special = true;
|
||||||
View *view = CreateView(buffer->id);
|
View *view = CreateView(buffer->id);
|
||||||
view->special = true;
|
view->special = true;
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#include "plugin_debug_window.h"
|
#include "plugin_debug_window.h"
|
||||||
#include "plugin_status_window.h"
|
#include "plugin_status_window.h"
|
||||||
#include "plugin_build_window.h"
|
#include "plugin_build_window.h"
|
||||||
|
#include "plugin_project_management.h"
|
||||||
|
#include "plugin_search_open_buffers.h"
|
||||||
#if OS_WINDOWS
|
#if OS_WINDOWS
|
||||||
#include "plugin_remedybg.h"
|
#include "plugin_remedybg.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -37,7 +39,9 @@
|
|||||||
#include "draw.cpp"
|
#include "draw.cpp"
|
||||||
#include "test/tests.cpp"
|
#include "test/tests.cpp"
|
||||||
|
|
||||||
|
#include "commands_search_open_buffers.cpp"
|
||||||
#include "commands_clipboard.cpp"
|
#include "commands_clipboard.cpp"
|
||||||
|
#include "plugin_project_management.cpp"
|
||||||
#include "plugin_command_window.cpp"
|
#include "plugin_command_window.cpp"
|
||||||
#include "plugin_search_window.cpp"
|
#include "plugin_search_window.cpp"
|
||||||
#include "plugin_status_window.cpp"
|
#include "plugin_status_window.cpp"
|
||||||
@@ -718,7 +722,7 @@ void Windows_SetupVCVarsall(mco_coro *co) {
|
|||||||
View *view = NULL;
|
View *view = NULL;
|
||||||
{
|
{
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String working_dir = WorkDir;
|
String working_dir = ProjectDirectory;
|
||||||
String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-");
|
String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-");
|
||||||
String cmd = Format(scratch, "\"%S\" && set", WindowsVCVarsPathToLoadDevEnviroment);
|
String cmd = Format(scratch, "\"%S\" && set", WindowsVCVarsPathToLoadDevEnviroment);
|
||||||
view = ExecHidden(buffer_name, cmd, working_dir);
|
view = ExecHidden(buffer_name, cmd, working_dir);
|
||||||
@@ -836,7 +840,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WorkDir = GetWorkingDir(Perm);
|
ProjectDirectory = GetWorkingDir(Perm);
|
||||||
{
|
{
|
||||||
String sdl_config_path = SDL_GetPrefPath("krzosa", "text_editor");
|
String sdl_config_path = SDL_GetPrefPath("krzosa", "text_editor");
|
||||||
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '\\') {
|
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '\\') {
|
||||||
@@ -939,7 +943,6 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportConsolef(":Set WorkDir '%S'", WorkDir);
|
|
||||||
if (Testing) InitTests();
|
if (Testing) InitTests();
|
||||||
#if OS_WINDOWS
|
#if OS_WINDOWS
|
||||||
CoRemove("Windows_SetupVCVarsall");
|
CoRemove("Windows_SetupVCVarsall");
|
||||||
|
|||||||
Reference in New Issue
Block a user