Add better eglot doc function

This commit is contained in:
Alexander Rosenberg 2023-10-05 21:43:36 -07:00
parent aba461a801
commit 5f1ac858a2
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

28
init.el
View File

@ -391,10 +391,34 @@ visual states."
python-ts-mode latex-mode) . eglot-ensure) python-ts-mode latex-mode) . eglot-ensure)
(eglot-managed-mode . my/-eglot-setup)) (eglot-managed-mode . my/-eglot-setup))
:init :init
(defvar my/-eglot-documentation-buffer nil
"Buffer for showing documentation for `my/eglot-documentation-at-point'.")
(defun my/eglot-documentation-at-point ()
"Show documentation for a symbol at point."
(interactive)
(if-let (server (eglot-current-server))
(progn
(if-let* (((not (buffer-live-p my/-eglot-documentation-buffer)))
(name (generate-new-buffer-name "*eglot documentation*")))
(setq my/-eglot-documentation-buffer (generate-new-buffer name)))
(eglot-hover-eldoc-function
(lambda (info _ _)
(if-let (((not (seq-empty-p info)))
(buff (current-buffer)))
(with-current-buffer my/-eglot-documentation-buffer
(read-only-mode -1)
(erase-buffer)
(insert info)
(special-mode)
(read-only-mode 1)
(when (not (get-buffer-window my/-eglot-documentation-buffer nil))
(switch-to-buffer-other-window my/-eglot-documentation-buffer t)
(switch-to-buffer-other-window buff t)))))))))
(defun my/-eglot-setup () (defun my/-eglot-setup ()
"Setup eldoc variables for `eglot-managed-mode-hook'." "Setup eldoc variables for `eglot-managed-mode-hook'."
(setq-local eldoc-echo-area-use-multiline-p (setq-local eldoc-echo-area-use-multiline-p nil
nil) evil-lookup-func #'my/eglot-documentation-at-point)
(evil-define-key '(normal motion) 'local "K" #'evil-lookup)
(eglot-inlay-hints-mode -1)) (eglot-inlay-hints-mode -1))
(advice-add 'eglot-completion-at-point :around #'cape-wrap-buster) (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster)
(setq eglot-autoshutdown t)) (setq eglot-autoshutdown t))