From 5f1ac858a28c2592828bf40ec32d8c91f3b08439 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Thu, 5 Oct 2023 21:43:36 -0700 Subject: [PATCH] Add better eglot doc function --- init.el | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/init.el b/init.el index ee17de4..e1ba194 100644 --- a/init.el +++ b/init.el @@ -391,10 +391,34 @@ visual states." python-ts-mode latex-mode) . eglot-ensure) (eglot-managed-mode . my/-eglot-setup)) :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 () "Setup eldoc variables for `eglot-managed-mode-hook'." - (setq-local eldoc-echo-area-use-multiline-p - nil) + (setq-local eldoc-echo-area-use-multiline-p nil + evil-lookup-func #'my/eglot-documentation-at-point) + (evil-define-key '(normal motion) 'local "K" #'evil-lookup) (eglot-inlay-hints-mode -1)) (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster) (setq eglot-autoshutdown t))