summaryrefslogtreecommitdiff
path: root/ide-highlights.c
diff options
context:
space:
mode:
Diffstat (limited to 'ide-highlights.c')
-rw-r--r--ide-highlights.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/ide-highlights.c b/ide-highlights.c
index 4246c66..239f4ec 100644
--- a/ide-highlights.c
+++ b/ide-highlights.c
@@ -1,16 +1,29 @@
-void highlights_send_request(Ted *ted, TextBuffer *buffer) {
+static void highlights_clear(Highlights *hls) {
+ arr_clear(hls->highlights);
+}
+
+void highlights_send_request(Ted *ted) {
+ TextBuffer *buffer = ted->active_buffer;
Highlights *hls = &ted->highlights;
- if (!buffer) return;
+ if (!buffer) {
+ highlights_clear(hls);
+ return;
+ }
LSP *lsp = buffer_lsp(buffer);
- if (!lsp) return;
+ if (!lsp) {
+ highlights_clear(hls);
+ return;
+ }
LSPDocumentPosition pos = buffer_cursor_pos_as_lsp_document_position(buffer);
LSPRequest request = {.type = LSP_REQUEST_HIGHLIGHT};
request.data.highlight.position = pos;
hls->last_request_id = lsp_send_request(lsp, &request);
+ hls->last_request_lsp = lsp->id;
+ hls->requested_position = pos;
}
void highlights_close(Ted *ted) {
- arr_clear(ted->highlights.highlights);
+ highlights_clear(&ted->highlights);
}
void highlights_process_lsp_response(Ted *ted, LSPResponse *response) {
@@ -28,5 +41,20 @@ void highlights_process_lsp_response(Ted *ted, LSPResponse *response) {
void highlights_frame(Ted *ted) {
Highlights *hls = &ted->highlights;
-
+ TextBuffer *buffer = ted->active_buffer;
+ if (!buffer) {
+ highlights_clear(hls);
+ return;
+ }
+ LSPDocumentPosition pos = buffer_cursor_pos_as_lsp_document_position(buffer);
+ if (!lsp_document_position_eq(pos, hls->requested_position)) {
+ // cursor moved or something. let's resend the request.
+ highlights_clear(hls);
+ highlights_send_request(ted);
+ }
+
+ arr_foreach_ptr(hls->highlights, LSPHighlight, hl) {
+ ted_highlight_lsp_range(ted, buffer, hl->range);
+ }
+ gl_geometry_draw();
}