Fix completions for import aliases#4111
Open
roian6 wants to merge 1 commit into
Open
Conversation
Import aliases create local binding names, so treating them as import targets produces irrelevant module or export suggestions. Detect alias ranges for both import forms before normal completion dispatch. Lightweight regression tests cover direct and from-import aliases.
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
Fixes #4107
Import alias names are local binding targets, but completion treated them as import paths. This produced module suggestions for
import pandas as pdand package-export suggestions forfrom package import name as alias.Detect when the cursor is on
Alias.asnamefor either import form and return no completions before normal import completion dispatch. Normal module and imported-name completions remain unchanged outside alias targets. Lightweight regression tests cover both forms.AI agent disclosure: This PR was prepared by Hermes Agent, an AI coding agent, under the contributor's direction. The agent traced the relevant source paths, added and exercised regression tests, ran the repository validation commands listed below, and performed an independent automated code review. The contributor is aware of the AI-agent involvement.
Test Plan
cargo test -p pyrefly import_alias_has_no_completions -- --nocapture— 2 passed, 0 failedcargo test -p pyrefly 'test::lsp::completion::'— 100 passed, 0 failedpython3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema— formatting and linting passedcargo fmt --all -- --checkgit diff --check