pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

Go to references and go to definition breaks if line numbers change due to empty lines

Open aduernberger opened this issue 1 month ago • 1 comments

Describe the Bug

lib.py

class Tools:
    @staticmethod
    def helper():
        return 1


def function():
    return 1

user.py

from lib import Tools, function

Tools.helper()
function()
Tools.helper()

Goto reference on helper() (user.py) -> shows references Add empty line after class Tools. Goto reference on helper() (user.py) -> jumps directly to the definition, does not find the second Tool.helper() anymore. Goto definition on helper() (user.py) -> jumps to the old line number, holds true even if more space is added.

For the go to definition I can also reproduce it by:

  • adding an empty line inside a method or a docstring
  • adding a empty line inside a class
  • Adding a docstring to the class or method.

Docstrings were always added as follows, so it also points to an issue with newlines?

"""
test
"""

References and definition on function() stay working through all the changes. PS: just noticed Call hierarchy is broken in the same way as references.

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

VSCode (Pyrefly 1.3.2, 1.4), but Claude also verified that it works with a standalone pyrefly it started itself. Both files are open in vscode. Files are saved after every change.

aduernberger avatar Nov 02 '26 10:11 aduernberger

Just a note to anyone considering picking this up: the obvious way to handle it is to disable the logic in Pyrefly that makes blank lines not trigger full rechecks. That would be quite bad for incremental performance though.

So there's going to be some nontrivial design questions in how to best do this.

cc @kinto0, @samwgoldman who have thought the most about incremental + lsp

stroxler avatar Nov 02 '26 15:11 stroxler