[ty] Improve completion rankings for raise-from/except contexts#22775
Conversation
Typing conformance resultsNo changes detected ✅ |
|
BurntSushi
left a comment
There was a problem hiding this comment.
LGTM!
This does regress the completions when no character is typed after the raise keyword raise but I think that's a reasonable trade-off to greatly simplify the implementation with AST-traversal rather than extending the token-based approach.
Can you add a test with a comment about this? (Pretty much just saying what you've said here.)
| base_exception_ty, | ||
| Type::homogeneous_tuple(db, base_exception_ty), | ||
| ], | ||
| ); |
There was a problem hiding this comment.
I kind of wonder whether it'd made sense to only constructs these if we know we'll need them. Since I'd expect the common case is that we won't. But I think that's easy enough to do if this shows up on a profile.
There was a problem hiding this comment.
Yep I believe so, it would be quite cool to have some performance tests for completions running in CI (or at least an easy local benchmark) to have a baseline to compare performance against.
There was a problem hiding this comment.
There is now an ad hoc CLI for benchmarking completions that I just added. The README should say how to use it. :-) https://github.com/astral-sh/ruff/tree/main/crates/ty_completion_bench
I already did a round of plucking low hanging fruit here: #22630
From looking at profiles, my sense is that this sort of work done here (even when it isn't necessary) is marginal.
And yeah, ideally we'd have some benchmarks in CI: astral-sh/ty#2570
There was a problem hiding this comment.
Oh look at that, nice!
Completions of the correct types are now favoured in `except <CURSOR>` and `raise <EXPR> from <CURSOR>` contexts
c6fcabb to
dacf708
Compare
BurntSushi
left a comment
There was a problem hiding this comment.
Thanks!
(I kinda suspect we'll end up wanting the token matching to recover raise <CURSOR> completions, but we can do that in response to user feedback.)
Completions of the correct types are now favoured in
except <CURSOR>andraise <EXPR> from <CURSOR>contextsFixes astral-sh/ty#1779
This does regress the completions when no character is typed after the raise keyword
raise <CURSOR>but I think that's a reasonable trade-off to greatly simplify the implementation with AST-traversal rather than extending the token-based approach.Test Plan
New completion evaluation tasks with correct rankings (that produces incorrect rankings on main)