You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
answer for the imports a renamed module leaves behind
renaming `util.by` to `helpers.by` renames the module `alpha.util`, and every
`from alpha.util import thing` in the project is now naming a module that is
not there. an editor cannot find those on its own: it would have to resolve
every import against the same search paths the checker uses. so the protocol
has it ask first, and the server had no answer — `workspace/willRenameFiles`
was never advertised, and `rename` is a symbol rename that refuses an import's
module component outright.
the request is now handled. it arrives before the file moves, which is what
makes it answerable at all: the old path still holds the file, so the module it
is today resolves, while the new path is a path to read a name out of. that is
the one thing `file_to_module` cannot do — it resolves the name it derives back
to a file and checks the answer is the same file, which nothing at the new path
can satisfy — so `path_to_module_name` answers the narrower, purely
path-shaped question, for directories as well as files.
what is rewritten is the module paths in import statements, at any depth in the
file (an `if TYPE_CHECKING:` import is exactly the one written carefully), and
the *uses* of a name an import binds when that name changes: `import alpha.util`
binds `alpha`, so `alpha.util.thing()` moves too. those uses are found by their
text and confirmed by their type — an expression is only rewritten when the
checker says it is the module that moved, so a local called `util` in a file
that also imports a module of that name is left alone.
a relative import inside a package that is being renamed as a whole comes out
unchanged, which is the truth: the dots go on meaning the file's own package,
and that package is moving with it.
two things are deliberately not rewritten, and both are reported rather than
half-done: a module named as a string, and an import that would have to change
shape — moving `alpha.util` to `beta.util` leaves `from alpha import util`
needing a different statement, not a different word.
folders are asked about as well as files, because renaming a directory renames
every module under it and the client sends only the directory. a folder pattern
cannot be narrowed the way the file one is — a directory has no extension, and
whether it is a package is a question about the search paths — so every folder
rename costs one request that usually answers with no edits.
name a path by the deepest search path that contains it
caught by driving the server against a real uv workspace. the member's
package sits inside two search paths at once — the project root, and the
editable entry uv writes for the member itself, pointing at its own `src`
— and taking the first one consulted named `packages/alpha/src/alpha` as
`packages.alpha.src.alpha`. that is not a module anything imports and not
the name any `import alpha` resolves to, so a rename of it found nothing to
rewrite and answered no edits at all.
the deepest search path is the one whose name resolves back to the path,
which is what `file_to_module` verifies for a file that exists. with the
rule fixed, the same workspace answers with all three edits: the `from
alpha import thing`, the `import alpha`, and the `alpha.thing()` in the
body.
0 commit comments