svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
501 stars 34 forks source link

hl-line-mode lags behind debugger point movement #147

Closed brownts closed 2 months ago

brownts commented 2 months ago

I use hl-line-mode to highlight the line where point resides in the buffer. I noticed that when I step within a file (e.g., dape-step-in, dape-next, etc.), that hl-line-mode updates to the line where point is, but then the debugger steps and the cursor is placed at the next location, while hl-line-mode doesn't move to this new location until I issue another step command, therefore usually lagging by one step.

I believe this is because hl-line-mode is reacting to the initial stepping command (e.g., dape-step-in) and updates due to that, but once the debugger steps and reports back the new location, dape moves the point to this location, but it doesn't trigger the post-command-hook, which hl-line-mode uses to update. Anything that triggers the post-command-hook will cause the highlighting to update to the current point location.

I used the following to test this theory and verified that the current line is not highlighted afterwards:

(run-with-timer 5 nil (lambda () (goto-char (point-min))))

I've worked around this issue by adding hl-line-highlight to the dape-display-source-hook, but since hl-line-mode is built in to Emacs, I would think this should "just work" without needing to add the hook.

svaante commented 2 months ago

Thanks for reporting, and your analysis is spot on. That dape moves point in timer context is both a feature and a bug. It makes dape misbehave and move the point in a non command context, but it also removes all the spinlocks aka (accept-process-output).

One could "just" call post-command-hook instead of having this special handling for hl-line-mode but is more likely to break other packages (repeat-mode for example stops working). See comment for more info.

                ;; This code is running within the timer context
                ;; rather than the command context.  Since the
                ;; `post-command-hook' is executed before the point
                ;; (cursor position) is actually updated, we must
                ;; manually intervene to account for this.  The
                ;; following logic borrows from gud.el to interact
                ;; with `hl-line'.

Please reopen this issue if the commit referenced above does not fix your issue!

brownts commented 2 months ago

Yes, this fixed my issue, thanks!