diff options
author | pommicket <pommicket@gmail.com> | 2022-12-30 22:07:03 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-30 22:07:03 -0500 |
commit | 94ce74b998ad019e2307e4b69f006127dba775e2 (patch) | |
tree | eee0d731cd5897f3825fb7892e5f1f670eef0a2c /ted.c | |
parent | f69275faee4cd3045389a98fefefb0c683757a5c (diff) |
document highlights!
Diffstat (limited to 'ted.c')
-rw-r--r-- | ted.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -567,3 +567,40 @@ void ted_go_to_lsp_document_position(Ted *ted, LSP *lsp, LSPDocumentPosition pos u32 character = position.pos.character; ted_go_to_position(ted, path, line, character, true); } + +void ted_highlight_lsp_range(Ted *ted, 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; + 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]); + } +} |