Dart-Code
Dart-Code copied to clipboard
[Request] On variable hover, show the typedef instead of the full type if possible
Consider this snippet:
typedef MyTypedef = T Function();
MyTypedef variable;
In this snippet, hovering variable will show a contextual menu where the type of variable is said to be T Function().
This is not ideal when the typedef is more complex as it becomes rapidly unreadable. For example, I have a typedef that looks like this:
typedef Complex<A> = T Function<T>(
T Function(A value),
Function _,
Function __,
);
It is incredibly more readable to see Complex<A> than the full blown function prototype.
The suggestion would be that since variable explicitly uses MyTypedef, the tooltip should say that variable is of type MyTypedef instead of T Function().
This sounds reasonable - maybe it could include both (since if you're trying to satisfy it, knowing what Complex<A> actually means would help). The information in the hovers all comes from the analysis server, which doesn't currently supply any info on the typedef:
{
"id": "96",
"result": {
"hovers": [
{
"offset": 167,
"length": 3,
"containingLibraryPath": "/Users/dantup/Desktop/Dart Sample/bin/types.dart",
"containingLibraryName": "bin/types.dart",
"elementDescription": "T Function<T>(T Function(String), Function, Function) foo",
"elementKind": "top level variable",
"isDeprecated": false,
"staticType": "T Function<T>(T Function(String), Function, Function)"
}
]
}
}
So this would need to be supported by the server first - would you mind opening an issue in dart-lang/sdk with the info above and post the link back here? (I'm trying to avoid being the author of a ton of issues in the SDK repo, it's better to have the original requestor :-))
Done https://github.com/dart-lang/sdk/issues/39332
Just to add to this the same applies for type aliases.
typedef MemberId = int;
void func(MemberId memberId);
...
// call it.
func(memberId);
When I hover over func after the 'call it' comment the memberId is shown as an Int. I want it to show the type alias to remind me that this int actually needs to be a member id.
It's better to add that to https://github.com/dart-lang/sdk/issues/39332, since that's where it'll be implemented. This issue is a little superfluous, though I'll keep it open to verify the fix via LSP once done.