Conversation
|
|
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
| binding.matching_overloads().map(|(_, overload)| { | ||
| overload | ||
| .signature | ||
| .display_with(db, DisplaySettings::default().multiline()) | ||
| .to_string() | ||
| }) |
There was a problem hiding this comment.
I spent an unconscionable amount of time trying to have this return a Type or something more useful than a String but the types on Binding are haunted by the overloads when you try to render them (meaning printing them still returns the full overload set!).
Stringifying the raw Signature is the only thing that seems to be safe.
There was a problem hiding this comment.
(An early version returned a full CallSignatureDetails but this usecase has no use of that so I dropped it as a waste of effort. Also this version that just returns a String is easier to iterate on (I kept trying to Not have a String and had to refactor like 4 calls and 2 types over and over as I experimented between Type vs Vec<Type> vs CallSignatureDetails vs...))
|
|
||
| pub struct DisplayHover<'a> { | ||
| db: &'a dyn Db, | ||
| hover: &'a Hover<'a>, | ||
| pub struct DisplayHover<'db, 'a> { | ||
| db: &'db dyn Db, | ||
| hover: &'a Hover<'db>, | ||
| kind: MarkupKind, | ||
| } |
There was a problem hiding this comment.
This is debris from versions where this was being asked to store CallSignatureDetails, which is actually invariant over 'db. Leaving it like this just simplifies any potential future work.
MichaReiser
left a comment
There was a problem hiding this comment.
I'll do a full review on Monday but I've a question why we limit overload matching to hover only
| // TODO: Render the symbol's signature instead of just its type. | ||
| let mut contents = Vec::new(); | ||
| if let Some(ty) = ty { | ||
| if let Some(signature) = goto_target.call_type_simplified_by_overloads(&model) { |
There was a problem hiding this comment.
Is there a reason we only apply overload simplification for hover mode? For example, TypeScript jumps to the matching overload if you use "go to definition," which matches my expectation. https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABFApgZygCgIYC5FggC2ARigE4CU+hpFA3AFCiSwLLpZ4HFnkA0iEvgzkYYAObVEo8RKYto8JKgw4avCoJIB+EVDGTp2MAE9EAb0aMAvtcaqsARgAMggESP3le0A
I'm surprised that Pylance doesn't seem to do that
There was a problem hiding this comment.
Hmm strictly speaking I don't think goto-definition should jump to an overload unless we can't find the actual implementation (in which case it's actually goto-declaration). goto-declaration should ideally jump to the overload though.
| let func_type = call_expr.func.inferred_type(model); | ||
|
|
||
| // Use into_callable to handle all the complex type conversions | ||
| let callable_type = func_type.try_upcast_to_callable(db)?; |
There was a problem hiding this comment.
Is my understanding correct that this adds another "todo" call-site to astral-sh/ty#1086?
There was a problem hiding this comment.
I'm not sure if we'll be able to do astral-sh/ty#1086; commented on that issue.
| .flat_map(|binding| { | ||
| binding.matching_overloads().map(|(_, overload)| { | ||
| overload | ||
| .signature | ||
| .display_with(db, DisplaySettings::default().multiline()) | ||
| .to_string() | ||
| }) | ||
| }) |
There was a problem hiding this comment.
I think I remember now facing a similar problem regarding using the signature_type on Binding struct that we saw during our call last week. For context, the signature_type would represent the FunctionLiteral which means the display would contain all the overloads and this is the main reason we need to use the display of Signature to display the matching overload which leads to requiring #21438.
I faced this issue while implementing #18452 and the way I resolved it is by capturing the required information (FunctionType, BoundMethodType, etc. and the matching overload index) in MatchingOverloadLiteral and implementing a .get method to return the matching OverloadLiteral.
I think we could possibly use a similar approach to get the actual OverloadLiteral that needs to be displayed as it does implement the Display trait. You might find it useful to go through this part of the code:
ruff/crates/ty_python_semantic/src/types/call/bind.rs
Lines 2125 to 2162 in dcc451d
Another approach could be to expand the DisplaySettings to include the matching_overload_index: MatchingOverloadIndex which can then be used directly to filter the overloads at the display level. The None variant would display all the overloads.
|
@Gankra what's the status of this PR? |
|
I think this PR could be landed as-is as an incremental strict improvement. I've been locally experimenting with alternative approaches that would e.g. empower goto-declaration as well, but I keep running into issues around the fact that randomly places in the code (like type printing) don't want to talk about A Specific Overload (connected to the fact that definitions-hanging-off-types is a fundamental hack). |
|
I'm fine with handling go-to separately. But we might want to address @dhruvmanila's feedback before landing? |
|
Yeah dhruv's suggestions are what I was experimenting with locally. Hover doesn't really benefit from it (it really just needs a String, and I'm computing that String fine), but goto-decl would benefit. |
MichaReiser
left a comment
There was a problem hiding this comment.
Alright. I'm fine with this, given that you're already working on the follow ups. If you don't end up implementing all of them, would you mind opening follow up issues in that case.
|
Or well, I suppose dhruv's suggestions would ideally obsolete the more hacky stuff in #21438 But yeah it's all kinda the same work. |
This is a very conservative minimal implementation of applying overloads to resolve a callable-type-being-called down to a single function signature on hover. If we ever encounter a situation where the answer doesn't simplify down to a single function call, we bail out to preserve prettier printing of non-raw-Signatures.
The resulting Signatures are still a bit bare, I'm going to try to improve that in a followup to improve our Signature printing in general.
Fixes astral-sh/ty#73