Skip to content

Fix first auto-import completion for unloaded modules#4159

Draft
paranoa233 wants to merge 1 commit into
facebook:mainfrom
paranoa233:agent/fix-first-auto-import-completion
Draft

Fix first auto-import completion for unloaded modules#4159
paranoa233 wants to merge 1 commit into
facebook:mainfrom
paranoa233:agent/fix-first-auto-import-completion

Conversation

@paranoa233

Copy link
Copy Markdown
Contributor

Summary

  • include modules discoverable from the active file's import paths in fuzzy module auto-import completion
  • deduplicate discoverable modules with modules already loaded in the transaction
  • add a regression test for completing json before the module has been imported or loaded

Root 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 -- --check
  • python 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

completions auto-import doesn't work on first try after reload

1 participant