Skip to content

Import library with prefix assist #55863

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

Closed
FMorschel opened this issue May 29, 2024 · 5 comments
Closed

Import library with prefix assist #55863

FMorschel opened this issue May 29, 2024 · 5 comments
Labels
devexp-quick-fix Issues with analysis server (quick) fixes devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead. P4 type-enhancement A request for a change that isn't a bug

Comments

@FMorschel
Copy link
Contributor

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 Dart-Code/Dart-Code#5123 but was asked to open the request here first.

@DanTup DanTup added legacy-area-analyzer Use area-devexp instead. devexp-server Issues related to some aspect of the analysis server devexp-quick-fix Issues with analysis server (quick) fixes type-enhancement A request for a change that isn't a bug labels May 29, 2024
@bwilkerson
Copy link
Member

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.

@FMorschel
Copy link
Contributor Author

FMorschel commented Aug 30, 2024

I've been using your suggestion a lot. Thanks! I'd like to point out that it would be even more useful if #56584 existed.

@FMorschel
Copy link
Contributor Author

@srawlins
Copy link
Member

I support this quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-quick-fix Issues with analysis server (quick) fixes devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead. P4 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants