]> git.eshelyaron.com Git - emacs.git/commitdiff
Adjust active param highlighting in first line of signature (1/3)
authorFredrik Bergroth <fbergroth@gmail.com>
Thu, 13 Dec 2018 11:59:57 +0000 (12:59 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sun, 16 Dec 2018 13:51:57 +0000 (13:51 +0000)
JT@2018/12/16: Previously, the whole first line of the rendered
documentation was searched for, potentially highlighting params
in the wrong place.

Copyright-paperwork-exempt: yes

* eglot.el (eglot--sig-info): Search for active parameter within
`params-start` and `params-end`.

lisp/progmodes/eglot.el

index 2b51c2155bc49b9dd4566b9375fa9e68330e66d9..46cfb595fe51aff6b141fafa6d3ccc57f4af0148 100644 (file)
@@ -1941,38 +1941,41 @@ is not active."
    (eglot--dbind ((SignatureInformation) label documentation parameters) sig
      (with-temp-buffer
        (save-excursion (insert label))
-       (when (looking-at "\\([^(]+\\)(")
-         (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 (point-min))
-           (let ((case-fold-search nil))
-             (cl-loop for nmatches from 0
-                      while (and (not (string-empty-p label))
-                                 (search-forward label nil t))
-                      finally do
-                      (when (= 1 nmatches)
-                        (add-face-text-property
-                         (- (point) (length label)) (point)
-                         'eldoc-highlight-function-argument))))
-           (when documentation
+       (let ((params-start (point-min))
+             (params-end (point-max)))
+         (when (looking-at "\\([^(]+\\)(")
+           (setq params-start (match-end 0))
+           (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 "\n"
-                     (propertize
-                      label 'face 'eldoc-highlight-function-argument)
-                     ": " (eglot--format-markup documentation)))))
-       (buffer-string)))
+             (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 ((case-fold-search nil))
+               (cl-loop for nmatches from 0
+                        while (and (not (string-empty-p label))
+                                   (search-forward label params-end t))
+                        finally do
+                        (when (= 1 nmatches)
+                          (add-face-text-property
+                           (- (point) (length label)) (point)
+                           'eldoc-highlight-function-argument))))
+             (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"))
 
 (defun eglot-help-at-point ()