-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Improve lsp handling of hover/goto on imports #21572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
| fn definitions_for_expression<'db>( | ||
| db: &'db dyn crate::Db, | ||
| file: ruff_db::files::File, | ||
| model: &SemanticModel<'db>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of funny that SemanticModel survived to this day. I introduced it in one of the very earliest prototypes of a type aware linter back when ty was barely able to infer ints. I'm not sure it's the right API but good to see that it's not complete rubbish and is useful in cases like this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah between this PR and the string annotations one I am Fully embracing it as an actually useful abstraction!
| let covering_node = covering_node(parsed.syntax().into(), token.range()) | ||
| .find_first(|node| node.is_identifier() || node.is_expression()) | ||
| .find_first(|node| { | ||
| node.is_identifier() || node.is_expression() || node.is_stmt_import_from() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it makes sense to change this to node.is_stmt. I don't think we ever want to go beyond the closest statement (my, now proven incorrect, assumption was that expression is a sufficient boundary but turns out it isn't)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'll think about it
* origin/main: (27 commits) [ty] Add hint about resolved Python version when a user attempts to import a member added on a newer version (#21615) Use release commit for actions/checkout (#21610) [ty] Add failing mdtest for known `Protocol` panic (#21594) [`parser`] Fix panic when parsing IPython escape command expressions (#21480) Fix cargo shear in CI (#21609) Update actions/checkout digest to c2d88d3 (#21601) Update dependency ruff to v0.14.6 (#21603) Update astral-sh/setup-uv action to v7.1.4 (#21602) Update Rust crate clap to v4.5.53 (#21604) Update taiki-e/install-action action to v2.62.56 (#21608) Update Rust crate hashbrown to v0.16.1 (#21605) Update Rust crate indexmap to v2.12.1 (#21606) Update Rust crate syn to v2.0.111 (#21607) [ty] Check method definitions on subclasses for Liskov violations (#21436) [ty] Fix panic for unclosed string literal in type annotation position (#21592) [ty] Fix rendering of unused suppression diagnostic (#21580) [ty] Improve lsp handling of hover/goto on imports (#21572) [ty] Improve diagnostics when a submodule is not available as an attribute on a module-literal type (#21561) [ty] Improve concise diagnostics for invalid exceptions when a user catches a tuple of objects (#21578) [ty] upgrade salsa (#21575) ...
.xproperly at all in hover/gotoIt turns out all of our import handling completely ignored the
level(number of relative.'s) in afrom ..x.y import zstatement. It was nice seeing how much my understanding oftyhas improved -- previously this would have all been opaque to me but now it was just, completely glaring and blatant.Fixing this required refactoring all the import code to take the importing file into consideration. I ended up refactoring a bunch of code to pass around/require
SemanticModelmore, as it's the natural API for resolving this kind of import (it actually had an API for this that was just... dead code, whoops!).