diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 3f00281e155..247ebaf42da 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -3133,30 +3133,34 @@ for which LSP on-type-formatting should be requested." (when-let (doc (and (not briefp) sigdoc (eglot--format-markup sigdoc))) (goto-char (point-max)) (insert "\n" (replace-regexp-in-string "^" " " doc))) + ;; Perhaps highlight active parameter in the formals list + (let + ((active-param (or sig-active activeParameter))) + (when (and active-param (< -1 active-param (length parameters))) + (save-excursion + (goto-char (point-min)) + (pcase-let + ((`(,beg ,end) + (eglot--dbind ((ParameterInformation) + ((:label parlabel))) + (aref parameters active-param) + (if (stringp parlabel) + (let ((case-fold-search nil)) + (and (search-forward parlabel (line-end-position) t) + (list (match-beginning 0) (match-end 0)))) + (mapcar #'1+ (append parlabel nil)))))) + (if (and beg end) + (add-face-text-property + beg end + 'eldoc-highlight-function-argument))))) ;; Now to the parameters (cl-loop - with active-param = (or sig-active activeParameter) for i from 0 for parameter across parameters do (eglot--dbind ((ParameterInformation) ((:label parlabel)) ((:documentation pardoc))) parameter - ;; ...perhaps highlight it in the formals list - (when (and (eq i active-param)) - (save-excursion - (goto-char (point-min)) - (pcase-let - ((`(,beg ,end) - (if (stringp parlabel) - (let ((case-fold-search nil)) - (and (search-forward parlabel (line-end-position) t) - (list (match-beginning 0) (match-end 0)))) - (mapcar #'1+ (append parlabel 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. + ;; Maybe add its doc on a line by its own. (let (fpardoc) (when (and pardoc (not briefp) (not (string-empty-p @@ -3166,7 +3170,7 @@ for which LSP on-type-formatting should be requested." (if (stringp parlabel) parlabel (apply #'substring siglabel (mapcar #'1+ parlabel))) 'face (and (eq i active-param) 'eldoc-highlight-function-argument)) - ": " fpardoc))))) + ": " fpardoc)))))) (buffer-string)))) (defun eglot-signature-eldoc-function (cb)