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.23k stars 1.57k forks source link

Update "Import library" correction to account for linter rules #53819

Open Mike278 opened 1 year ago

Mike278 commented 1 year ago

Dart SDK version: 3.3.0-48.0.dev (dev) (Fri Oct 20 09:02:07 2023 -0700) on "windows_x64"

Steps to reproduce:

This function seems to suggest the order depends on the value of prefer_relative_imports, but changing this value doesn't change the order.

Might be related to https://github.com/dart-lang/sdk/issues/32916 where support for relative imports was added?

Mike278 commented 1 year ago

[...] (I haven't tested this in any other editor)

I should have! This works as expected in VSCode.

Interestingly if I rename foo.dart to zzz.dart the order flips, so IntelliJ is sorting it alphabetically somewhere.

bwilkerson commented 1 year ago

The ordering of completion suggestions produced by the analysis server is taken as "advice" from most editors / IDEs. We can't change the behavior of the editors, so there's probably nothing we can do to improve this situation.

Mike278 commented 1 year ago

Looks like this might be the API to do it for IntelliJ?

Alternatively, what if the "Import Library" correction also took into account other preferences like avoid_relative_lib_imports or always_use_package_imports? If it could be configured such that there's only ever one correction in the list then the order doesn't matter.

bwilkerson commented 1 year ago

... what if the "Import Library" correction also took into account other preferences ...

That's a direction we're definitely interested in moving toward. We have started using lint enablement to control some other code generation styles (fixes, iirc), and should do so here as well.