From 9844c679b4a4fb42c97f80e5653dea7c73ff0edf Mon Sep 17 00:00:00 2001 From: pommicket Date: Mon, 2 Jan 2023 12:22:14 -0500 Subject: restructure ide-*.c --- ide-autocomplete.c | 8 +++++--- ide-definitions.c | 2 ++ ide-highlights.c | 4 +++- ide-hover.c | 4 +++- ide-signature-help.c | 2 ++ ide-usages.c | 2 ++ main.c | 1 + ted.h | 53 +++++++++++++++++++++++++++++++++++++++++++--------- 8 files changed, 62 insertions(+), 14 deletions(-) diff --git a/ide-autocomplete.c b/ide-autocomplete.c index bec2112..ed9617d 100644 --- a/ide-autocomplete.c +++ b/ide-autocomplete.c @@ -1,3 +1,5 @@ +#include "ted.h" + #define TAGS_MAX_COMPLETIONS 200 // max # of tag completions to scroll through #define AUTOCOMPLETE_NCOMPLETIONS_VISIBLE 10 // max # of completions to show at once @@ -25,7 +27,7 @@ static void autocomplete_complete(Ted *ted, Autocompletion completion) { autocomplete_close(ted); } -static void autocomplete_select_cursor_completion(Ted *ted) { +void autocomplete_select_cursor_completion(Ted *ted) { Autocomplete *ac = &ted->autocomplete; if (ac->open) { size_t nsuggestions = arr_len(ac->suggested); @@ -64,11 +66,11 @@ static void autocomplete_move_cursor(Ted *ted, i32 by) { autocomplete_correct_scroll(ted); } -static void autocomplete_next(Ted *ted) { +void autocomplete_next(Ted *ted) { autocomplete_move_cursor(ted, 1); } -static void autocomplete_prev(Ted *ted) { +void autocomplete_prev(Ted *ted) { autocomplete_move_cursor(ted, -1); } diff --git a/ide-definitions.c b/ide-definitions.c index cd7f3f2..0152376 100644 --- a/ide-definitions.c +++ b/ide-definitions.c @@ -1,3 +1,5 @@ +#include "ted.h" + void definition_cancel_lookup(Ted *ted) { Definitions *defs = &ted->definitions; ted_cancel_lsp_request(ted, defs->last_request_lsp, defs->last_request_id); diff --git a/ide-highlights.c b/ide-highlights.c index f53fb19..511a2fe 100644 --- a/ide-highlights.c +++ b/ide-highlights.c @@ -1,3 +1,5 @@ +#include "ted.h" + void highlights_close(Ted *ted) { Highlights *hls = &ted->highlights; arr_clear(hls->highlights); @@ -6,7 +8,7 @@ void highlights_close(Ted *ted) { hls->requested_position = (LSPDocumentPosition){0}; } -void highlights_send_request(Ted *ted) { +static void highlights_send_request(Ted *ted) { TextBuffer *buffer = ted->active_buffer; Highlights *hls = &ted->highlights; if (!buffer) { diff --git a/ide-hover.c b/ide-hover.c index 1d6ccbc..ecca8d8 100644 --- a/ide-hover.c +++ b/ide-hover.c @@ -1,5 +1,7 @@ // LSP hover information (textDocument/hover request) +#include "ted.h" + void hover_close(Ted *ted) { Hover *hover = &ted->hover; hover->open = false; @@ -22,7 +24,7 @@ static bool get_hover_position(Ted *ted, LSPDocumentPosition *pos, TextBuffer ** return false; } -void hover_send_request(Ted *ted) { +static void hover_send_request(Ted *ted) { Hover *hover = &ted->hover; LSPRequest request = {.type = LSP_REQUEST_HOVER}; LSPRequestHover *h = &request.data.hover; diff --git a/ide-signature-help.c b/ide-signature-help.c index 97dc8c3..0e6fd91 100644 --- a/ide-signature-help.c +++ b/ide-signature-help.c @@ -1,5 +1,7 @@ // deals with textDocument/signatureHelp LSP requests +#include "ted.h" + static void signature_help_clear(SignatureHelp *help) { for (int i = 0; i < help->signature_count; ++i) { Signature sig = help->signatures[i]; diff --git a/ide-usages.c b/ide-usages.c index 70a44f1..0bfdb05 100644 --- a/ide-usages.c +++ b/ide-usages.c @@ -1,3 +1,5 @@ +#include "ted.h" + void usages_cancel_lookup(Ted *ted) { Usages *usages = &ted->usages; if (usages->last_request_id) { diff --git a/main.c b/main.c index 7bd1415..2f06cdf 100644 --- a/main.c +++ b/main.c @@ -31,6 +31,7 @@ - bad json can give "Unexpected error: client exited without proper shutdown sequence" FUTURE FEATURES: - comment-start + comment-end settings +- go to declaration with LSP - robust find (results shouldn't move around when you type things) - multiple files with command line arguments - :set-build-command diff --git a/ted.h b/ted.h index c25a53e..21e421a 100644 --- a/ted.h +++ b/ted.h @@ -810,6 +810,50 @@ void gl_geometry_rect_border(Rect r, float border_thickness, u32 color); void gl_geometry_draw(void); GLuint gl_load_texture_from_image(const char *path); +// === ide-autocomplete.c === +void autocomplete_select_cursor_completion(Ted *ted); +void autocomplete_scroll(Ted *ted, i32 by); +void autocomplete_next(Ted *ted); +void autocomplete_prev(Ted *ted); +void autocomplete_close(Ted *ted); +void autocomplete_update_suggested(Ted *ted); + +// === ide-definitions.c === +// go to the definition of `name`. +// if `lsp` is NULL, tags will be used. +// Note: the document position is required for LSP requests because of overloading (where the name +// alone isn't sufficient) +void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition pos); +void definitions_selector_open(Ted *ted); +void definitions_selector_update(Ted *ted); +void definitions_selector_render(Ted *ted, Rect bounds); +void definitions_selector_close(Ted *ted); + +// === ide-highlights.c === +void highlights_close(Ted *ted); +void highlights_process_lsp_response(Ted *ted, LSPResponse *response); +void highlights_frame(Ted *ted); + +// === ide-hover.c === +void hover_close(Ted *ted); +void hover_process_lsp_response(Ted *ted, LSPResponse *response); +void hover_frame(Ted *ted, double dt); + +// === ide-signature-help.c === +void signature_help_send_request(Ted *ted); +void signature_help_retrigger(Ted *ted); +void signature_help_open(Ted *ted, char32_t trigger); +bool signature_help_is_open(Ted *ted); +void signature_help_close(Ted *ted); +void signature_help_process_lsp_response(Ted *ted, const LSPResponse *response); +void signature_help_frame(Ted *ted); + +// === ide-usages.c === +void usages_cancel_lookup(Ted *ted); +void usages_find(Ted *ted); +void usages_process_lsp_response(Ted *ted, LSPResponse *response); +void usages_frame(Ted *ted); + // === menu.c === void menu_close(Ted *ted); void menu_open(Ted *ted, Menu menu); @@ -938,14 +982,5 @@ void menu_open(Ted *ted, Menu menu); void menu_close(Ted *ted); void autocomplete_close(Ted *ted); void signature_help_retrigger(Ted *ted); -// go to the definition of `name`. -// if `lsp` is NULL, tags will be used. -// Note: the document position is required for LSP requests because of overloading (where the name -// alone isn't sufficient) -void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition pos); -void definitions_selector_open(Ted *ted); -void definitions_selector_update(Ted *ted); -void definitions_selector_render(Ted *ted, Rect bounds); -void definitions_selector_close(Ted *ted); #endif -- cgit v1.2.3