Code completion does not behave correctly
See original GitHub issueHi!
I have a problem with code completion with my project. It worked up until a certain point but then stopped working. I first noticed the issue some time during the holidays. I can’t pinpoint to a specific version of VSCode, Dart-Code or the Flutter SDK as I’ve tried several different version and combinations by downgrading.
TLTR; Dart-Code can analyze my code but fails to provide quick fixes.
What doesn’t work:
- Code completion with classes from within my project
- Quick Fixes (missing import statements, remove unused imports, surround with new widget, etc)
What works:
- Code completion of external packages from pub
- Code formatting
- Static analysis (using pedantic rules)
- Refactoring like renaming classes
- Classes are found without problem once I add the import statements manually
What I’ve tried (and didn’t fix the problem)
- Downgrading versions of VSCode, Dart-Code and Flutter SDK
- Deleting all generated files:
rm -rf .dart_tool/ build/ .flutter-plugins .flutter-plugins-dependencies .packages
Strange occurrence: Deleting the files worked once and the next morning code completion the problem magically reappeared. Deleting doesn’t work anymore.
- Checkout a fresh copy of the repository on another PC and try again
- Remove pedantic code analyzer
- I’ve looked at https://github.com/Dart-Code/Dart-Code/issues/1846 and https://github.com/Dart-Code/Dart-Code/issues/1742. Both seem unrelated to me.
- Check out an older version of my code
The problem doesn’t appear when I create a new project using flutter create myproject
. I’ve added the analyzer logs to this gist: https://gist.github.com/fusion44/87bf104afba4cf1edcecf80781a75522.
My repository: https://github.com/fusion44/sendmany
Any idea what might cause this? Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Thanks! I was able to repro this from your video and code.
I traced the issue back to the
analysis_options.yaml
file in yourlib
folder. I believe what’s happening is the analysis server is finding that file inlib
and then treating that folder as the project root - which means it doesn’t find the referenced packages. If you rename this file away and reload VS Code, the quick-fixes seem to appear.As far as I can tell, the
analysis_options.yaml
file should be alongside thepubspec.yaml
(see https://dart.dev/guides/language/analysis-options#the-analysis-options-file), though I do recall seeing discussion about it being nested. It’s slightly strange that if you manually add theimport
then things work - so it’s possible this is a bug - @bwilkerson might be able to confirm.@fusion44 based on Brian’s comment above, it sounds like this can be considered an analysis server bug, so it should be raised at https://github.com/dart-lang/sdk/issues. If the SDK is updated to handle this, it won’t require any changes in the VS Code extension.
Thanks!