Skip to content

Inlay hints for nested patterns #4712

Closed

Description

@Zekfad

Is your feature request related to a problem? Please describe.
It would be helpful to easily see (and navigate) to inferred types for nested patterns (switch, if-case, destructuring, etc.)
For now it's only possible to navigate to most inner inferred type.

Describe the solution you'd like
Make inlay hints for nested patterns behave like for generics (like #4366)

Describe alternatives you've considered
Not really.

Additional context
Addition to #4624

final class Box<T> {
  const Box(this.value);
  final T value;
}
void main() {
  {
    const boxedBox = Box(Box((1,2)));
    const boxedList = Box([1,2]);

    { // actual (notice that inner pattern is augmented correctly)
      if (boxedBox case Box(value: Box(:final (int, int) value))) {}
      if (boxedList case Box(value: List(:final int length)) when length > 0) {}
    }
    { // expected
      if (boxedBox case Box<Box<(int, int)>>(value: Box<(int, int)>(:final (int, int) value))) {}
      if (boxedList case Box<List<int>>(value: List<int>(:final int length)) when length > 0) {}
    }
  }
}

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Sep 3, 2023
  2. DanTup commented on Sep 4, 2023

    @DanTup
    Member

    @Zekfad I'm not sure I understand the code sample (specifically, which parts of the code are intended to be code, and which parts are intended to be hints). I don't see any hints in either the "actual" or "expected" code because they already have explicit types.

    Could you provide the code where you want to see hints without the hints (or with the hints in comments) so I can understand what you'd like? Thanks!

  3. added
    awaiting infoRequires more information from the customer to progress
    on Sep 4, 2023
  4. Zekfad commented on Sep 4, 2023

    @Zekfad
    Author

    Thank you for response, I'll clarify:
    in this line:

    if (boxedBox case Box(value: Box(:final (int, int) value))) {}

    First Box and second Box should be augmented like so (Box<Box<(int, int)>> and Box<(int, int)> respectively):

    if (boxedBox case Box<Box<(int, int)>>(value: Box<(int, int)>(:final (int, int) value))) {}

    Same for Box and List pairs from the 2nd line of examples.

  5. DanTup commented on Sep 4, 2023

    @DanTup
    Member

    Oh gotcha, thanks!

  6. added this to the v3.74.0 milestone on Sep 4, 2023
  7. added
    in editorRelates to code editing or language features
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    and removed
    awaiting infoRequires more information from the customer to progress
    on Sep 4, 2023
  8. Zekfad commented on Sep 4, 2023

    @Zekfad
    Author

    Thank you for your work, these hits makes it really easy to play aground switch cases!

  9. modified the milestones: v3.74.0, v3.76.0 on Oct 2, 2023
  10. DanTup commented on Oct 31, 2023

    @DanTup
    Member

    Working on a fix at https://dart-review.googlesource.com/c/sdk/+/332960. With the fix looks like this:

    Screenshot 2023-10-31 104940

    Screenshot 2023-10-31 104954

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

    @DanTup
    Member

    Fixed by dart-lang/sdk@939e081. It ships in the analysis server so will show up in a future Dart/Flutter SDK release rather than a Dart-Code release.

  13. Zekfad commented on Nov 1, 2023

    @Zekfad
    Author

    Thank you for your awesome work, this helps a lot!

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