Skip to content

Patterns and records are missing some IDE features like autocomplete, highlight usages under caret, ctrl click go to, and quick docs on hover #55740

@Mike278

Description

@Mike278

Most IDE features work for most interactions with patterns and/or records, but there are a few cases that seem to be missing support.

The following examples were done with the following environment:

  • Dart 3.3.4 (stable) (Tue Apr 16 19:56:12 2024 +0000) on "windows_x64"
  • IntelliJ IDEA 2023.1.2
  • Dart IntelliJ plugin 231.9065

Autocomplete

Place the caret after ba and before the ; and trigger autocomplete (ctrl+space) - the list of suggestions should include bar, but it does not.

// Destructure object in for-loop
for (final Foo(:bar) in [Foo(0)]) {
  ba;
}

// Destructure named record in for-loop
for (final (:bar) in [(bar: 0)]) {
  ba;
}

// Destructure positional record in for-loop
for (final (bar,) in [(0,)]) {
  ba;
}

Show type info in quick doc

Place the caret inside the left-hand-side bar and trigger quick docs (ctrl+q) - the quick docs window should popup and show type information, but instead the popup says No documentation found.

// Destructure object
{
  final Foo(:bar) = Foo(0);
}

// Destructure named record
{
  final (:bar) = (bar: 0);
}

Control+click go to

This one's a bit less clear for records (compared to classes) due to positional fields and a potential lack of explicit type annotation, but at least for cases like below, it seems like control+clicking on .bar and .$1 should be pretty unambiguous. Pretty much anything is better than nothing :P

{
  final x = (bar: 0);
  x.bar;

  void foo(({int bar}) params) {
    params.bar;
  }
}

{
  final x = (0,);
  x.$1;

  void foo((int,) params) {
    params.$1;
  }
}

Highlight usages under caret

Place the caret inside any of the variables below (foo, bar, or $1) - all usages of that symbol within its scope should be highlighted, but they aren't. Note that code like bar; bar; is to show that neither will trigger a highlight. Also note that removing usages triggers an unused variable warning, so at least part of the analysis is working.

// Destructure object
{
  final Foo(:bar) = Foo(0);
  bar; bar;
}

// Destructure named record
{
  final (:bar) = (bar: 0);
  bar; bar;
}

// Destructure positional record
{
  final (bar,) = (0,);
  bar; bar;
}

// Destructure list
{
  final [foo, ...bar] = [0, 0];
  foo; foo;
  bar; bar;
}

// Variable pattern in if-case
{
  if (0 case final bar) {
    bar; bar;
  }
}

// Variable pattern in switch expression
{
  final _ = switch (0) {
    final bar => bar
  };
}

// Variable pattern in switch statement
{
  switch (0) {
    case final bar: bar;
  }
}

// Named record field access
{
  final x = (bar: 0);
  x.bar; x.bar;
}

// Positional record field access
{
  final x = (0,);
  x.$1; x.$1;
}

Happy to provide screenshots and/or screencasts to help clarify any of these cases!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-completionIssues with the analysis server's code completion featuredevexp-hoverIssues related to hoversdevexp-uxtype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions