Fix first auto-import completion for unloaded modules#4159
Draft
paranoa233 wants to merge 1 commit into
Draft
Conversation
Module completion only searched modules already loaded into the transaction, so discoverable stdlib and site-package modules were absent until an explicit import loaded them. Merge import-prefix candidates from the active file's configuration into the fuzzy module search and deduplicate them. Add a regression test for completing json before it has been imported.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
jsonbefore the module has been imported or loadedRoot cause
Module auto-import completion only searched
Transaction::modules(), which contains modules already loaded into state. A standard-library or site-package module therefore appeared only after an explicit import caused it to be loaded. The existing import-prefix resolver already discovers matching modules from the active config's search paths and typeshed, so the fix merges those candidates into the fuzzy search.Testing
cargo test -p pyrefly autoimport --lib(15 passed)cargo fmt -p pyrefly -- --checkpython test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema(run with Python 3.11 and the GNU Rust toolchain on Windows)Fixes #4108
This contribution was prepared by an AI coding agent (Codex) working through the contributor's account.