unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes
@ 2023-02-19 22:08 Eric Abrahamsen
  2023-02-19 22:42 ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Abrahamsen @ 2023-02-19 22:08 UTC (permalink / raw)
  To: 61640

[-- Attachment #1: Type: text/plain, Size: 523 bytes --]


In a form such as this:

(defclass ebdb-field-id (ebdb-field-labeled ebdb-field-obfuscated ebdb-field-user)
  ((label-list :initform 'ebdb-id-label-list)
   ...
   ))

All the symbols in

(ebdb-field-labeled ebdb-field-obfuscated ebdb-field-user)

should be recognized by `elisp--xref-infer-namespace' as 'function.
Right now, this is treated like a function call (ie like '(function
variable variable)).

I can't promise that the attached patch is exactly the right thing, but
it ought to be pretty close.

Thanks,
Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: elispxrefdefclass.diff --]
[-- Type: text/x-patch, Size: 585 bytes --]

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 1c339d08148..f7cd9e90926 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -943,6 +943,10 @@ elisp--xref-infer-namespace
                                  cl-defmethod cl-defgeneric)))
             ;; (defun FUNC (... IDENT
             'variable)
+           ((and (eql j 2)
+                 (eq j-head 'defclass))
+            ;; (defclass CLASS (... IDENT
+            'function)
            ((eq j-head 'cond)
             ;; (cond ... (... IDENT
             'variable)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes
  2023-02-19 22:08 bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes Eric Abrahamsen
@ 2023-02-19 22:42 ` Dmitry Gutov
  2023-02-19 23:45   ` Eric Abrahamsen
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2023-02-19 22:42 UTC (permalink / raw)
  To: Eric Abrahamsen, 61640

Hi!

On 20/02/2023 00:08, Eric Abrahamsen wrote:
> In a form such as this:
> 
> (defclass ebdb-field-id (ebdb-field-labeled ebdb-field-obfuscated ebdb-field-user)
>    ((label-list :initform 'ebdb-id-label-list)
>     ...
>     ))
> 
> All the symbols in
> 
> (ebdb-field-labeled ebdb-field-obfuscated ebdb-field-user)
> 
> should be recognized by `elisp--xref-infer-namespace' as 'function.
> Right now, this is treated like a function call (ie like '(function
> variable variable)).
> 
> I can't promise that the attached patch is exactly the right thing, but
> it ought to be pretty close.

Thanks for the patch. Could you try including a corresponding test?

There are examples in test/lisp/progmodes/elisp-mode-tests.el, see the 
ones using the helper xref-elisp-deftest, starting with line 395.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes
  2023-02-19 22:42 ` Dmitry Gutov
@ 2023-02-19 23:45   ` Eric Abrahamsen
  2023-02-20  1:05     ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Abrahamsen @ 2023-02-19 23:45 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 61640

Dmitry Gutov <dgutov@yandex.ru> writes:

> Hi!
>
> On 20/02/2023 00:08, Eric Abrahamsen wrote:
>> In a form such as this:
>> (defclass ebdb-field-id (ebdb-field-labeled ebdb-field-obfuscated
>> ebdb-field-user)
>>    ((label-list :initform 'ebdb-id-label-list)
>>     ...
>>     ))
>> All the symbols in
>> (ebdb-field-labeled ebdb-field-obfuscated ebdb-field-user)
>> should be recognized by `elisp--xref-infer-namespace' as 'function.
>> Right now, this is treated like a function call (ie like '(function
>> variable variable)).
>> I can't promise that the attached patch is exactly the right thing,
>> but
>> it ought to be pretty close.
>
> Thanks for the patch. Could you try including a corresponding test?
>
> There are examples in test/lisp/progmodes/elisp-mode-tests.el, see the
> ones using the helper xref-elisp-deftest, starting with line 395.

There's a lot going on in there!

The tests using xref-elisp-deftest look like they're mostly aimed at
correctly finding definitions, which isn't the problem here: the
defclass is always found correctly *if* xref infers the namespace as
'function.

Shouldn't this instead be an addition to `elisp-mode-infer-namespace',
like with p8 below?

  (elisp-mode-test--with-buffer
      (concat "(list {p1}alpha {p2}beta)\n"
              "(progn {p3}gamma {p4}delta)\n"
              "(lambda ({p5}epsilon {p6}zeta) {p7}eta)\n"
              "(defclass child-class (parent-1 {p8}parent-2)\n")
    (should (equal (elisp--xref-infer-namespace p1) 'variable))
    (should (equal (elisp--xref-infer-namespace p2) 'variable))
    (should (equal (elisp--xref-infer-namespace p3) 'variable))
    (should (equal (elisp--xref-infer-namespace p4) 'variable))
    (should (equal (elisp--xref-infer-namespace p5) 'variable))
    (should (equal (elisp--xref-infer-namespace p6) 'variable))
    (should (equal (elisp--xref-infer-namespace p7) 'variable))
    (should (equal (elisp--xref-infer-namespace p8) 'function)))

Obviously just guessing here...





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes
  2023-02-19 23:45   ` Eric Abrahamsen
@ 2023-02-20  1:05     ` Dmitry Gutov
  2023-02-20  1:43       ` Eric Abrahamsen
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2023-02-20  1:05 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 61640-done

Version: 30.1

On 20/02/2023 01:45, Eric Abrahamsen wrote:
> Shouldn't this instead be an addition to `elisp-mode-infer-namespace',
> like with p8 below?
> 
>    (elisp-mode-test--with-buffer
>        (concat "(list {p1}alpha {p2}beta)\n"
>                "(progn {p3}gamma {p4}delta)\n"
>                "(lambda ({p5}epsilon {p6}zeta) {p7}eta)\n"
>                "(defclass child-class (parent-1 {p8}parent-2)\n")
>      (should (equal (elisp--xref-infer-namespace p1) 'variable))
>      (should (equal (elisp--xref-infer-namespace p2) 'variable))
>      (should (equal (elisp--xref-infer-namespace p3) 'variable))
>      (should (equal (elisp--xref-infer-namespace p4) 'variable))
>      (should (equal (elisp--xref-infer-namespace p5) 'variable))
>      (should (equal (elisp--xref-infer-namespace p6) 'variable))
>      (should (equal (elisp--xref-infer-namespace p7) 'variable))
>      (should (equal (elisp--xref-infer-namespace p8) 'function)))
> 
> Obviously just guessing here...

It seems you're right, thanks.

I've put the test case separately and pushed the combined change to 
master, commit cac13e36054.

That fixes the bug in my testing, but please do tell if something else 
comes up.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes
  2023-02-20  1:05     ` Dmitry Gutov
@ 2023-02-20  1:43       ` Eric Abrahamsen
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Abrahamsen @ 2023-02-20  1:43 UTC (permalink / raw)
  To: 61640; +Cc: dgutov

Dmitry Gutov <dgutov@yandex.ru> writes:

> Version: 30.1
>
> On 20/02/2023 01:45, Eric Abrahamsen wrote:
>> Shouldn't this instead be an addition to `elisp-mode-infer-namespace',
>> like with p8 below?
>>    (elisp-mode-test--with-buffer
>>        (concat "(list {p1}alpha {p2}beta)\n"
>>                "(progn {p3}gamma {p4}delta)\n"
>>                "(lambda ({p5}epsilon {p6}zeta) {p7}eta)\n"
>>                "(defclass child-class (parent-1 {p8}parent-2)\n")
>>      (should (equal (elisp--xref-infer-namespace p1) 'variable))
>>      (should (equal (elisp--xref-infer-namespace p2) 'variable))
>>      (should (equal (elisp--xref-infer-namespace p3) 'variable))
>>      (should (equal (elisp--xref-infer-namespace p4) 'variable))
>>      (should (equal (elisp--xref-infer-namespace p5) 'variable))
>>      (should (equal (elisp--xref-infer-namespace p6) 'variable))
>>      (should (equal (elisp--xref-infer-namespace p7) 'variable))
>>      (should (equal (elisp--xref-infer-namespace p8) 'function)))
>> Obviously just guessing here...
>
> It seems you're right, thanks.
>
> I've put the test case separately and pushed the combined change to
> master, commit cac13e36054.
>
> That fixes the bug in my testing, but please do tell if something else
> comes up.

Thanks!





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-02-20  1:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-19 22:08 bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes Eric Abrahamsen
2023-02-19 22:42 ` Dmitry Gutov
2023-02-19 23:45   ` Eric Abrahamsen
2023-02-20  1:05     ` Dmitry Gutov
2023-02-20  1:43       ` Eric Abrahamsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).