From d6b2cc80723ce6e8454449bcdcdcb495f7a08ad9 Mon Sep 17 00:00:00 2001 From: pommicket Date: Wed, 28 Dec 2022 12:25:18 -0500 Subject: refresh signature help when cursor moved or buffer switched --- buffer.c | 1 + lsp-parse.c | 1 - lsp-write.c | 3 +++ main.c | 5 +++++ signature-help.c | 19 +++++++++++++++++-- ted.c | 2 ++ ted.h | 3 +++ 7 files changed, 31 insertions(+), 3 deletions(-) diff --git a/buffer.c b/buffer.c index 9796eb5..8d20a6f 100644 --- a/buffer.c +++ b/buffer.c @@ -1186,6 +1186,7 @@ void buffer_cursor_move_to_pos(TextBuffer *buffer, BufferPos pos) { buffer->cursor_pos = pos; buffer->selection = false; buffer_scroll_to_cursor(buffer); + signature_help_retrigger(buffer->ted); } i64 buffer_cursor_move_left(TextBuffer *buffer, i64 by) { diff --git a/lsp-parse.c b/lsp-parse.c index e780ee7..828c672 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -118,7 +118,6 @@ static void parse_capabilities(LSP *lsp, const JSON *json, JSONObject capabiliti if (signature_help_value.type == JSON_OBJECT) { cap->signature_help_support = true; JSONObject signature_help = signature_help_value.val.object; - json_debug_print_object(json, signature_help); JSONArray trigger_chars = json_object_get_array(json, signature_help, "triggerCharacters"); lsp->signature_help_trigger_chars = parse_trigger_characters(json, trigger_chars); JSONArray retrigger_chars = json_object_get_array(json, signature_help, "retriggerCharacters"); diff --git a/lsp-write.c b/lsp-write.c index 910eb1b..406faa5 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -397,6 +397,9 @@ static void write_request(LSP *lsp, LSPRequest *request) { write_key_obj_start(o, "signatureHelp"); // we don't have context support because sending the activeSignatureHelp member is annoying //write_key_bool(o, "contextSupport", true); + write_key_obj_start(o, "signatureInformation"); + write_key_bool(o, "activeParameterSupport", true); + write_obj_end(o); write_obj_end(o); write_obj_end(o); write_key_obj_start(o, "workspace"); diff --git a/main.c b/main.c index 4e06699..cca34ee 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,10 @@ /* @TODO: +Unrecognized request method: language/status +Unrecognized request method: client/registerCapability +Unrecognized request method: workspace/executeClientCommand +- why is jdtls not giving us signatures? +- why is clangd not giving us active parameter? - more LSP stuff: - signature help - hover diff --git a/signature-help.c b/signature-help.c index 4b7e847..27f9203 100644 --- a/signature-help.c +++ b/signature-help.c @@ -1,14 +1,26 @@ // deals with textDocument/signatureHelp LSP requests -void signature_help_open(Ted *ted, char32_t trigger) { - (void)trigger; // for now we don't send context +void signature_help_send_request(Ted *ted) { TextBuffer *buffer = ted->active_buffer; if (!buffer) return; LSP *lsp = buffer_lsp(buffer); + if (!lsp) return; LSPRequest request = {.type = LSP_REQUEST_SIGNATURE_HELP}; LSPRequestSignatureHelp *s = &request.data.signature_help; s->position = buffer_cursor_pos_as_lsp_document_position(buffer); lsp_send_request(lsp, &request); + ted->signature_help.retrigger = false; +} + +void signature_help_retrigger(Ted *ted) { + // don't just send the request here -- we don't want to send more than + // one request per frame. + ted->signature_help.retrigger = true; +} + +void signature_help_open(Ted *ted, char32_t trigger) { + (void)trigger; // for now we don't send context + signature_help_send_request(ted); } bool signature_help_is_open(Ted *ted) { @@ -66,6 +78,8 @@ void signature_help_process_lsp_response(Ted *ted, const LSPResponse *response) void signature_help_frame(Ted *ted) { SignatureHelp *help = &ted->signature_help; + if (help->retrigger) + signature_help_send_request(ted); u16 signature_count = help->signature_count; if (!signature_count) return; @@ -74,6 +88,7 @@ void signature_help_frame(Ted *ted) { TextBuffer *buffer = ted->active_buffer; if (!buffer) return; + Settings *settings = buffer_settings(buffer); u32 *colors = settings->colors; float border = settings->border_thickness; diff --git a/ted.c b/ted.c index 75a2246..222932f 100644 --- a/ted.c +++ b/ted.c @@ -241,6 +241,7 @@ void ted_switch_to_buffer(Ted *ted, TextBuffer *buffer) { if (idx == *tab) { node->active_tab = (u16)(tab - node->tabs); ted->active_node = node; + signature_help_retrigger(ted); return; } } @@ -250,6 +251,7 @@ void ted_switch_to_buffer(Ted *ted, TextBuffer *buffer) { } else { ted->active_node = NULL; } + } // set ted->active_buffer to something nice diff --git a/ted.h b/ted.h index 0f6bcdf..21d3bf5 100644 --- a/ted.h +++ b/ted.h @@ -430,6 +430,8 @@ typedef struct { // "signature help" (LSP) is thing that shows the current parameter, etc. typedef struct { + // should we resend a signature help request this frame? + bool retrigger; // if signature_count = 0, signature help is closed u16 signature_count; Signature signatures[SIGNATURE_HELP_MAX]; @@ -553,6 +555,7 @@ typedef struct Ted { } Ted; void autocomplete_close(Ted *ted); +void signature_help_retrigger(Ted *ted); char *buffer_contents_utf8_alloc(TextBuffer *buffer); void command_execute(Ted *ted, Command c, i64 argument); void ted_switch_to_buffer(Ted *ted, TextBuffer *buffer); -- cgit v1.2.3