Skip to content

LSP WillRenameFiles implementation doesn't adjust relative imports #4055

Description

@smheidrich

Describe the Bug

Pyrefly's LSP server implementation only adjusts absolute imports when it gets a renamed-file notification (WillRenameFiles / DidRenameFiles1) from the client, but not relative ones.

To reproduce:

  1. Create a Python package pkg/__init__.py with modules pkg/a.py and pkg/b.py.
  2. Define a function in a.py:
    def foo(): ...
  3. Import this function from b.py:
    from .a import foo
    foo()
  4. In your editor with Pyrefly attached as an LSP server, rename a.py to a2.py and notice that the import in b.py remains unchanged.

Whereas if you instead have from pkg.a import foo in b.py, the import is updated to say pkg.a2 as it should.

1 Although I think Pyrefly only implements the former

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Note: I tested this in Neovim with neo-tree and nvim-lsp-file-operations, but as it worked fine for absolute imports, it wouldn't make sense for the editor setup to be at fault.

Metadata

Metadata

Assignees

Labels

language-serverIssues specific to our IDE integration rather than type checking

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions