-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feature request: List all applicable From/Into impls #13394
Comments
Regarding David Barsky's second point:
That we can't just do, this could get quickly out of control for blanket implementations referring many traits and it would certainly confuse people at the same time wondering why its showing unrelated references. Nevertheless I agree that there is a feature "hole" here, goto def for into is quite useless (blanket impls in general make goto def and the like not as useful). I believe IntelliJ (I might be misremembering) goes to the blanket impls first, but if you re-invoke the goto thing immediately it will go the actual point of interest. We might want to look into something similar for that. Regarding the hover ideas (that is David Barsky's first point and ljw1004's comment): Proposal 2 is a bit a more tricky to think about, I don't think we want to necessarily overload a hover with information, that is we don't want to pack it so full that you have to start searching for the actual "useful" information (useful being whatever the person might be interested in). This might not be a problem though, we'd see if it works or not if we have something working for that, worse case we could make it configurable. Proposal 3 is tough, it certainly sounds lovely to have, but I am uncertain if we can currently implement that. Overall I like the ideas you have outlined here and I think they are certainly something we should try to pursue
This confuses me though, why do you have to scan through things? Why does goto def not work for you here? |
I think a 'general' solution for this would be 'monomorphised go to definition' #8373, which would basically mean that if you go to definition on |
Another nice-to-have thing I've wanted would be a kind of 'trait query browser' where you can ask 'why does type X implement trait Y' and it shows you a UI that says 'because of impl Z' and lets you drill down further into the where clauses etc., basically visualizing the Chalk recursive solver's solution tree. That's also quite UI-heavy though. |
Here is my proposal for go-to-def.
Proposal 4. When a method call involves constraint satisfaction, then the syntax that the user wrote which looks like it's using a single definition (that of the receiver method), is actually also using a second definition -- that which justifies how the constraints are satisfied. When we cmd-click "go-to-def" on the method call we should be offered all the definitions which went into it.
Here's a slightly different example from Hack where GoToDef offers multiple results. Imagine you write
I think that Proposal4 will be bad if it shows multiple results but users 99% of the time only want to go to one of the results. My idea is to maybe limit it at first, using it only when the target of the call is from a white-list of standard library calls. I think the initial content of this white-list might be solely
|
@Veykril I'm sure @davidbarsky could tell you more about our company's setup, but our rust-analyzer works fine at providing language services for the project you're working on where it's already warm. But then you ask it to warm itself up and resolve everything it needs to understand a file within stdlib or a third-party crate then it's often either slower at the warmup than I am myself at scrolling through the first 30 lines of the file, or it fails entirely. In C# they never face this because types imported from stdlib or third-party packages are always exposed to the user as as "signature-only" and the language server is never asked to spin itself up to process/understand/build a third-party crate. Indeed, for C#, my developer machine might not even have installed the tools needed to compile that third-party crate's source code. I'm not disagreeing with Rust! I think it's wonderful that I can cmd+click into a third-party crate to see how it's implemented. I just think that if my workflow depends upon rust-analyzer being able to work correctly for all stdlib and third-party crate source code then it feels like a higher bar being placed for rust-analyzer than, say, for C#. The proposals in this issue would reduce the bar. |
fwiw, most of the limitations you might experience today are not rust's or rust-analyzer's fault—they're mine for being too lazy/short-on-time to implement support for the files correctly. looking back, most/all of these are pretty easy to fix and don't require help from the very nice rust-analyzer folks 😄 |
I like this approach quite a bit! Maybe as an initial pass, this component can reuse the existing "view status/HIR" pane as the UI? I'll take a look at Chalk and the existing integration with RA. |
The biggest problem with that one is that it requires either some way of tracing Chalk's solution, or basically replicating all of Chalk's logic. |
Ah, gotcha! I assumed there was a handy "get me all applicable impls for type |
Oh, reading over the Chalk book, I can see how some reflexive implementations could lead to an unbounded search: https://rust-lang.github.io/chalk/book/canonical_queries.html#the-traditional-interactive-prolog-query. That... can throw a wrench into a naive implementation 😅 |
I don't quite see how. For r-a to calculate the hover, we need to do the same work as we do for goto-def, so in either case r-a will need to warm up here, so whatever you describe here will not be able to help you with that. |
Here's what I'm thinking. I'm in file A.RS and rust-analyzer is warm for this file -- it has resolved all the crates I depend upon and knows the signatures in them. This is how it knows that somecrate::foo has return type If I cmd+click on foo and it takes me to third-party/crates/somecrate/lib.rs to the line of code which says In C# and Hack, the user rarely needs to have the language-service warm for that third-party file since they got all they need from hover in their own (warm) source file. That laziness allows for faster startup times. |
@ljw1004 Ah, there's a misunderstanding here. if you're able to a separate crate/file from an indexed file, that file you've reached is also indexed. Another rust-analyzer instance does not need to start up again; the indexing cost is entirely up-front. |
As a maintainer of several Rust code projects I didn't write, any |
A coworker asked this question, and I was little surprised to not have an answer. I'll quote what he said:
The coworker thought (and I personally agree) that it'd be a neat feature for Rust Analyzer to surface these implementations these implementations at the callsite. I'd be happy to implement this feature, as I'm assuming that Chalk has most of this information already. However, I'm struggling to think of a general, principled way of surfacing this information, but I suppose that having rust-analyzer surface just the
From
/Into
/TryFrom
/TryInto
impls for a given type is probably reasonable.The text was updated successfully, but these errors were encountered: