Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mike278 opened this issue May 16, 2024 · 1 comment
Labels
analyzer-completion Issues with the analysis server's code completion feature analyzer-language-patterns Issues with analyzer's support for the patterns language feature analyzer-ux area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Mike278
Copy link

Mike278 commented May 16, 2024

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!

@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label May 16, 2024
@scheglov scheglov added analyzer-completion Issues with the analysis server's code completion feature P3 A lower priority bug or feature request analyzer-ux analyzer-language-patterns Issues with analyzer's support for the patterns language feature labels May 16, 2024
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label May 24, 2024
@Mike278
Copy link
Author

Mike278 commented Jul 5, 2024

Idk if I did myself a disservice by grouping these into one issue, but if I had to pick one that's the most annoying, it's the missing control+click go-to.

As another concrete example, this was the code I was just typing that prompted me to check back on this issue:

I have a class that just exists as a namespace for some constants:

class JustANamespace {
  static final some = 1;
  static final variables = '2';
  static final and = false;
  static final stuff = 3;
}

final hello = JustANamespace.some; // ctrl+click on `some` brings you to the declaration

I decided I wanted to nest some of these in their own namespace:

class JustANamespace {
  static final nested = (
    some: 1,
    variables: '2',
  );
  static final and = false;
  static final stuff = 3;
}

final hello = JustANamespace.nested.some;  // ctrl+click on `nested` works, but ctrl+click on `some` does nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-completion Issues with the analysis server's code completion feature analyzer-language-patterns Issues with analyzer's support for the patterns language feature analyzer-ux area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants