summaryrefslogtreecommitdiff
path: root/ide-document-link.c
blob: d0e1ef803d4d5f5dde879adf91815dca679a90b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "ted.h"

void document_link_frame(Ted *ted) {
	DocumentLink *document_link = &ted->document_link;
	
	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;
	}
	
	TextBuffer *buffer = ted->active_buffer;
	if (!buffer)
		return;
	
	LSP *lsp = buffer_lsp(buffer);
	if (!lsp)
		return;
	
	if (!document_link->last_request.id) {
		// send the request
		LSPRequest request = {.type = LSP_REQUEST_DOCUMENT_LINK};
		LSPRequestDocumentLink *lnk = &request.data.document_link;
		lnk->document = buffer_lsp_document_id(buffer);
		document_link->last_request = lsp_send_request(lsp, &request);
	}
}

void document_link_process_lsp_response(Ted *ted, const LSPResponse *response) {
	if (response->request.type != LSP_REQUEST_DOCUMENT_LINK)
		return;
	
	(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));
		
	}
}