summaryrefslogtreecommitdiff
path: root/ide-document-link.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-08-04 19:43:56 -0400
committerpommicket <pommicket@gmail.com>2023-08-04 19:43:56 -0400
commit4cdbd1c8caf7fbd9ed584049312241a0e039e115 (patch)
tree54dacf1d8974bffff974f87b781d4e6958fc36b7 /ide-document-link.c
parent45d69107725a02cf6d912a571b771da3ef5abfbf (diff)
more document link parsing
Diffstat (limited to 'ide-document-link.c')
-rw-r--r--ide-document-link.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/ide-document-link.c b/ide-document-link.c
index d0e1ef8..9d4803f 100644
--- a/ide-document-link.c
+++ b/ide-document-link.c
@@ -5,15 +5,6 @@ void document_link_frame(Ted *ted) {
bool key_down = ted_is_ctrl_down(ted);
if (!key_down) {
- document_link->key_press_time = 0.0;
- } else if (document_link->key_press_time == 0.0) {
- document_link->key_press_time = ted->frame_time;
- }
-
- bool show_links = document_link->key_press_time != 0.0
- && ted->frame_time - document_link->key_press_time > 1.0;
-
- if (!show_links) {
ted_cancel_lsp_request(ted, &document_link->last_request);
return;
}
@@ -36,14 +27,28 @@ void document_link_frame(Ted *ted) {
}
void document_link_process_lsp_response(Ted *ted, const LSPResponse *response) {
+ DocumentLink *document_link = &ted->document_link;
if (response->request.type != LSP_REQUEST_DOCUMENT_LINK)
return;
+ if (!document_link->last_request.id)
+ return; // request was cancelled
- (void)ted;//TODO
- const LSPResponseDocumentLink *document_link = &response->data.document_link;
-
- arr_foreach_ptr(document_link->links, const LSPDocumentLink, link) {
- printf("target: %s\n", lsp_response_string(response, link->target));
+ bool key_down = ted_is_ctrl_down(ted);
+ if (!key_down)
+ return;
+ TextBuffer *buffer = ted->active_buffer;
+ if (!buffer)
+ return;
+ if (buffer_lsp_document_id(buffer) != response->request.data.document_link.document)
+ return; // request was for a different document
+
+ const LSPResponseDocumentLink *response_data = &response->data.document_link;
+ arr_foreach_ptr(response_data->links, const LSPDocumentLink, link) {
+ BufferPos start = buffer_pos_from_lsp(buffer, link->range.start);
+ BufferPos end = buffer_pos_from_lsp(buffer, link->range.end);
+ printf("%d:%d — %d:%d\t: %s\n",
+ start.line, start.index, end.line, end.index,
+ lsp_response_string(response, link->target));
}
}