summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-08-12 10:41:22 -0300
committerpommicket <pommicket@gmail.com>2023-08-12 10:41:22 -0300
commitdbf441cdc74245c5a5f567ae0165146cd74c3b92 (patch)
treef1ca3bdf3102445a000bbc6e2695333150d0c0a2
parenta974b6192479e5f7f6d6fcc328313c76290f486d (diff)
more internralization
-rw-r--r--build.c12
-rw-r--r--ide-definitions.c38
-rw-r--r--macro.c22
-rw-r--r--main.c4
-rw-r--r--ted-internal.h44
-rw-r--r--ted.c5
6 files changed, 75 insertions, 50 deletions
diff --git a/build.c b/build.c
index 63658b9..771fd6d 100644
--- a/build.c
+++ b/build.c
@@ -3,6 +3,18 @@
#include "ted-internal.h"
+struct BuildError {
+ char *path;
+ u32 line;
+ u32 column;
+ /// if this is 1, then column == UTF-32 index.
+ /// if this is 4, for example, then column 4 in a line starting with a tab would
+ /// be the character right after the tab.
+ u8 columns_per_tab;
+ /// which line in the build output corresponds to this error
+ u32 build_output_line;
+};
+
void build_stop(Ted *ted) {
if (ted->building)
process_kill(&ted->build_process);
diff --git a/ide-definitions.c b/ide-definitions.c
index 57738b1..fd06ebc 100644
--- a/ide-definitions.c
+++ b/ide-definitions.c
@@ -3,8 +3,19 @@
#include "ted-internal.h"
+struct Definitions {
+ LSPServerRequestID last_request;
+ double last_request_time;
+ /// last query string which we sent a request for
+ char *last_request_query;
+ /// for "go to definition of..." menu
+ Selector selector;
+ /// an array of all definitions (gotten from workspace/symbols) for "go to definition" menu
+ SymbolInfo *all_definitions;
+};
+
void definition_cancel_lookup(Ted *ted) {
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
ted_cancel_lsp_request(ted, &defs->last_request);
}
@@ -54,7 +65,7 @@ static SymbolKind symbol_kind_to_ted(LSPSymbolKind kind) {
}
void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition position, GotoType type) {
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
if (lsp) {
// cancel old request
definition_cancel_lookup(ted);
@@ -91,7 +102,7 @@ void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition p
}
void definitions_frame(Ted *ted) {
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
if (defs->last_request.id && ted->frame_time - defs->last_request_time > 0.2) {
ted->cursor = ted->cursor_wait;
}
@@ -125,7 +136,7 @@ static int definition_entry_qsort_cmp(const void *av, const void *bv) {
// put the entries matching the search term into the selector.
static void definitions_selector_filter_entries(Ted *ted) {
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
Selector *sel = &defs->selector;
// create selector entries based on search term
@@ -159,7 +170,7 @@ static void definitions_selector_filter_entries(Ted *ted) {
void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *response) {
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
if (response->request.id != defs->last_request.id) {
// response to an old/irrelevant request
return;
@@ -244,7 +255,7 @@ void definitions_send_request_if_needed(Ted *ted) {
LSP *lsp = buffer_lsp(ted->prev_active_buffer);
if (!lsp)
return;
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
char *query = buffer_contents_utf8_alloc(ted->line_buffer);
if (defs->last_request_query && strcmp(defs->last_request_query, query) == 0) {
free(query);
@@ -262,7 +273,7 @@ void definitions_send_request_if_needed(Ted *ted) {
}
static void definitions_selector_open(Ted *ted) {
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
definitions_clear_entries(defs);
LSP *lsp = ted->prev_active_buffer
? buffer_lsp(ted->prev_active_buffer)
@@ -280,7 +291,7 @@ static void definitions_selector_open(Ted *ted) {
static bool definitions_selector_close(Ted *ted) {
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
definitions_clear_entries(defs);
ted_cancel_lsp_request(ted, &defs->last_request);
free(defs->last_request_query);
@@ -289,7 +300,7 @@ static bool definitions_selector_close(Ted *ted) {
}
static void definitions_selector_update(Ted *ted) {
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
Selector *sel = &defs->selector;
sel->enable_cursor = true;
@@ -331,7 +342,7 @@ static void definitions_selector_update(Ted *ted) {
static void definitions_selector_render(Ted *ted) {
Rect bounds = selection_menu_render_bg(ted);
- Definitions *defs = &ted->definitions;
+ Definitions *defs = ted->definitions;
Selector *sel = &defs->selector;
sel->bounds = bounds;
selector_render(ted, sel);
@@ -346,4 +357,11 @@ void definitions_init(Ted *ted) {
};
strbuf_cpy(info.name, MENU_GOTO_DEFINITION);
menu_register(ted, &info);
+
+ ted->definitions = calloc(1, sizeof *ted->definitions);
+}
+
+void definitions_quit(Ted *ted) {
+ free(ted->definitions);
+ ted->definitions = NULL;
}
diff --git a/macro.c b/macro.c
index 75c2eae..d334dd5 100644
--- a/macro.c
+++ b/macro.c
@@ -1,7 +1,17 @@
#include "ted-internal.h"
+typedef struct MacroAction {
+ Command command;
+ CommandArgument argument;
+} MacroAction;
+
+struct Macro {
+ // dynamic array
+ MacroAction *actions;
+};
+
static void macro_clear(Macro *macro) {
- arr_foreach_ptr(macro->actions, Action, act) {
+ arr_foreach_ptr(macro->actions, MacroAction, act) {
free((char *)act->argument.string);
}
arr_free(macro->actions);
@@ -34,7 +44,7 @@ void macro_add(Ted *ted, Command command, const CommandArgument *argument) {
CommandArgument arg = *argument;
if (arg.string)
arg.string = str_dup(arg.string);
- Action action = {
+ MacroAction action = {
.command = command,
.argument = arg
};
@@ -51,15 +61,21 @@ void macro_execute(Ted *ted, u32 index) {
ted->executing_macro = true;
const CommandContext context = {.running_macro = true};
- arr_foreach_ptr(macro->actions, Action, act) {
+ arr_foreach_ptr(macro->actions, MacroAction, act) {
command_execute_ex(ted, act->command, &act->argument, &context);
}
ted->executing_macro = false;
}
+void macros_init(Ted *ted) {
+ ted->macros = calloc(TED_MACRO_MAX, sizeof *ted->macros);
+}
+
void macros_free(Ted *ted) {
for (int i = 0; i < TED_MACRO_MAX; ++i) {
Macro *macro = &ted->macros[i];
macro_clear(macro);
}
+ free(ted->macros);
+ ted->macros = NULL;
}
diff --git a/main.c b/main.c
index cdc0bb2..bfaf506 100644
--- a/main.c
+++ b/main.c
@@ -498,6 +498,8 @@ int main(int argc, char **argv) {
gl_geometry_init();
text_init();
menu_init(ted);
+ find_init(ted);
+ macros_init(ted);
definitions_init(ted);
autocomplete_init(ted);
signature_help_init(ted);
@@ -506,7 +508,6 @@ int main(int argc, char **argv) {
hover_init(ted);
rename_symbol_init(ted);
document_link_init(ted);
- find_init(ted);
PROFILE_TIME(gl_end)
@@ -1199,6 +1200,7 @@ int main(int argc, char **argv) {
session_write(ted);
rename_symbol_quit(ted);
document_link_quit(ted);
+ definitions_quit(ted);
menu_quit(ted);
arr_free(ted->edit_notifys);
diff --git a/ted-internal.h b/ted-internal.h
index c986759..6de2cfd 100644
--- a/ted-internal.h
+++ b/ted-internal.h
@@ -238,17 +238,7 @@ struct Node {
/// "find" menu result
typedef struct FindResult FindResult;
-typedef struct {
- char *path;
- u32 line;
- u32 column;
- /// if this is 1, then column == UTF-32 index.
- /// if this is 4, for example, then column 4 in a line starting with a tab would
- /// be the character right after the tab.
- u8 columns_per_tab;
- /// which line in the build output corresponds to this error
- u32 build_output_line;
-} BuildError;
+typedef struct BuildError BuildError;
/// `LSPSymbolKind`s are translated to these. this is a much coarser categorization
typedef enum {
@@ -294,34 +284,14 @@ typedef struct {
LSPDocumentPosition position;
} SymbolInfo;
-typedef struct {
- LSPServerRequestID last_request;
- double last_request_time;
- /// last query string which we sent a request for
- char *last_request_query;
- /// for "go to definition of..." menu
- Selector selector;
- /// an array of all definitions (gotten from workspace/symbols) for "go to definition" menu
- SymbolInfo *all_definitions;
-} Definitions;
+typedef struct Definitions Definitions;
/// "highlight" information from LSP server
typedef struct Highlights Highlights;
-typedef struct {
- Command command;
- CommandArgument argument;
-} Action;
+typedef struct Macro Macro;
-typedef struct {
- // dynamic array
- Action *actions;
-} Macro;
-
-typedef struct {
- char *path;
- Font *font;
-} LoadedFont;
+typedef struct LoadedFont LoadedFont;
typedef struct {
vec2 pos;
@@ -341,7 +311,7 @@ struct Ted {
/// current time (see time_get_seconds), as of the start of this frame
double frame_time;
- Macro macros[TED_MACRO_MAX];
+ Macro *macros;
Macro *recording_macro;
bool executing_macro;
@@ -415,7 +385,7 @@ struct Ted {
SignatureHelp *signature_help;
DocumentLinks *document_links;
Hover *hover;
- Definitions definitions;
+ Definitions *definitions;
Highlights *highlights;
Usages *usages;
RenameSymbol *rename_symbol;
@@ -685,6 +655,7 @@ void definitions_init(Ted *ted);
void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition pos, GotoType type);
void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *response);
void definitions_frame(Ted *ted);
+void definitions_quit(Ted *ted);
// === ide-document-link.c ===
void document_link_init(Ted *ted);
@@ -724,6 +695,7 @@ void usages_quit(Ted *ted);
// === macro.c ===
void macro_add(Ted *ted, Command command, const CommandArgument *argument);
+void macros_init(Ted *ted);
void macros_free(Ted *ted);
// === menu.c ===
diff --git a/ted.c b/ted.c
index 3dfe7ce..379217d 100644
--- a/ted.c
+++ b/ted.c
@@ -5,6 +5,11 @@
#include <SDL_syswm.h>
#endif
+struct LoadedFont {
+ char *path;
+ Font *font;
+};
+
void die(const char *fmt, ...) {
char buf[256] = {0};