Skip to content

Inlay hints for patterns #4624

@Zekfad

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 patterns (switch, if-case, destructuring, etc.)
For now it's only possible to see inferred type from hover popup.

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

Describe alternatives you've considered
Not really.

Additional context
Also inferred patterns are not navigable, in example hint Box<int> allows to navigate to int, but Box<(int, int)> both ints are not navigable.
And probably inferred single element pattern should be (Type,) instead of (Type).

final class Box<T> {
  const Box(this.value);
  final T value;
}
void main() {
  {
    { // actual
      final (i, j) = (1, 2);
    }
    { // expected
      final (int i, int j) = (1, 2);
    }
  }
  {
    final pattern = (test: (10,), 2);
    { // actual
      if (pattern case final p) {}

      final (_, :test,) = pattern;

      final Null _switch = switch (pattern) {
        (:final test, var i) => null,
      };
    }
    { // expected
      if (pattern case final (int, {(int,) test}) p) {}

      final (_, :(int,) test,) = pattern;

      final Null _switch = switch (pattern) {
        (:final (int,) test, var /*int*/ i) => null,
      };
    }
  }
  {
    const simple = Box(2);
    const pattern = Box((1,2));

    { // actual
      if (simple case Box(:final value)) {}
      if (pattern case Box(:final value)) {}
      if (pattern case Box(value: final test)) {}
    }
    { // expected
      if (simple case Box<int>(:final int value)) {}
      if (pattern case Box<(int, int)>(:final (int, int) value)) {}
      if (pattern case Box<(int, int)>(value: final (int, int) test)) {}
    }
  }
}
Screenshot of current behavior

image

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 enhancementrelies 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