Subject: bug#61640: 30.0.50; Help Elisp xref recognize defclass parent classes

From: Eric Abrahamsen <[email-masked]>
Date: Sun, 19 Feb 2023 15:45:37 -0800

Dmitry Gutov <[email-masked]> 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...