dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.56k forks source link

[analyzer] Different completion results for constructors with and without named imports #56225

Open incendial opened 1 month ago

incendial commented 1 month ago

Hi, consider the following example:

class Test {
  const Test();

  const Test.named();
}

when I type the name of this class and add . - only the named constructor appears in the completion suggestions:

Screenshot 2024-07-11 at 19 19 03

but when the class is imported via named imports, the default constructor also appears in the completion suggestions:

Screenshot 2024-07-11 at 19 20 09

which is inconsistent (and does not look like the desired behavior)

Dart SDK version: 3.4.3 (stable) (Tue Jun 4 19:51:39 2024 +0000) on "macos_arm64"

dart-github-bot commented 1 month ago

Summary: The Dart analyzer provides inconsistent constructor completion suggestions depending on whether the class is imported with a named import. The default constructor is only suggested when using a named import, which is unexpected and potentially confusing for users.

bwilkerson commented 1 month ago

I guess the first question is: which behavior is better? It seems a bit odd to me to suggest new because it's not a coding style we want to encourage, but it is valid so others might have a different opinion.