emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master d00e05daa96 04/10: Eglot: take advantage of new Eldoc options for


From: João Távora
Subject: master d00e05daa96 04/10: Eglot: take advantage of new Eldoc options for signature doc
Date: Sun, 2 Apr 2023 19:15:39 -0400 (EDT)

branch: master
commit d00e05daa96700860dbb9dc6527105e464ffb960
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Eglot: take advantage of new Eldoc options for signature doc
    
    Only echo the "active signature", send all the other signatures for
    the *eldoc* buffer.
    
    * lisp/progmodes/eglot.el (eglot--sig-info): Rework protocol.
    (eglot-signature-eldoc-function): Rework.
---
 lisp/progmodes/eglot.el | 116 +++++++++++++++++++++++-------------------------
 1 file changed, 56 insertions(+), 60 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 8e47c397ca8..04fc7235919 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -3096,62 +3096,57 @@ for which LSP on-type-formatting should be requested."
   (mapconcat #'eglot--format-markup
              (if (vectorp contents) contents (list contents)) "\n"))
 
-(defun eglot--sig-info (sigs active-sig sig-help-active-param)
-  (cl-loop
-   for (sig . moresigs) on (append sigs nil) for i from 0
-   concat
-   (eglot--dbind ((SignatureInformation) label documentation parameters 
activeParameter) sig
-     (with-temp-buffer
-       (save-excursion (insert label))
-       (let ((active-param (or activeParameter sig-help-active-param))
-             params-start params-end)
-         ;; Ad-hoc attempt to parse label as <name>(<params>)
-         (when (looking-at "\\([^(]*\\)(\\([^)]+\\))")
-           (setq params-start (match-beginning 2) params-end (match-end 2))
-           (add-face-text-property (match-beginning 1) (match-end 1)
-                                   'font-lock-function-name-face))
-         (when (eql i active-sig)
-           ;; Decide whether to add one-line-summary to signature line
-           (when (and (stringp documentation)
-                      (string-match "[[:space:]]*\\([^.\r\n]+[.]?\\)"
-                                    documentation))
-             (setq documentation (match-string 1 documentation))
-             (unless (string-prefix-p (string-trim documentation) label)
-               (goto-char (point-max))
-               (insert ": " (eglot--format-markup documentation))))
-           ;; Decide what to do with the active parameter...
-           (when (and (eql i active-sig) active-param
-                      (< -1 active-param (length parameters)))
-             (eglot--dbind ((ParameterInformation) label documentation)
-                 (aref parameters active-param)
-               ;; ...perhaps highlight it in the formals list
-               (when params-start
-                 (goto-char params-start)
-                 (pcase-let
-                     ((`(,beg ,end)
+(defun eglot--sig-info (sig &optional _activep sig-help-active-param)
+  (eglot--dbind ((SignatureInformation) label documentation parameters 
activeParameter)
+      sig
+    (with-temp-buffer
+      (save-excursion (insert label))
+      (let ((active-param (or activeParameter sig-help-active-param))
+            params-start params-end)
+        ;; Ad-hoc attempt to parse label as <name>(<params>)
+        (when (looking-at "\\([^(]*\\)(\\([^)]+\\))")
+          (setq params-start (match-beginning 2) params-end (match-end 2))
+          (add-face-text-property (match-beginning 1) (match-end 1)
+                                  'font-lock-function-name-face))
+        ;; Decide whether to add one-line-summary to signature line
+        (when (and (stringp documentation)
+                   (string-match "[[:space:]]*\\([^.\r\n]+[.]?\\)"
+                                 documentation))
+          (setq documentation (match-string 1 documentation))
+          (unless (string-prefix-p (string-trim documentation) label)
+            (goto-char (point-max))
+            (insert ": " (eglot--format-markup documentation))))
+        ;; Decide what to do with the active parameter...
+        (when (and active-param (< -1 active-param (length parameters)))
+          (eglot--dbind ((ParameterInformation) label documentation)
+              (aref parameters active-param)
+            ;; ...perhaps highlight it in the formals list
+            (when params-start
+              (goto-char params-start)
+              (pcase-let
+                  ((`(,beg ,end)
+                    (if (stringp label)
+                        (let ((case-fold-search nil))
+                          (and (re-search-forward
+                                (concat "\\<" (regexp-quote label) "\\>")
+                                params-end t)
+                               (list (match-beginning 0) (match-end 0))))
+                      (mapcar #'1+ (append label nil)))))
+                (if (and beg end)
+                    (add-face-text-property
+                     beg end
+                     'eldoc-highlight-function-argument))))
+            ;; ...and/or maybe add its doc on a line by its own.
+            (when documentation
+              (goto-char (point-max))
+              (insert "\n"
+                      (propertize
                        (if (stringp label)
-                           (let ((case-fold-search nil))
-                             (and (re-search-forward
-                                   (concat "\\<" (regexp-quote label) "\\>")
-                                   params-end t)
-                                  (list (match-beginning 0) (match-end 0))))
-                         (mapcar #'1+ (append label nil)))))
-                   (if (and beg end)
-                       (add-face-text-property
-                        beg end
-                        'eldoc-highlight-function-argument))))
-               ;; ...and/or maybe add its doc on a line by its own.
-               (when documentation
-                 (goto-char (point-max))
-                 (insert "\n"
-                         (propertize
-                          (if (stringp label)
-                              label
-                            (apply #'buffer-substring (mapcar #'1+ label)))
-                          'face 'eldoc-highlight-function-argument)
-                         ": " (eglot--format-markup documentation))))))
-         (buffer-string))))
-   when moresigs concat "\n"))
+                           label
+                         (apply #'buffer-substring (mapcar #'1+ label)))
+                       'face 'eldoc-highlight-function-argument)
+                      ": " (eglot--format-markup documentation))))))
+      (buffer-string))))
 
 (defun eglot-signature-eldoc-function (cb)
   "A member of `eldoc-documentation-functions', for signatures."
@@ -3164,11 +3159,12 @@ for which LSP on-type-formatting should be requested."
        (eglot--lambda ((SignatureHelp)
                        signatures activeSignature activeParameter)
          (eglot--when-buffer-window buf
-           (funcall cb
-                    (unless (seq-empty-p signatures)
-                      (eglot--sig-info signatures
-                                       activeSignature
-                                       activeParameter)))))
+           (let ((active-sig (and (cl-plusp (length signatures))
+                                  (aref signatures (or activeSignature 0)))))
+             (if (not active-sig) (funcall cb nil)
+               (funcall cb
+                        (mapconcat #'eglot--sig-info signatures "\n")
+                        :echo (eglot--sig-info active-sig t 
activeParameter))))))
        :deferred :textDocument/signatureHelp))
     t))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]