"Only analyze projects with open files" results in import resolution errors if you jump into Flutter without having run "flutter update-packages" (and possibly pub packages in pub cache)
Describe the bug When I look at the library source code in VSCODE, some imports get this error, but not in IDEA.
To Reproduce Steps to reproduce the behavior:
CTRL + Mouse to enter the import and view the source code.
Expected behavior don't show this error
Screenshots
- Operating System and version: Windows 11
- VS Code version: win 1.85.0
- Dart extension version:3.78.0
- Dart/Flutter SDK version: Dart (3.2.3),Flutter (3.16.3)
How have you opened this file/project in VS Code? The dart:ui and package:flutter imports are only valid in the context of a Flutter project. If you open a Flutter project in VS Code and then navigate to these files, it should work fine.
If you think there's still a bug, please provide exact steps to reproduce this (starting with opening VS Code) and I'll take a look. Thanks!
I created the Flutter project in VS code, and here is the problem replication video.
https://github.com/Dart-Code/Dart-Code/assets/74097223/2d0bf656-8876-400d-967a-152f5aedcac6
Is it possible you have two different versions of Flutter on your machine?
Can you try:
- run
where.exe flutterin the terminal in VS Code - Run the Flutter: Change SDK setting from the VS Code command palette (
F1) and see which SDK is selected (take a screenshot, then pressEscapeto cancel)
Please provide screenshots of both
where.exe
Change SDK
Thanks!
where.exe
Change SDK
Thanks, looks like they are the same SDK. I've still not been able to reproduce. Could you try capturing a log?
- Open an empty folder in VS Code
- Run the Dart: Capture Analyzer Logs command from the command palette (
F1) - Now run
flutter create .in the terminal - Open
lib/main.dart ctrl+clickonpackage:flutter/material.dartctrl+clickonsrc/material/about.dart- Wait for errors to appear
- Click Cancel on the logging notification
- Attach the log file here
Here is a video showing the steps (although the error does not occur for me).
https://github.com/Dart-Code/Dart-Code/assets/1078012/21388dd6-4c55-4cde-b5cd-589e84eb83f4
If you can reproduce and attach the log file, I might be able to understand what's happening.
Thanks!
I have found the cause of the problem. I checked this option:
After I unchecked this option and restart VS Code, everything is fine.
I think this option causes files are same to not being in the context of the flutter project.
Thank you very much for your previous reply.
I thought you might have that option ticked, however I tested with and without that option but had not been able to reproduce the issue.
If you can reproduce (even with that setting enabled), I would still be interested in the log noted above so I can do some debugging and see whether I can fix it.
(although I'll note, that I do recommend keeping that setting unticked and ticking it only for the specific workspaces that need it if required)
Have you restarted VS Code after checking that option? I need to restart VS code to reproduce the issue.
And here is the log file (ticked option and reproduce the issue):
Dart-Code-Log-2023-11-04 10-42-36.txt
This log file is only 500+ KB, but during the process of capturing logs, there were several instances where I recorded 40+MB of log files. They are beyond the size of the attached the file.
I took a brief look. There are hundreds of “Target of URI doesn't exist” records in the big log files, and there are only three log files uploaded, which is the three of about.dart displayed.
This issue has been marked stale because it is tagged awaiting-info for 20 days with no activity. Remove the stale label or comment to prevent the issue being closed in 10 days.
Thanks - I understand what's happened now. Because I contribute to Flutter, I've previously run flutter update-packages on my machine, which means there is a .dart_tool/package_config.json file inside my package:flutter. This means all of the paths can be resolved.
If I delete that folder then step into some of the framework files (with the option above set), I'll see the same issue:
So this issue occurs if:
- you are using "only analyze projects with open files"
- have not run
flutter update-packages(so that the Flutter package analyzes cleanly in isolation) - you step into a framework file that references a
package:flutterlibrary
A possible fix for this is to have "only analyze files from open projects" to only consider files that are also inside the workspace. I don't know if that would impact other users of this though and will need to think more about it.
For now, I would recommend not using that setting (or running flutter update-packages to set up your Flutter SDK for contribution).