diff options
-rw-r--r-- | buffer.c | 43 | ||||
-rw-r--r-- | ide-highlights.c | 2 | ||||
-rw-r--r-- | ide-hover.c | 2 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | ted.c | 37 |
5 files changed, 45 insertions, 41 deletions
@@ -3019,3 +3019,46 @@ void buffer_toggle_comment_selection(TextBuffer *buffer) { } buffer_toggle_comment_lines(buffer, l1, l2); } + + +// make sure to call gl_geometry_draw after this +void buffer_highlight_lsp_range(TextBuffer *buffer, LSPRange range) { + Font *font = buffer_font(buffer); + const u32 *colors = buffer_settings(buffer)->colors; + float char_height = font->char_height; + BufferPos range_start = buffer_pos_from_lsp(buffer, range.start); + BufferPos range_end = buffer_pos_from_lsp(buffer, range.end); + // draw the highlight + if (range_start.line == range_end.line) { + v2 a = buffer_pos_to_pixels(buffer, range_start); + v2 b = buffer_pos_to_pixels(buffer, range_end); + b.y += char_height; + Rect r = rect_endpoints(a, b); buffer_clip_rect(buffer, &r); + gl_geometry_rect(r, colors[COLOR_HOVER_HL]); + } else if (range_end.line - range_start.line < 1000) { // prevent gigantic highlights from slowing things down + // multiple lines. + v2 a = buffer_pos_to_pixels(buffer, range_start); + v2 b = buffer_pos_to_pixels(buffer, buffer_pos_end_of_line(buffer, range_start.line)); + b.y += char_height; + Rect r1 = rect_endpoints(a, b); buffer_clip_rect(buffer, &r1); + gl_geometry_rect(r1, colors[COLOR_HOVER_HL]); + + for (u32 line = range_start.line + 1; line < range_end.line; ++line) { + // these lines are fully contained in the range. + BufferPos start = buffer_pos_start_of_line(buffer, line); + BufferPos end = buffer_pos_end_of_line(buffer, line); + a = buffer_pos_to_pixels(buffer, start); + b = buffer_pos_to_pixels(buffer, end); + b.y += char_height; + Rect r = rect_endpoints(a, b); buffer_clip_rect(buffer, &r); + gl_geometry_rect(r, colors[COLOR_HOVER_HL]); + } + + // last line + a = buffer_pos_to_pixels(buffer, buffer_pos_start_of_line(buffer, range_end.line)); + b = buffer_pos_to_pixels(buffer, range_end); + b.y += char_height; + Rect r2 = rect_endpoints(a, b); buffer_clip_rect(buffer, &r2); + gl_geometry_rect(r2, colors[COLOR_HOVER_HL]); + } +} diff --git a/ide-highlights.c b/ide-highlights.c index 239f4ec..8ecf3ea 100644 --- a/ide-highlights.c +++ b/ide-highlights.c @@ -54,7 +54,7 @@ void highlights_frame(Ted *ted) { } arr_foreach_ptr(hls->highlights, LSPHighlight, hl) { - ted_highlight_lsp_range(ted, buffer, hl->range); + buffer_highlight_lsp_range(buffer, hl->range); } gl_geometry_draw(); } diff --git a/ide-hover.c b/ide-hover.c index 77aec96..9a7c0c9 100644 --- a/ide-hover.c +++ b/ide-hover.c @@ -118,7 +118,7 @@ void hover_frame(Ted *ted, double dt) { float x = ted->mouse_pos.x, y = ted->mouse_pos.y + font->char_height; float char_height = font->char_height; - ted_highlight_lsp_range(ted, buffer, hover->range); + buffer_highlight_lsp_range(buffer, hover->range); if (hover->text) { float max_width = 400; @@ -1,9 +1,7 @@ /* @TODO: - find usages (textDocument/references) -- clip highlight to buffer rect - different highlight colors -- --help, --version - framerate-cap setting - highlight-enabled, and highlight-auto - handle multiple symbols with same name in go-to-definition menu @@ -568,40 +568,3 @@ void ted_go_to_lsp_document_position(Ted *ted, LSP *lsp, LSPDocumentPosition pos ted_go_to_position(ted, path, line, character, true); } -void ted_highlight_lsp_range(Ted *ted, TextBuffer *buffer, LSPRange range) { - (void)ted; - Font *font = buffer_font(buffer); - const u32 *colors = buffer_settings(buffer)->colors; - float char_height = font->char_height; - BufferPos range_start = buffer_pos_from_lsp(buffer, range.start); - BufferPos range_end = buffer_pos_from_lsp(buffer, range.end); - // draw the highlight - if (range_start.line == range_end.line) { - v2 a = buffer_pos_to_pixels(buffer, range_start); - v2 b = buffer_pos_to_pixels(buffer, range_end); - b.y += char_height; - gl_geometry_rect(rect_endpoints(a, b), colors[COLOR_HOVER_HL]); - } else if (range_end.line - range_start.line < 1000) { // prevent gigantic highlights from slowing things down - // multiple lines. - v2 a = buffer_pos_to_pixels(buffer, range_start); - v2 b = buffer_pos_to_pixels(buffer, buffer_pos_end_of_line(buffer, range_start.line)); - b.y += char_height; - gl_geometry_rect(rect_endpoints(a, b), colors[COLOR_HOVER_HL]); - - for (u32 line = range_start.line + 1; line < range_end.line; ++line) { - // these lines are fully contained in the range. - BufferPos start = buffer_pos_start_of_line(buffer, line); - BufferPos end = buffer_pos_end_of_line(buffer, line); - a = buffer_pos_to_pixels(buffer, start); - b = buffer_pos_to_pixels(buffer, end); - b.y += char_height; - gl_geometry_rect(rect_endpoints(a, b), colors[COLOR_HOVER_HL]); - } - - // last line - a = buffer_pos_to_pixels(buffer, buffer_pos_start_of_line(buffer, range_end.line)); - b = buffer_pos_to_pixels(buffer, range_end); - b.y += char_height; - gl_geometry_rect(rect_endpoints(a, b), colors[COLOR_HOVER_HL]); - } -} |