GNU bug report logs - #58777
eldoc + eglot does not highlight the function parameter the cursor is at

Previous Next

Package: emacs;

Reported by: Michał Dubiel <majkijin <at> gmail.com>

Date: Tue, 25 Oct 2022 14:54:02 UTC

Severity: normal

Tags: patch

Fixed in version 29.1

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 58777 in the body.
You can then email your comments to 58777 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#58777; Package emacs. (Tue, 25 Oct 2022 14:54:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michał Dubiel <majkijin <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 25 Oct 2022 14:54:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michał Dubiel <majkijin <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: eldoc + eglot does not highlight the function parameter the cursor is
 at
Date: Tue, 25 Oct 2022 12:47:45 +0200
[Message part 1 (text/plain, inline)]
Hi,

I have noticed an issue with highlighting the function parameters by
eldoc when using eglot + pyright python LSP server (version 1.1.276).
Assume this very simple python code:
```
def function(arg1, arg2, arg3):
    pass

function(1, 2, 3)
```

If the cursor is placed at any of the arguments of the function call
statement, eldoc does not highlight the argument the cursor is
currently at.

This happens because pyright does not include the function name in the
returned signature help label when the cursor is inside the
parentheses, i.e (cursor denoted as |) :
1. For fun|ction(arg1, arg2, arg3), the returned signature label from
pyright is:
(function) function: (arg1: Unknown, arg2: Unknown, arg3: Unknown) -> None

2. For function(1|, 2, 3) (please notice the cursor is at arg1):
(arg1: Unknown, arg2: Unknown, arg3: Unknown) -> None

Because in case 2 there is no function name but only the arguments
inside the parenthesis, the eglot's `eglot--sig-info' function fails
to parse the label correctly and mark the `params-start' and
`params-end' variables.

I believe a simple fix for this is to change the regexp pattern used
for finding the arguments in the function signature label as in the
attached patch. It ensures that the parameters are found regardless of
whether the function name was included in the signature label or not.

Regards,
Michal
[0001-eglot-Support-signature-labels-without-a-function-na.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58777; Package emacs. (Sat, 12 Nov 2022 20:46:01 GMT) Full text and rfc822 format available.

Message #8 received at 58777 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Michał Dubiel <majkijin <at> gmail.com>
Cc: 58777 <at> debbugs.gnu.org, joaotavora <at> gmail.com
Subject: Re: bug#58777: eldoc + eglot does not highlight the function
 parameter the cursor is at
Date: Sat, 12 Nov 2022 12:45:43 -0800
Copying in João; please see the below patch.

Michał Dubiel <majkijin <at> gmail.com> writes:

> Hi,
>
> I have noticed an issue with highlighting the function parameters by
> eldoc when using eglot + pyright python LSP server (version 1.1.276).
> Assume this very simple python code:
> ```
> def function(arg1, arg2, arg3):
>     pass
>
> function(1, 2, 3)
> ```
>
> If the cursor is placed at any of the arguments of the function call
> statement, eldoc does not highlight the argument the cursor is
> currently at.
>
> This happens because pyright does not include the function name in the
> returned signature help label when the cursor is inside the
> parentheses, i.e (cursor denoted as |) :
> 1. For fun|ction(arg1, arg2, arg3), the returned signature label from
> pyright is:
> (function) function: (arg1: Unknown, arg2: Unknown, arg3: Unknown) -> None
>
> 2. For function(1|, 2, 3) (please notice the cursor is at arg1):
> (arg1: Unknown, arg2: Unknown, arg3: Unknown) -> None
>
> Because in case 2 there is no function name but only the arguments
> inside the parenthesis, the eglot's `eglot--sig-info' function fails
> to parse the label correctly and mark the `params-start' and
> `params-end' variables.
>
> I believe a simple fix for this is to change the regexp pattern used
> for finding the arguments in the function signature label as in the
> attached patch. It ensures that the parameters are found regardless of
> whether the function name was included in the signature label or not.
>
> Regards,
> Michal
>
> From e9cebcd9aed7d92bd2ea0b692165e5b55adf8084 Mon Sep 17 00:00:00 2001
> From: Michal Dubiel <majkijin <at> gmail.com>
> Date: Sun, 23 Oct 2022 19:54:31 +0200
> Subject: [PATCH] eglot: Support signature labels without a function name
>
> * lisp/progmodes/eglot.el (eglot--sig-info): Support signature labels
> without a function name.
> ---
>  lisp/progmodes/eglot.el | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> index 71001ba680..f5a00b03c7 100644
> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -2909,7 +2909,7 @@ for which LSP on-type-formatting should be requested."
>         (let ((active-param (or activeParameter sig-help-active-param))
>               params-start params-end)
>           ;; Ad-hoc attempt to parse label as <name>(<params>)
> -         (when (looking-at "\\([^(]+\\)(\\([^)]+\\))")
> +         (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))




Added tag(s) patch. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 12 Nov 2022 20:46:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58777; Package emacs. (Sat, 12 Nov 2022 21:14:02 GMT) Full text and rfc822 format available.

Message #13 received at 58777 <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 58777 <at> debbugs.gnu.org, Michał Dubiel <majkijin <at> gmail.com>
Subject: Re: bug#58777: eldoc + eglot does not highlight the function
 parameter the cursor is at
Date: Sat, 12 Nov 2022 21:12:46 +0000
[Message part 1 (text/plain, inline)]
I'd say this looks good. It would be even better with a couple of automated
tests, but then again eglot-tests.el hasn't migrated to Emacs yet.

João

On Sat, Nov 12, 2022, 20:45 Stefan Kangas <stefankangas <at> gmail.com> wrote:

> Copying in João; please see the below patch.
>
> Michał Dubiel <majkijin <at> gmail.com> writes:
>
> > Hi,
> >
> > I have noticed an issue with highlighting the function parameters by
> > eldoc when using eglot + pyright python LSP server (version 1.1.276).
> > Assume this very simple python code:
> > ```
> > def function(arg1, arg2, arg3):
> >     pass
> >
> > function(1, 2, 3)
> > ```
> >
> > If the cursor is placed at any of the arguments of the function call
> > statement, eldoc does not highlight the argument the cursor is
> > currently at.
> >
> > This happens because pyright does not include the function name in the
> > returned signature help label when the cursor is inside the
> > parentheses, i.e (cursor denoted as |) :
> > 1. For fun|ction(arg1, arg2, arg3), the returned signature label from
> > pyright is:
> > (function) function: (arg1: Unknown, arg2: Unknown, arg3: Unknown) ->
> None
> >
> > 2. For function(1|, 2, 3) (please notice the cursor is at arg1):
> > (arg1: Unknown, arg2: Unknown, arg3: Unknown) -> None
> >
> > Because in case 2 there is no function name but only the arguments
> > inside the parenthesis, the eglot's `eglot--sig-info' function fails
> > to parse the label correctly and mark the `params-start' and
> > `params-end' variables.
> >
> > I believe a simple fix for this is to change the regexp pattern used
> > for finding the arguments in the function signature label as in the
> > attached patch. It ensures that the parameters are found regardless of
> > whether the function name was included in the signature label or not.
> >
> > Regards,
> > Michal
> >
> > From e9cebcd9aed7d92bd2ea0b692165e5b55adf8084 Mon Sep 17 00:00:00 2001
> > From: Michal Dubiel <majkijin <at> gmail.com>
> > Date: Sun, 23 Oct 2022 19:54:31 +0200
> > Subject: [PATCH] eglot: Support signature labels without a function name
> >
> > * lisp/progmodes/eglot.el (eglot--sig-info): Support signature labels
> > without a function name.
> > ---
> >  lisp/progmodes/eglot.el | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> > index 71001ba680..f5a00b03c7 100644
> > --- a/lisp/progmodes/eglot.el
> > +++ b/lisp/progmodes/eglot.el
> > @@ -2909,7 +2909,7 @@ for which LSP on-type-formatting should be
> requested."
> >         (let ((active-param (or activeParameter sig-help-active-param))
> >               params-start params-end)
> >           ;; Ad-hoc attempt to parse label as <name>(<params>)
> > -         (when (looking-at "\\([^(]+\\)(\\([^)]+\\))")
> > +         (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))
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58777; Package emacs. (Sat, 12 Nov 2022 21:35:01 GMT) Full text and rfc822 format available.

Message #16 received at 58777 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: João Távora <joaotavora <at> gmail.com>
Cc: 58777 <at> debbugs.gnu.org, Michał Dubiel <majkijin <at> gmail.com>
Subject: Re: bug#58777: eldoc + eglot does not highlight the function
 parameter the cursor is at
Date: Sat, 12 Nov 2022 13:34:38 -0800
close 58777 29.1
thanks

João Távora <joaotavora <at> gmail.com> writes:

> I'd say this looks good. It would be even better with a couple of automated
> tests, but then again eglot-tests.el hasn't migrated to Emacs yet.

OK, pushed to master (commit 9d334f558a).




bug marked as fixed in version 29.1, send any further explanations to 58777 <at> debbugs.gnu.org and Michał Dubiel <majkijin <at> gmail.com> Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 12 Nov 2022 21:35:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 11 Dec 2022 12:24:13 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 187 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.