Dart-Code icon indicating copy to clipboard operation
Dart-Code copied to clipboard

Render large types in multiline

Open rrousselGit opened this issue 2 years ago • 2 comments

Hello!

Earlier I encountered the following:

Screenshot 2024-01-13 at 18 54 14

As it is, the type is very unreadable.

I think it would be much better VScode formatted the type in a more humanly readable way For instance:

({
  ProviderFamily<R, Arg> Function<R, Arg>(
    R Function(Ref<R>, Arg), {
    Iterable<ProviderOrFamily>? dependencies,
    String? name,
  }) autoDispose,
  ProviderFamily<R, Arg> Function<R, Arg>(
    R Function(Ref<R>, Arg), {
    Iterable<ProviderOrFamily>? dependencies,
    bool isAutoDispose,
    String? name,
  }) call,
})

It is suddenly more clearer what we're dealing with.

rrousselGit avatar Jan 13 '24 17:01 rrousselGit

One way to do that could be to use dart_style combined with a typedef.

The way I formatted the type on my end was:

typedef Foo =  ({ProviderFamily<R, Arg> Function<R, Arg>(R Function(Ref<R>, Arg), {Iterable<ProviderOrFamily>? dependencies, String? name}) autoDispose, ProviderFamily<R, Arg> Function<R, Arg>(R Function(Ref<R>, Arg), {Iterable<ProviderOrFamily>? dependencies, bool isAutoDispose, String? name}) call});

Then use the "add trailling comma" quick fix. Then format.

rrousselGit avatar Jan 13 '24 17:01 rrousselGit

Yeah, it'd be nice if these were formatted better. I suspect we're building a string to describe the element, but maybe it'd be nice if we were able to extra the code from the file (as the user formatted it) and show that. This string likely shows up in many others place too, so we'd need to figure out which places it makes sense to format and which are best on a single line.

Needs some experimenting I think!

DanTup avatar Jan 15 '24 11:01 DanTup