lsp-ui icon indicating copy to clipboard operation
lsp-ui copied to clipboard

lsp-ui-doc frame overlaps with the active line

Open laynor opened this issue 3 years ago • 1 comments

I noticed this issue when editing rust files. If the line has warnings (which are displayed on the right in the buffer in my config, which is the spacemacs default) the doc frame overlaps with the line currently being edited as shown in the screenshot. image

The frame placement is perfect otherwise.

laynor avatar Jun 22 '21 04:06 laynor

Right now I'm using this hack to make the situation more bearable:

  (defun lsp-ui-doc--mv-at-point (width height start-x start-y)
    "Return position of FRAME to be where the point is.
WIDTH is the child frame width.
HEIGHT is the child frame height.
START-X is the position x of the current window.
START-Y is the position y of the current window.
The algorithm prefers to position FRAME just above the
symbol at point, to not obstruct the view of the code that follows.
If there's no space above in the current window, it places
FRAME just below the symbol at point."
    (-let* (((x . y) (--> (or lsp-ui-doc--bounds (bounds-of-thing-at-point 'symbol))
                       (or (posn-x-y (posn-at-point (car it)))
                           (if (< (car it) (window-start))
                               (cons 0 0)
                             (posn-x-y (posn-at-point (1- (window-end))))))))
            (frame-relative-symbol-x (+ start-x x (* (frame-char-width) 2)))
            (frame-relative-symbol-y (+ start-y y))
            (char-height (frame-char-height))
            ;; Make sure the frame is positioned horizontally such that
            ;; it does not go beyond the frame boundaries.
            (frame-x (or (and (<= (frame-outer-width) (+ frame-relative-symbol-x width))
                              (- x (- (+ frame-relative-symbol-x width)
                                      (frame-outer-width))))
                         x))
            (frame-y (+ (or (and (<= height frame-relative-symbol-y)
                                 (- y height))
                            (+ y char-height))
                        (if (fboundp 'window-tab-line-height) (window-tab-line-height) 0)))
            (foo (if (flycheck-overlay-errors-at (point))   ;; <------- the skew of the doc window always appears to be 1 line approx
                     (+ 4 (- char-height)) ;; The 4 is maybe related to the doc window border?
                   0)))
      (cons (+ start-x frame-x) (+ start-y frame-y foo))))

laynor avatar Jun 23 '21 05:06 laynor