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 destructing functions are colored the same as getters #59976

Open
FMorschel opened this issue Jan 24, 2025 · 4 comments
Open

Patterns destructing functions are colored the same as getters #59976

FMorschel opened this issue Jan 24, 2025 · 4 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request

Comments

@FMorschel
Copy link
Contributor

FMorschel commented Jan 24, 2025

Today the colouring for geters and methods is different. See the following code:

class Class {
  void Function() get getter => () {};
  void method() {}
}

void foo() {
  var instance = Class();
  instance.getter;
  instance.method;
}

This differenciates both in declaration and on usage even tough both of the above work the same*.


Today we have patterns that allow us to deconstruct a variable:

class Class {
  int myField = 0;
}

void foo() {
  var instance = Class();
  if (instance case Class(myField: var myFieldValue)) {}
}

We also can get** a method as a FunctionType:

class Class {
  int foo(int x) => x;
}

void bar() {
  var instance = Class();
  if (instance case Class(foo: var fooFn)) {
    fooFn(3);
  }
}

I'd like to request the same colouring to be applied here inside pattern destruction - at least when we have the name before : but I'd be fine with it also being applied to the new variable here if it has the same name.


*I've opened dart-lang/language#4159 related to this propriety.
**1. I've opened dart-lang/language#4234 related to this functionality.

**2. @lrhn has commented the following:

We also can get a method as a FunctionType:

Not absolutely sure that's intended, but will have to check the future specification to be sure whether it's allowed by that.

@FMorschel FMorschel added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jan 24, 2025
@FMorschel
Copy link
Contributor Author

FMorschel commented Jan 24, 2025

Here are some screenshots to help:

Image

Here I've highlighted foo to see the different colouring:

Image

I'd like some more consistency in method highlighting.

@DanTup
Copy link
Collaborator

DanTup commented Jan 24, 2025

Yeah, I feel like both foos here should be highlighted the same (in the yellow colour). I'd have to do some debugging to figure out why it's not - the colours for semantic tokens are mapped from the servers Highlight kinds. Methods are usually handled around here:

bool _addIdentifierRegion_method(

So my guess is that we're not going in here for the second foo identifier.

@bwilkerson
Copy link
Member

I'd like to wait to see whether method tear-offs are allowed in patterns before we fix this issue. But I agree that if tear-offs are allowed it would be good to color them in such a way that it's more obvious when it's happening.

@bwilkerson bwilkerson added the P3 A lower priority bug or feature request label Jan 24, 2025
@lrhn
Copy link
Member

lrhn commented Jan 24, 2025

The spec allows it.
(If the link target doesn't work, search for "normal property extraction rules".)

Can't see a good reason for allowing tear-offs, but it's there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

4 participants