flutter / flutter-intellij

Flutter Plugin for IntelliJ
https://flutter.dev/using-ide
BSD 3-Clause "New" or "Revised" License
1.95k stars 316 forks source link

Flutter SDK Path resolves symlink #6616

Open rivella50 opened 1 year ago

rivella50 commented 1 year ago

Steps to Reproduce

  1. Open Settings -> Languages & Frameworks -> Flutter
  2. Enter a symlink path in the Flutter SDK path field and click Apply
  3. The path is resolved

Please tell us what you were doing and what went wrong

The path shouldn't be resolved since this doesn't allow me to update the Flutter version using FVM in the shell. The path is resolved which causes me to manually change the Flutter SDK version in the settings as well.

I use FVM for handling different Flutter versions in my ongoing projects. Switching a version works by calling fvm use VERSION in the console, where the symlink to the new Flutter version path is changed in .fvm/flutter_sdk

If i remember correctly the absolute path to the symlink could be entered in the mentioned SDK path text field and wasn't resolved when i clicked Apply or Ok in an earlier version of this plugin, which allowed me to only change the Flutter version in the shell which was then recognized and automatically updated in the IDE.

Now this isn't possible anymore since the path to the symlink isn't kept but resolved.

Version info

[✓] Flutter (Channel stable, 3.3.2, on macOS 13.1 22C65 darwin-arm, locale en-CH) • Flutter version 3.3.2 on channel stable at /Users/valley/fvm/versions/3.3.2 • Upstream repository https://github.com/flutter/flutter.git • Framework revision e3c29ec00c (5 months ago), 2022-09-14 08:46:55 -0500 • Engine revision a4ff2c53d8 • Dart version 2.18.1 • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/valley/Library/Android/sdk • Platform android-33, build-tools 33.0.1 • ANDROID_HOME = /Users/valley/Library/Android/sdk • ANDROID_SDK_ROOT = /Users/valley/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14C18 • CocoaPods version 1.11.3

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.2) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin version 72.0.4 • Dart plugin version 223.8617.8

[✓] VS Code (version 1.74.3) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.58.0

[✓] Connected device (3 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 12 (API 32) (emulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.1 22C65 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability • All required HTTP hosts are available

• No issues found!

stevemessick commented 1 year ago

I spent some time in the debugger to find how the symlinks were handled. The conversion from symlink to directory happens in the IntelliJ UI framework. Unfortunately, we can't change this behavior unless we rewrite the SDK selection code to use some component that does not resolve symlinks (if there is one). The component we currently use is deprecated, so we'll need to change it someday. We'll try to use one that does not resolve symlinks.

rivella50 commented 1 year ago

That would be great. Thanks a lot for investigating it, @stevemessick .

dasRicardo commented 1 year ago

Hello,

i have the same problem if i use the file browser. A temporary fix, if u paste the path directly into the input field, the path stays.

There is a second problem with fvm and the sdk path. The problem in my opinion is the cacheKey. Projects have a symlink and all projects with the same flutter version have the same canonical path like: fvm/versions/3.10.5. If u set the path for the first project, the key is created and saved the path for this project. But if u go into another project, set the path and the symlink points to the same flutter version, the code produces the same canonical path and will find an entry in the 'projectSdkCache' map and return this entry (first project with the same flutter version).

This function is in FlutterSdk.java line 149 actual master branch.

private static FlutterSdk saveSdkInCache(VirtualFile home) { // this is the problem because all projects with the same version got the same canonical path final String cacheKey = home.getCanonicalPath(); synchronized (projectSdkCache) { if (!projectSdkCache.containsKey(cacheKey)) { projectSdkCache.put(cacheKey, new FlutterSdk(home, FlutterSdkVersion.readFromSdk(home))); } } return projectSdkCache.get(cacheKey); } Sorry for my english.

AlexV525 commented 10 months ago

@rivella50 Can you try changing the Dart SDK path with a linked path? Is it resolved or remains the same as you entered?

rivella50 commented 10 months ago

@AlexV525 As mentioned in my initial post i entered the symlink in the Flutter SDK input field (which then also applies the included Dart version), and this symlink is resolved when i hit the Apply or Ok button.

AlexV525 commented 10 months ago

@AlexV525 As mentioned in my initial post i entered the symlink in the Flutter SDK input field (which then also applies the included Dart version), and this symlink is resolved when i hit the Apply or Ok button.

What I mean is to set the Dart SDK path with symlinked without toggling Flutter's path.

ManuelRauber commented 4 months ago

@stevemessick

I spent some time in the debugger to find how the symlinks were handled. The conversion from symlink to directory happens in the IntelliJ UI framework. Unfortunately, we can't change this behavior unless we rewrite the SDK selection code to use some component that does not resolve symlinks (if there is one). The component we currently use is deprecated, so we'll need to change it someday. We'll try to use one that does not resolve symlinks.

That's interesting. When I did a little PR in FVM repo (https://github.com/leoafarias/fvm/pull/576) the IDE did not resolve the symlink. Also, I added code to check that in fvm doctor command (https://github.com/leoafarias/fvm/blob/e5c0c0fe5ef09ca64d471ef81f3d7b2e22c4420f/lib/src/commands/doctor_command.dart#L138-L144).

Windisch94 commented 1 month ago

any fix or workaround available for this?