summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-07 16:19:58 -0500
committerpommicket <pommicket@gmail.com>2023-01-07 16:19:58 -0500
commitcb55279a20865fcfde23a160233155d23a09a03b (patch)
tree588764775a2f415aa7a78b02bb398578d6df0133
parent66da8ac5dcfe02d3aa79f72ba415235eb872ec1d (diff)
hover/signature cancellation
-rw-r--r--ide-hover.c16
-rw-r--r--ide-signature-help.c15
-rw-r--r--main.c3
-rw-r--r--ted.h4
4 files changed, 28 insertions, 10 deletions
diff --git a/ide-hover.c b/ide-hover.c
index 2be04ca..aed7ed1 100644
--- a/ide-hover.c
+++ b/ide-hover.c
@@ -7,6 +7,7 @@ void hover_close(Ted *ted) {
hover->open = false;
free(hover->text);
hover->text = NULL;
+ ted_cancel_lsp_request(ted, &hover->last_request);
}
static bool get_hover_position(Ted *ted, LSPDocumentPosition *pos, TextBuffer **pbuffer, LSP **lsp) {
@@ -26,13 +27,14 @@ static bool get_hover_position(Ted *ted, LSPDocumentPosition *pos, TextBuffer **
static void hover_send_request(Ted *ted) {
Hover *hover = &ted->hover;
+
+ ted_cancel_lsp_request(ted, &hover->last_request);
LSPRequest request = {.type = LSP_REQUEST_HOVER};
LSPRequestHover *h = &request.data.hover;
LSP *lsp = NULL;
if (get_hover_position(ted, &h->position, NULL, &lsp)) {
hover->requested_position = h->position;
- hover->requested_lsp = lsp->id;
- lsp_send_request(lsp, &request);
+ hover->last_request = lsp_send_request(lsp, &request);
}
}
@@ -41,6 +43,12 @@ void hover_process_lsp_response(Ted *ted, LSPResponse *response) {
if (response->request.type != LSP_REQUEST_HOVER) return;
Hover *hover = &ted->hover;
+ if (response->request.id != hover->last_request.id) {
+ // stale request
+ return;
+ }
+
+ hover->last_request.id = 0;
LSPResponseHover *hover_response = &response->data.hover;
TextBuffer *buffer=0;
@@ -53,7 +61,7 @@ void hover_process_lsp_response(Ted *ted, LSPResponse *response) {
if (hover->text // we already have hover text
&& (
- lsp->id != hover->requested_lsp // this request is from a different LSP
+ lsp->id != hover->last_request.lsp // this request is from a different LSP
|| !lsp_document_position_eq(response->request.data.hover.position, pos) // this request is for a different position
)) {
// this is a stale request. ignore it
@@ -104,7 +112,7 @@ void hover_frame(Ted *ted, double dt) {
LSPDocumentPosition pos={0};
LSP *lsp=0;
if (get_hover_position(ted, &pos, &buffer, &lsp)) {
- if (lsp->id != hover->requested_lsp
+ if (lsp->id != hover->last_request.lsp
|| !lsp_document_position_eq(pos, hover->requested_position)) {
// refresh hover
hover_send_request(ted);
diff --git a/ide-signature-help.c b/ide-signature-help.c
index 8cabdf7..87eef7d 100644
--- a/ide-signature-help.c
+++ b/ide-signature-help.c
@@ -34,7 +34,8 @@ static void signature_help_send_request(Ted *ted) {
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_cancel_lsp_request(ted, &help->last_request);
+ help->last_request = lsp_send_request(lsp, &request);
help->retrigger = false;
}
@@ -55,16 +56,24 @@ bool signature_help_is_open(Ted *ted) {
void signature_help_close(Ted *ted) {
- signature_help_clear(&ted->signature_help);
+ SignatureHelp *help = &ted->signature_help;
+ signature_help_clear(help);
+ ted_cancel_lsp_request(ted, &help->last_request);
}
void signature_help_process_lsp_response(Ted *ted, const LSPResponse *response) {
+ SignatureHelp *help = &ted->signature_help;
Settings *settings = ted_active_settings(ted);
if (!settings->signature_help_enabled) return;
if (response->request.type != LSP_REQUEST_SIGNATURE_HELP)
return;
- SignatureHelp *help = &ted->signature_help;
+ if (response->request.id != help->last_request.id) {
+ // stale request
+ return;
+ }
+ help->last_request.id = 0;
+
const LSPResponseSignatureHelp *lsp_help = &response->data.signature_help;
u32 signature_count = arr_len(lsp_help->signatures);
if (signature_count > SIGNATURE_HELP_MAX)
diff --git a/main.c b/main.c
index a1d3cab..8073262 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,6 @@
/*
@TODO:
-- cancel signature help requests
-- cancel hover requests
+- test that signature help requests and hover requests are cancelled
- don't let 0 be a valid LSPDocumentID
- TESTING: check all IDE features with different servers
- run everything through valgrind ideally with leak checking
diff --git a/ted.h b/ted.h
index 500ba0d..6300c0b 100644
--- a/ted.h
+++ b/ted.h
@@ -416,6 +416,7 @@ typedef struct {
// "signature help" (LSP) is thing that shows the current parameter, etc.
typedef struct {
+ LSPServerRequestID last_request;
// should we resend a signature help request this frame?
bool retrigger;
// if signature_count = 0, signature help is closed
@@ -425,6 +426,7 @@ typedef struct {
// "hover" information from LSP server
typedef struct {
+ LSPServerRequestID last_request;
// is some hover info being displayed?
bool open;
// text to display
@@ -432,7 +434,6 @@ typedef struct {
// where the hover data is coming from.
// we use this to check if we need to refresh it.
LSPDocumentPosition requested_position;
- LSPID requested_lsp;
LSPRange range;
double time; // how long the cursor has been hovering for
} Hover;
@@ -1367,6 +1368,7 @@ void ted_go_to_position(Ted *ted, const char *path, u32 line, u32 index, bool is
// go to this LSP document position, opening a new buffer containing the file if necessary.
void ted_go_to_lsp_document_position(Ted *ted, LSP *lsp, LSPDocumentPosition position);
// cancel this LSP request. also zeroes *request
+// if *request is zeroed, this does nothing.
void ted_cancel_lsp_request(Ted *ted, LSPServerRequestID *request);
// how tall is a line buffer?
float ted_line_buffer_height(Ted *ted);