Skip to content

Commit

Permalink
Fix cursor is not show in visible area after jump to diagnostic place.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Nov 5, 2023
1 parent 7569769 commit 9174c62
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lsp-bridge-diagnostic.el
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,25 @@ You can set this value with `(2 3 4) if you just need render error diagnostic."
(when goto-beginning
(goto-char (overlay-start diagnostic-overlay)))

;; When point not in visiable area, `posn-at-point' in `acm-frame-get-popup-position' will return nil.
;; We need scroll window to make sure point in visiable area before call `acm-frame-get-popup-position'.
(let* ((pos (window-point))
(start (window-start))
(end (window-end)))
(cond
((< pos start) (scroll-down-line (count-lines pos start)))
((> pos end) (scroll-up-line (count-lines end pos)))))

;; NOTE:
;; We need use redisplay function to make sure diagnostic show in visible area.
;; `redisplay' causes a slight flicker on the screen but currently there is no better solution.
(redisplay t)

;; Adjusting the cursor position when it is too close to the edge of the window.
(let* ((window-start-line (save-excursion
(goto-char (window-start))
(current-line)))
(window-end-line (save-excursion
(goto-char (window-end))
(current-line)))
(adjust-line-number 5))
(cond ((< (abs (- (current-line) window-start-line)) adjust-line-number)
(scroll-down-line adjust-line-number))
((< (abs (- (current-line) window-end-line)) adjust-line-number)
(scroll-up-line adjust-line-number))))

;; Show diagnostic tooltip.
(with-current-buffer (get-buffer-create lsp-bridge-diagnostic-buffer)
(erase-buffer)
(lsp-bridge-diagnostic-insert-colored-string (overlay-get diagnostic-overlay 'color) diagnostic-display-message)
Expand Down

0 comments on commit 9174c62

Please sign in to comment.