leoafarias / fvm

Flutter Version Management: A simple CLI to manage Flutter SDK versions.
https://fvm.app
MIT License
4.46k stars 217 forks source link

[Enhancement] Maintain project reference to cache versions after switch #681

Open bkleineibst opened 4 months ago

bkleineibst commented 4 months ago

Before creating a bug report please make check the following

Describe the bug I use different versions of flutter in different branches of my repo. If I switch between branches, .settings.json references a version of flutter that doesn't necessarily exist anymore. I need to run fvm use to get the link to the correct version of flutter for the branch, for use from within vscode.

To Reproduce Steps to reproduce the behavior:

  1. Create 2 branches.
  2. fvm use different flutter versions in each branch, and commit .fvmrc and .settings.json in each branch.
  3. Switch branches.
  4. Reload vscode.
  5. Will complain about missing flutter sdk.

Expected behavior Should be able to switch branches and automatically use correct flutter version.

Desktop (please complete the following information):

Additional context fvm use seems to create a link to the appropriate version of flutter in the .fvm folder, and deletes other versions. If it kept other versions here, things should work, except on trying to use a new version that has not been used before.

leoafarias commented 4 months ago

@bkleineibst you should run "fvm install" to install the version that is configured.

The version is not "deleted" is just that the symlink gets removed.

Does the issue persist?

bkleineibst commented 4 months ago

@leoafarias fvm install works, as does fvm use. However, both of these delete my comments from settings.json. I know I can use json formatted comments, but they just don't stand out.

The main question is why remove the symlinks for other flutter versions when switching flutter versions with fvm? If they were left there, I would not have to fvm install to get the folder back.

leoafarias commented 4 months ago

Ok, I understand now. I will look into it. However, I need a way to clean up at some point.

Maybe use flavors as the flag to check if it should be maintained?

bkleineibst commented 4 months ago

@leoafarias My thinking is rather have symlinks to all installed flutter versions. There is very little cost of keeping all of them in each project. Maybe just delete symlinks in the project if their targets have been removed? I.e., keep symlinks in sync with all installed flutter versions.

leoafarias commented 4 months ago

@bkleineibst I have to think about it. FYI, some tools like melos and others depend on only one symlinks, which is flutter_sdk, that means that it is best practice to always rerun fvm install.

I think this should be handled by a trigger, on .vscode, maybe an FVM extension?

bkleineibst commented 4 months ago

@leoafarias How about when fvm is run, it always checks to make sure that the flutter_sdk/version file matches the version specified in .fvmrc. If not, it triggers an install, but without updating settings.json. (assuming there is no reason to update it)

If a solution like this would work, would you then need the specific version symlink in the .fvm/versions folder? Couldn't settings.json always point to flutter_sdk? Would this not also obfuscate the need to update settings.json at all, except maybe on a first-time fvm use?