Skip to content

Include type arguments in Type Hierarchy #4217

Closed

Description

@DanTup
class A extends B<String> {}
class B<T> {}

When browsing the hierarchy from A, we see a node for B but it doesn't include <String> (or <T>).

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    in editorRelates to code editing or language features
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    on Oct 14, 2022
  2. added this to the v3.52.0 milestone on Oct 14, 2022
  3. dupuchba commented on Oct 19, 2022

    @dupuchba

    Is there anyway I can help ? I've worked quite a lot with the analyzer API

  4. DanTup commented on Oct 19, 2022

    @DanTup
    MemberAuthor

    Right now this is blocked on me finishing https://dart-review.googlesource.com/c/sdk/+/264300 (which is blocked on another change I'm working on). I'm hoping to get them done fairly soon, though.

  5. DanTup commented on Oct 20, 2022

    @DanTup
    MemberAuthor

    @bwilkerson with the ability to round-trip element locations, I had a look at this. Including the type arguments for the "next level" works fine because from an element when we get its supertypes/subtypes we have the type arguments (in an InterfaceType).

    However, since we then only round-trip an element reference, those type args are lost in subsequent hops:

    Screenshot 2022-10-20 at 14 57 34

    I guess it turns out that really I wanted to tround-trip the InterfaceType rather than the Element. Is there anything existing that might help with this, or do you have any suggestions for what might be a reasonable way? (I may still send what I've got so far in the meantime since I think this behaviour is probably still an improvement over not showing any type args at all).

  6. bwilkerson commented on Oct 20, 2022

    @bwilkerson

    To the best of my knowledge, we don't have any support for serializing and deserializing instances of InterfaceType (outside the summary file format, but I'm skeptical that we want to try to send binary data back and forth to the client).

    The easiest way I can think of off-hand would be to keep the ElementLocation of the original element, then some indication of the "path" from that to the type we're trying to access. If the list of supertypes is stable then the path could just be the indexes into the lists of children.

    I'm not sure whether it's worth the effort, so I'm happy to go either way with it.

    But it does seem to me that it's better to be consistent, because I think it could be misleading not to be. As a result, I'd say we should either have all or none. That is, if we don't use an InterfaceType at every level of the hierarchy then we shouldn't use it at any level (and if we're not displaying actual types, then we should probably just drop the type arguments from the display).

  7. DanTup commented on Oct 20, 2022

    @DanTup
    MemberAuthor

    If the list of supertypes is stable then the path could just be the indexes into the lists of children.

    Interesting idea. I don't think we can guarantee they're stable (the type hierarchy nodes are long-lived on the client) but we could compare the new type we arrive at with the element location and ensure they still match up. If they don't, we could fall back to just showing the elements type parameters (as in the example above), but I think that will be an edge case (there's a Refresh button the user can use to re-sync the type hierarchy if they make changes that are likely to have affected its navigation, so having it sometimes go awry after changes is not unexpected).

    I'll give it a go and see how it works.

  8. dupuchba commented on Oct 20, 2022

    @dupuchba

    ultra reactive ! I've been sick all day, I am feeling better and I'll take a look tomorrow

  9. DanTup commented on Oct 25, 2022

    @DanTup
    MemberAuthor

    @dupuchba hope you're feeling better!

    I was able to make this work properly using Brian's suggestion above. Types are now shown (and correctly flow across supertypes):

    Screenshot 2022-10-25 at 13 09 17

    Your example from #4226 looks like this:

    Screenshot 2022-10-25 at 14 02 20

    And in the case where the type args are available:

    Screenshot 2022-10-25 at 14 03 29

    Change hasn't landed yet, it's up for review at https://dart-review.googlesource.com/c/sdk/+/264981. This is an SDK change so once landed, it will show up in a future Dart/Flutter SDK release (and not a VS Code extension release).

  10. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Oct 25, 2022
  11. DanTup commented on Oct 31, 2022

    @DanTup
    MemberAuthor

    This changed landed in dart-lang/sdk@27ba8fc. It's part of the SDK so will show up in a future Dart/Flutter SDK release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions