Skip to content

"Add 'x' to dependencies" quick-fix does not handle package URIs with multiple slashes correctly #5378

@KaiGerdMueller

Description

@KaiGerdMueller

The problem my feature request is related to:

I am using the standard VS-Code setup to develop a flutter app.

Recently I needed imports of the form:
import 'package:highlight/languages/java.dart';

So not like:
import 'package:<package_name>/<file_name>.dart';

But like:
import 'package:<package_name>/<folder_name>/<file_name>.dart';

I tried to go about it the usual way, simply using this suggestion to automatically import, but it failed:

Firstly, if you just start with such an import in an empty project, you sometimes don't even get that option:
image
(Perhaps even with any import?)

Tough, after a few seconds, things normalize regarding that:
image

So that's not that much of a problem in my opinion.

Now for the real "issue", if you just try the "auto-import" suggestion, you get:

[flutter_application_1] flutter pub add highlight/languages
Using a naked argument for directory is deprecated and will stop working in a future Flutter release.

Use --directory instead.
Expected to find project root in highlight/languages.
exit code 1

If you modify the import to look like this, however:
import 'package:highlight/sth.dart';
(With some nonexistent file name)

Then the import works as expected, and you can change the import back to:
import 'package:highlight/languages/java.dart';
which then works.

It seems to me, the layman, that importing only part of a library is not possible (anymore?) for some reason, causing the "auto-import" to needlessly fail, when it could instead just try to import the whole library, not just the specific folder.

The "easy" solution:

From my layman perspective, it seems like a simple solution would be for the auto-importer to simply always import the whole library.

Possible issues with the "easy" solution:

As I'm not that experienced with dart and flutter, it may be that in other use cases, people actually need the auto-import to work this way, and I simply don't know it. In this case, it would probably be best to have auto-import first try to work as it does now, and then have it work as in the "easy" solution if and only if the other way does not work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresis bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions