ruff
dd5afa8e - [ty] Skip unrelated definitions and imports in semantic token range requests (#30665)

Commit
6 hours ago
[ty] Skip unrelated definitions and imports in semantic token range requests (#30665) ## Summary When an editor asks ty to highlight part of a file, we can still infer types in unrelated functions and classes and resolve `from` imports outside that range. The semantic token visitor handles these statements directly, bypassing the range check in `walk_stmt`. We now apply the same check before visiting those statements. We still clear the docstring flag first, and we don't skip assignments: a string immediately after an assignment can document it even if the assignment is off screen. On [CPython’s `argparse.py`](https://github.com/python/cpython/blob/v3.12.13/Lib/argparse.py#L1001-L1180), the savings depended on whether the client had already requested diagnostics. When it only asked to highlight lines 1001–1060, the server used 61.00–61.01% fewer instructions. When it first requested diagnostics and then highlighted three consecutive 60-line ranges starting at line 1001, it used 4.71–4.72% fewer. Checking the file can still require inference that highlighting alone now skips.
Author
Parents
Loading