]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix small problems around eglot's help buffer
authorJoão Távora <joaotavora@gmail.com>
Sun, 31 May 2020 10:49:51 +0000 (11:49 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sun, 31 May 2020 10:58:25 +0000 (11:58 +0100)
Specifically:

- correctly format the message shown to the user about doc being truncated
- don't show message if the buffer is showing in some frame's window
- correctly name the help buffer switched to with `C-h .'.

This is still not ideal:

- When the `C-h .' suggestion is shown to the user, typing that keybinding
  shouldn't result in a new LSP request to fetch probably the same info;
- All this functionality belongs in eldoc.el.

* eglot.el (eglot-help-at-point): Fix buffer name.
(eglot--update-doc): Provide more help.

lisp/progmodes/eglot.el

index 4b25368d735ed8bdc5229540f0be9e02db03f2f0..733b69c395d9d4802b609d57da578f4d2c366e08 100644 (file)
@@ -2270,12 +2270,12 @@ is not active."
       (jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover
                        (eglot--TextDocumentPositionParams))
     (let ((blurb (and (not (seq-empty-p contents))
-                      (eglot--hover-info contents range))))
+                      (eglot--hover-info contents range)))
+          (hint (thing-at-point 'symbol)))
       (if blurb
           (with-current-buffer (eglot--help-buffer)
             (with-help-window (current-buffer)
-              (rename-buffer (format "*eglot-help for %s*"
-                                     (thing-at-point 'symbol)))
+              (rename-buffer (format "*eglot-help for %s*" hint))
               (with-current-buffer standard-output (insert blurb))
               (setq-local nobreak-char-display nil)))
         (display-local-help)))))
@@ -2350,16 +2350,18 @@ documentation.  Honour `eglot-put-doc-in-help-buffer',
                (erase-buffer)
                (insert string)
                (goto-char (point-min)))
-             (if eglot-auto-display-help-buffer
-                 (display-buffer (current-buffer))
-               (unless (get-buffer-window (current-buffer))
-                 ;; This prints two lines.  Should it print 1?  Or
-                 ;; honour max-mini-window-height?
-                 (eglot--message
-                  "%s\n(...truncated. Full help is in `%s')"
-                  (eglot--truncate-string string 1 (- (frame-width) 8))
-                  (buffer-name eglot--help-buffer))))
-             (help-mode))))
+             (help-mode)))
+         (if eglot-auto-display-help-buffer
+             (display-buffer eglot--help-buffer)
+           (unless (get-buffer-window eglot--help-buffer t)
+             ;; Hand-tweaked to print two lines.  Should it print
+             ;; 1?  Or honour max-mini-window-height?
+             (eglot--message
+              "%s\n(Truncated, %sfull help in buffer %s)"
+              (eglot--truncate-string string 1 (- (frame-width) 9))
+              (if-let (key (car (where-is-internal 'eglot-help-at-point)))
+                  (format "use %s to see " (key-description key)) "")
+              (buffer-name eglot--help-buffer)))))
         ((eq eldoc-echo-area-use-multiline-p t)
          (if-let ((available (eglot-doc-too-large-for-echo-area string)))
              (eldoc-message (eglot--truncate-string string available))