From: João Távora Date: Sun, 16 Dec 2018 13:48:57 +0000 (+0000) Subject: Rewrite eglot--sig-info a bit for readability X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~362 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cdb3de6bc6f9a1d4f642d1613019f947e7138c7b;p=emacs.git Rewrite eglot--sig-info a bit for readability * eglot.el (eglot--sig-info): Rewrite a bit. --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 01f6960047f..429c329c824 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1941,37 +1941,42 @@ is not active." (eglot--dbind ((SignatureInformation) label documentation parameters) sig (with-temp-buffer (save-excursion (insert label)) - (let ((params-start (point-min)) - (params-end (point-max))) - (when (looking-at "\\([^(]+\\)(") - (setq params-start (match-end 0)) + (let (params-start params-end) + ;; Ad-hoc attempt to parse label as () + (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 (and (stringp documentation) (eql i active-sig) - (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)))) - (when (and (eql i active-sig) active-param - (< -1 active-param (length parameters))) - (eglot--dbind ((ParameterInformation) label documentation) - (aref parameters active-param) - (goto-char params-start) - (let ((regex (concat "\\<" (regexp-quote label) "\\>")) - (case-fold-search nil)) - (when (re-search-forward regex params-end t) - (add-face-text-property - (- (point) (length label)) (point) - 'eldoc-highlight-function-argument))) - (when documentation + (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 "\n" - (propertize - label 'face 'eldoc-highlight-function-argument) - ": " (eglot--format-markup documentation))))) + (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) + (let ((regex (concat "\\<" (regexp-quote label) "\\>")) + (case-fold-search nil)) + (when (re-search-forward regex params-end t) + (add-face-text-property + (match-beginning 0) (match-end 0) + '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 + label 'face 'eldoc-highlight-function-argument) + ": " (eglot--format-markup documentation)))))) (buffer-string)))) when moresigs concat "\n"))