16 Feb 2026

Using advice to limit lsp-ui-doc nuisance

I've switched back to lsp-mode temporarily until I've had time to fix a few things with my eglot setup. Returning prompted me to finally address an irritating behaviour with lsp-ui-doc.

No matter what I set lsp-ui-doc-position to it ends up covering information that I want to see. While waiting for a fix I decided to work around it. It seems to me that this is exactly what advice is for.

I came up with the following to make sure the frame appears on the half of the buffer where point isn't.

(defun my-lsp-ui-doc-wrapper (&rest _)
  (let* ((pos-line (- (line-number-at-pos (point))
                      (line-number-at-pos (window-start))))
         (pos (if (<= pos-line (/ (window-body-height) 2))
                  'bottom
                'top)))
    (setopt lsp-ui-doc-position pos)))

(advice-add 'lsp-ui-doc--move-frame :before #'my-lsp-ui-doc-wrapper)
Tags: emacs lsp-mode
Comment here.