aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2023-03-25 19:53:14 +0000
committerJoão Távora2023-04-02 23:40:46 +0100
commitd00e05daa96700860dbb9dc6527105e464ffb960 (patch)
tree3e5f7816d343f56b68e0ff0862df90c3d06cec77
parentd69d0b1a296c17508663afc9d0301b8ccaa7115e (diff)
downloademacs-d00e05daa96700860dbb9dc6527105e464ffb960.tar.gz
emacs-d00e05daa96700860dbb9dc6527105e464ffb960.zip
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.
-rw-r--r--lisp/progmodes/eglot.el116
1 files 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."
3096 (mapconcat #'eglot--format-markup 3096 (mapconcat #'eglot--format-markup
3097 (if (vectorp contents) contents (list contents)) "\n")) 3097 (if (vectorp contents) contents (list contents)) "\n"))
3098 3098
3099(defun eglot--sig-info (sigs active-sig sig-help-active-param) 3099(defun eglot--sig-info (sig &optional _activep sig-help-active-param)
3100 (cl-loop 3100 (eglot--dbind ((SignatureInformation) label documentation parameters activeParameter)
3101 for (sig . moresigs) on (append sigs nil) for i from 0 3101 sig
3102 concat 3102 (with-temp-buffer
3103 (eglot--dbind ((SignatureInformation) label documentation parameters activeParameter) sig 3103 (save-excursion (insert label))
3104 (with-temp-buffer 3104 (let ((active-param (or activeParameter sig-help-active-param))
3105 (save-excursion (insert label)) 3105 params-start params-end)
3106 (let ((active-param (or activeParameter sig-help-active-param)) 3106 ;; Ad-hoc attempt to parse label as <name>(<params>)
3107 params-start params-end) 3107 (when (looking-at "\\([^(]*\\)(\\([^)]+\\))")
3108 ;; Ad-hoc attempt to parse label as <name>(<params>) 3108 (setq params-start (match-beginning 2) params-end (match-end 2))
3109 (when (looking-at "\\([^(]*\\)(\\([^)]+\\))") 3109 (add-face-text-property (match-beginning 1) (match-end 1)
3110 (setq params-start (match-beginning 2) params-end (match-end 2)) 3110 'font-lock-function-name-face))
3111 (add-face-text-property (match-beginning 1) (match-end 1) 3111 ;; Decide whether to add one-line-summary to signature line
3112 'font-lock-function-name-face)) 3112 (when (and (stringp documentation)
3113 (when (eql i active-sig) 3113 (string-match "[[:space:]]*\\([^.\r\n]+[.]?\\)"
3114 ;; Decide whether to add one-line-summary to signature line 3114 documentation))
3115 (when (and (stringp documentation) 3115 (setq documentation (match-string 1 documentation))
3116 (string-match "[[:space:]]*\\([^.\r\n]+[.]?\\)" 3116 (unless (string-prefix-p (string-trim documentation) label)
3117 documentation)) 3117 (goto-char (point-max))
3118 (setq documentation (match-string 1 documentation)) 3118 (insert ": " (eglot--format-markup documentation))))
3119 (unless (string-prefix-p (string-trim documentation) label) 3119 ;; Decide what to do with the active parameter...
3120 (goto-char (point-max)) 3120 (when (and active-param (< -1 active-param (length parameters)))
3121 (insert ": " (eglot--format-markup documentation)))) 3121 (eglot--dbind ((ParameterInformation) label documentation)
3122 ;; Decide what to do with the active parameter... 3122 (aref parameters active-param)
3123 (when (and (eql i active-sig) active-param 3123 ;; ...perhaps highlight it in the formals list
3124 (< -1 active-param (length parameters))) 3124 (when params-start
3125 (eglot--dbind ((ParameterInformation) label documentation) 3125 (goto-char params-start)
3126 (aref parameters active-param) 3126 (pcase-let
3127 ;; ...perhaps highlight it in the formals list 3127 ((`(,beg ,end)
3128 (when params-start 3128 (if (stringp label)
3129 (goto-char params-start) 3129 (let ((case-fold-search nil))
3130 (pcase-let 3130 (and (re-search-forward
3131 ((`(,beg ,end) 3131 (concat "\\<" (regexp-quote label) "\\>")
3132 params-end t)
3133 (list (match-beginning 0) (match-end 0))))
3134 (mapcar #'1+ (append label nil)))))
3135 (if (and beg end)
3136 (add-face-text-property
3137 beg end
3138 'eldoc-highlight-function-argument))))
3139 ;; ...and/or maybe add its doc on a line by its own.
3140 (when documentation
3141 (goto-char (point-max))
3142 (insert "\n"
3143 (propertize
3132 (if (stringp label) 3144 (if (stringp label)
3133 (let ((case-fold-search nil)) 3145 label
3134 (and (re-search-forward 3146 (apply #'buffer-substring (mapcar #'1+ label)))
3135 (concat "\\<" (regexp-quote label) "\\>") 3147 'face 'eldoc-highlight-function-argument)
3136 params-end t) 3148 ": " (eglot--format-markup documentation))))))
3137 (list (match-beginning 0) (match-end 0)))) 3149 (buffer-string))))
3138 (mapcar #'1+ (append label nil)))))
3139 (if (and beg end)
3140 (add-face-text-property
3141 beg end
3142 'eldoc-highlight-function-argument))))
3143 ;; ...and/or maybe add its doc on a line by its own.
3144 (when documentation
3145 (goto-char (point-max))
3146 (insert "\n"
3147 (propertize
3148 (if (stringp label)
3149 label
3150 (apply #'buffer-substring (mapcar #'1+ label)))
3151 'face 'eldoc-highlight-function-argument)
3152 ": " (eglot--format-markup documentation))))))
3153 (buffer-string))))
3154 when moresigs concat "\n"))
3155 3150
3156(defun eglot-signature-eldoc-function (cb) 3151(defun eglot-signature-eldoc-function (cb)
3157 "A member of `eldoc-documentation-functions', for signatures." 3152 "A member of `eldoc-documentation-functions', for signatures."
@@ -3164,11 +3159,12 @@ for which LSP on-type-formatting should be requested."
3164 (eglot--lambda ((SignatureHelp) 3159 (eglot--lambda ((SignatureHelp)
3165 signatures activeSignature activeParameter) 3160 signatures activeSignature activeParameter)
3166 (eglot--when-buffer-window buf 3161 (eglot--when-buffer-window buf
3167 (funcall cb 3162 (let ((active-sig (and (cl-plusp (length signatures))
3168 (unless (seq-empty-p signatures) 3163 (aref signatures (or activeSignature 0)))))
3169 (eglot--sig-info signatures 3164 (if (not active-sig) (funcall cb nil)
3170 activeSignature 3165 (funcall cb
3171 activeParameter))))) 3166 (mapconcat #'eglot--sig-info signatures "\n")
3167 :echo (eglot--sig-info active-sig t activeParameter))))))
3172 :deferred :textDocument/signatureHelp)) 3168 :deferred :textDocument/signatureHelp))
3173 t)) 3169 t))
3174 3170