summaryrefslogtreecommitdiff
path: root/ide-highlights.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-30 22:07:03 -0500
committerpommicket <pommicket@gmail.com>2022-12-30 22:07:03 -0500
commit94ce74b998ad019e2307e4b69f006127dba775e2 (patch)
treeeee0d731cd5897f3825fb7892e5f1f670eef0a2c /ide-highlights.c
parentf69275faee4cd3045389a98fefefb0c683757a5c (diff)
document highlights!
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();
}