python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.76k stars 186 forks source link

`includeDeclaration` is no longer respected in `textDocument/references` #439

Closed krassowski closed 10 months ago

krassowski commented 10 months ago

From manual debugging it seems that includeDeclaration gets handled correctly here:

https://github.com/python-lsp/python-lsp-server/blob/6c168d0f8ee2e59ec8438373bc2c1b33cb74cdfa/pylsp/python_lsp.py#L753-L757

and here:

https://github.com/python-lsp/python-lsp-server/blob/6c168d0f8ee2e59ec8438373bc2c1b33cb74cdfa/pylsp/python_lsp.py#L516-L524

but when it is passed to pylsp_references here:

https://github.com/python-lsp/python-lsp-server/blob/6c168d0f8ee2e59ec8438373bc2c1b33cb74cdfa/pylsp/plugins/references.py#L10-L17

the default value is always used. It looks like the pluggy weirdness with it failing to pass arguments correctly. Reproduced in 1.8.0 with pluggy 1.2.0 and 1.3.0 on Python 3.11.

Removing the default value (exclude_declaration=Falseexclude_declaration) fixes the issue.

krassowski commented 10 months ago

Indeed this is what pluggy does:

import pluggy

hookspec = pluggy.HookspecMarker("test")
hookimpl = pluggy.HookimplMarker("test")

class MySpec:

    @hookspec
    def myhook(self, arg1, arg2):
        pass

class Plugin_1:

    @hookimpl
    def myhook(self, arg1, arg2=0):
        return arg1 + arg2

pm = pluggy.PluginManager("test")
pm.add_hookspecs(MySpec)
pm.register(Plugin_1())
results = pm.hook.myhook(arg1=1, arg2=2)
print(results)  # prints[1]

Compare with:

import pluggy

hookspec = pluggy.HookspecMarker("test")
hookimpl = pluggy.HookimplMarker("test")

class MySpec:

    @hookspec
    def myhook(self, arg1, arg2):
        pass

class Plugin_1:

    @hookimpl
    def myhook(self, arg1, arg2):
        return arg1 + arg2

pm = pluggy.PluginManager("test")
pm.add_hookspecs(MySpec)
pm.register(Plugin_1())
results = pm.hook.myhook(arg1=1, arg2=2)
print(results)  # prints[3]
krassowski commented 10 months ago

I am unable to find a version of pluggy which worked differently (checked down to 0.x series). I am also unable to narrow down python-lsp-server version (checked down to 1.4.x) which worked correctly. I also see this behaviour on Python 3.8.