sdk icon indicating copy to clipboard operation
sdk copied to clipboard

`Import library with prefix` assist

Open FMorschel opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe.

In my company, we have some packages for internal use and in the past there have been times when a package class was extended/implemented with the same name inside our apps. This gives room for conflicts when both the package and the class are imported into another file.

Other use-cases would be dart:math, dart:ui and package:http/http.dart which are almost always imported with prefixes.

Describe the solution you'd like I'd like to have an option of an import library quick-fix that asks for a prefix or moves the cursor after the as and before the ; on the import line.

Describe alternatives you've considered Manually looking for the import and adding the prefix.

Additional context It would be perfect if this could parse the prefix if prewritten on the method/class/etc like:

dev.log //<- This would ask to import either `dart:math` or `dart:developer` with the prefix `dev`.

Requested first at https://github.com/Dart-Code/Dart-Code/issues/5123 but was asked to open the request here first.

FMorschel avatar May 29 '24 12:05 FMorschel

That's an interesting idea, thanks for raising it.

It's very hard to find, but there is another way to do this that's implemented today.

If you add the import without a prefix, then right click on the keyword import and perform a Rename refactoring, replacing the default name of 'import' with the name of the prefix will add the prefix to the import directive and every reference to every name that comes from that library.

bwilkerson avatar May 29 '24 14:05 bwilkerson

I've been using your suggestion a lot. Thanks! I'd like to point out that it would be even more useful if https://github.com/dart-lang/sdk/issues/56584 existed.

FMorschel avatar Aug 30 '24 02:08 FMorschel

Related to:

  • https://github.com/dart-lang/sdk/issues/41515
  • https://github.com/dart-lang/sdk/issues/24338

FMorschel avatar Aug 30 '24 22:08 FMorschel

https://dart-review.googlesource.com/c/sdk/+/389780

FMorschel avatar Oct 12 '24 05:10 FMorschel

I support this quick fix.

srawlins avatar Oct 29 '24 16:10 srawlins