Skip to content
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

Quickfix to add package to pubspec.yaml. #42159

Open
lrhn opened this issue Jun 2, 2020 · 3 comments
Open

Quickfix to add package to pubspec.yaml. #42159

lrhn opened this issue Jun 2, 2020 · 3 comments
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P4 type-enhancement A request for a change that isn't a bug

Comments

@lrhn
Copy link
Member

lrhn commented Jun 2, 2020

If I write import "package:foo/foo.dart";, and there is no foo package in my package configuration, could we have a quick-fix to add it to the pubspec.yaml file (and run pub get).
(Make it a dev_dependency if the file is not in lib/.)

Is that possible, or must quick-fixes be in the same file?

An alternative would be a pub command like pub depend foo which adds a foo dependency to the pubspec.yaml file, but that requires the user to leave the editor.

@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-server type-enhancement A request for a change that isn't a bug labels Jun 2, 2020
@bwilkerson
Copy link
Member

Quick fixes are allowed to modify files other than the one in which they are invoked. You can see this, for example, by referencing, in a part file, an identifier that is not yet imported and selecting the fix to add an import. The import is correctly placed in the library file.

The harder question, in my mind, is what text to add. More specifically, which version constraint to use.

Quick fixes work by sending back a description (the menu item) and the edits to apply to implement the fix. That means that we have a limited amount of time in which to compose the edits before it impacts the UX.

My concerns are that

  • we likely won't be able to communicate with pub.dev to get a list of available version within that timeframe, and
  • even if we could we won't be able to know which versions are compatible with the version constraints on other packages within that timeframe.

I love this idea, but I'm not immediately seeing a way to implement it.

@lrhn
Copy link
Member Author

lrhn commented Jun 2, 2020

You could use any. Then Pub would probably pick the newest version compatible with all the other constraints. Users can change that if they need a specific version.

It does sound like pub is the right place to solve the problem more deepply. They can find the newest version of the package that is compatible with either the versions in pubspec.lock or find a new solution for everyone.

@bwilkerson
Copy link
Member

Yes, pub could solve the problem more deeply. But it might be more convenient to have a quick fix to add the any version and then have pub tell you when the lower bound of a package's constraints can't be used (because of the other dependencies) and hence could be tightened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P4 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants