ruff
a77db3da - [ty] Add completions for `from module import <CURSOR>` (#18830)

Commit
218 days ago
[ty] Add completions for `from module import <CURSOR>` (#18830) There were two main challenges in this PR. The first was mostly just figuring out how to get the symbols corresponding to `module`. It turns out that we do this in a couple of places in ty already, but through different means. In one approach, we use [`exported_names`]. In another approach, we get a `Type` corresponding to the module. We take the latter approach here, which is consistent with how we do completions elsewhere. (I looked into factoring this logic out into its own function, but it ended up being pretty constrained. e.g., There's only one other place where we want to go from `ast::StmtImportFrom` to a module `Type`, and that code also wants the module name.) The second challenge was recognizing the `from module import <CURSOR>` pattern in the code. I initially started with some fixed token patterns to get a proof of concept working. But I ended up switching to mini state machine over tokens. I looked at the parser for `StmtImportFrom` to determine what kinds of tokens we can expect. [`exported_names`]: https://github.com/astral-sh/ruff/blob/23a3b6ef2337c8a2c1496ebf68d12582f0b0706d/crates/ty_python_semantic/src/semantic_index/re_exports.rs#L47
Author
Parents
Loading