[ty] Improve import detection for completions and support from ...<CURSOR> completions by BurntSushi · Pull Request #21547 · astral-sh/ruff (original) (raw)
This is a small refactor that helps centralize the logic for how we gather, convert and possibly filter completions.
Some of this logic was spread out before, which motivated this refactor. Moreover, as part of other refactoring, I found myself chaffing against the lack of this abstraction.
This commit essentially does away of all our old heuristic and piecemeal
code for detecting different kinds of import statements. Instead, we
offer one single state machine that does everything. This on its own
fixes a few bugs. For example, import collections.abc, unico<CURSOR>
would previously offer global scope completions instead of module
completions.
For the most part though, this commit is a refactoring that preserves parity. In the next commit, we'll add support for completions on relative imports.
We already supported from .. import <CURSOR>, but we didn't support
from ..<CURSOR>. This adds support for that.
This was referenced
Nov 21, 2025
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
[ Show hidden characters]({{ revealButtonHref }})