|
8 | 8 | local Buffer = require 'std.nvim.buffer' |
9 | 9 | local Window = require 'std.nvim.window' |
10 | 10 | local async = require 'std.async' |
| 11 | +local throttle = require 'std.throttle' |
11 | 12 | ---Convert a buffer position to a human-readable (1, 1)-indexed string. |
12 | 13 | ---Takes the workspace into account in order to return a relative path. |
13 | 14 | ---@param buffer Buffer |
@@ -98,6 +99,7 @@ local options = { |
98 | 99 |
|
99 | 100 | autoopen = true, |
100 | 101 | autopause = false, |
| 102 | + update_cooldown = 50, |
101 | 103 | indicators = 'auto', |
102 | 104 | show_processing = true, |
103 | 105 | show_no_info_message = false, |
@@ -203,6 +205,9 @@ function Infoview:new(obj) |
203 | 205 | }, self) |
204 | 206 | new_infoview.info = Info:new { infoview = new_infoview } |
205 | 207 | new_infoview.info:render() |
| 208 | + new_infoview.__throttled_pin_update = throttle(options.update_cooldown, function(pin) |
| 209 | + pin:update() |
| 210 | + end) |
206 | 211 | return new_infoview |
207 | 212 | end |
208 | 213 |
|
@@ -720,7 +725,19 @@ function Infoview:__update() |
720 | 725 | end |
721 | 726 | info:update_last_window() |
722 | 727 | local cursor = vim.api.nvim_win_get_cursor(0) |
723 | | - info:move_pin(Buffer:current(), { cursor[1] - 1, cursor[2] }) |
| 728 | + local buffer = Buffer:current() |
| 729 | + local pos = { cursor[1] - 1, cursor[2] } |
| 730 | + |
| 731 | + -- Update the diff pin first, while the extmark is still at the old |
| 732 | + -- position (it reads the extmark to get the "previous" location). |
| 733 | + if info.__auto_diff_pin then |
| 734 | + info:__update_auto_diff_pin(buffer, pos) |
| 735 | + end |
| 736 | + -- Move the extmark immediately so the pin indicator stays responsive, |
| 737 | + -- but throttle the LSP request + render so rapid cursor movement |
| 738 | + -- doesn't flood the server. |
| 739 | + info.pin:__update_extmark(buffer, pos) |
| 740 | + self.__throttled_pin_update(info.pin) |
724 | 741 | end |
725 | 742 |
|
726 | 743 | ---Directly mark that the infoview has died. What a shame. |
|
0 commit comments