Function: eglot--sig-info

eglot--sig-info is a byte-compiled function defined in eglot.el.gz.

Signature

(eglot--sig-info SIG &optional SIG-ACTIVE BRIEFP)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(cl-defun eglot--sig-info (sig &optional sig-active briefp
                               &aux (move-fn eglot-move-to-linepos-function)
                               first-parlabel
                               fpardoc)
  (eglot--dbind ((SignatureInformation)
                 ((:label siglabel))
                 ((:documentation sigdoc)) parameters activeParameter)
      sig
    (with-temp-buffer
      (save-excursion
        ;; Insert main siglabel line
        (insert siglabel)
        ;; Add function documentation to end on a new line, indented so
        ;; we can distinguish multiple signatures
        (when-let* ((doc (and (not briefp) sigdoc (eglot--format-markup sigdoc))))
          (goto-char (point-max))
          (insert "\n" (replace-regexp-in-string "^" "  " doc))))
      ;; Back to point-min: try to highlight function name only
      (cond ((and (cl-plusp (length parameters))
                  (vectorp (setq first-parlabel
                                 (plist-get (aref parameters 0) :label))))
             (funcall move-fn (elt first-parlabel 0))
             (skip-syntax-backward "^w")
             (add-face-text-property (point-min) (point)
                                     'font-lock-function-name-face))
            ((looking-at "\\([^(]*\\)([^)]*)")
             (add-face-text-property (match-beginning 1) (match-end 1)
                                     'font-lock-function-name-face)))
      ;; Now to the parameters
      (cl-loop
       with active-param = (or activeParameter sig-active)
       with case-fold-search = nil
       for i from 0 for parameter across parameters do
       (eglot--dbind ((ParameterInformation)
                      ((:label parlabel))
                      ((:documentation pardoc)))
           parameter
         (cl-flet ((parlabel-bounds ()
                     (cond ((stringp parlabel)
                            (and (search-forward parlabel (line-end-position) t)
                                 (match-data)))
                           (t (mapcar move-fn parlabel)))))
           ;; ...perhaps highlight it in the formals list
           (when-let* ((b (and (eq i active-param)
                               (parlabel-bounds))))
             (add-face-text-property
              (car b) (cadr b)
              'eldoc-highlight-function-argument))
           ;; ...and/or maybe add its doc on a line by its own.
           (when (and pardoc (not briefp)
                      (not (string-empty-p
                            (setq fpardoc (eglot--format-markup pardoc)))))
             (unless (stringp parlabel)
               (setq parlabel (apply #'buffer-substring (parlabel-bounds))))
             (save-excursion
               (goto-char (point-max))
               (insert "\n  "
                       (propertize
                        parlabel
                        'face (and (eq i active-param) 'eldoc-highlight-function-argument))
                       ": " fpardoc))))))
      (buffer-string))))