:DartFmt does not work with flutter SDK
netskink opened this issue · 13 comments
Im using pathogen to install the plugin. I have dart syntax as a result, but none of the :commands work. For instance if I issue :DartFormat I get
[dart-vim-plugin] cannot execute binary file: dartfmt
It looks like there is something broken in your Dart SDK install, that file should be marked executable. Can you run dartfmt from the command line?
from my home dir I can not run dartfmt. I did not modify my path. Let me look again at the install instructions. FWIW I used the pathogen method to install.
hmm. when I first started dart, I had a file in ~/flutter called setenv.sh. I use that to modify my path to get access to tools in flutter/bin. After I use that to modify my path, I can not use dartfmt. dartfmt resides in .flutter//bin/cache/dart-sdk/bin/dartfmt so its not reachable by the default path.
@cbracken - Do you know if there are any special resources we should be pointing flutter users towards to help with the install to make dartfmt available.?
Hmmm - that's an interesting point. Flutter's install instructions (e.g. macOS) specify that $(pwd)/flutter/bin should be added to the path, but we don't suggest adding the underlying Dart SDK bin/ dir. That's because we don't expect users to ever interact with the Dart SDK directly -- the flutter tool delegates out to the appropriate underlying tools where necessary.
Generally I'm not keen on us updating our install docs to suggest users add the embedded Dart SDK to the path. Given that we route everything through the flutter command, it's basically an internal implementation detail. A couple reasonable options here:
- Flutter could expose
dartfmtfrom itsbin/directory. That could be useful. - dart-vim-plugin could try to detect flutter on the path and use the bundled
dartfmtif one isn't on the path (this is effectively what IntelliJ and VSCode Dart plugins do)
Thoughts?
Actually, TIL: flutter format is a thing :)
We should just update the plugin to look for dartfmt and if it doesn't find it, try flutter format before failing.
A bit more digging -- flutter format doesn't currently support reading from stdin, which we use. We'll need to add a --stdin option (or use a convention like passing - implies stdin), then make this change.
I appreciate you guys taking time to work on this. I enjoy the results of your work. Tip of the hat to you!
Hi all!
Just gently bumping this issue as I'm experiencing the same thing. I'm very new to Dart and Flutter, but let me know if there's any way I can help.
Thanks!
I filed a feature request at flutter/flutter#41011
I'm not eager to entirely re-implement out approach to formatting to work around it so I think we need to wait for the flutter team on this one.
@cbracken - is there a consistent way we can get from the location of the flutter command to the Dart SDK that comes with flutter? We could also consider doing some path manipulation ourselves to try to find it if it's not on $PATH.
Dart SDK that comes with flutter? We could also consider doing some path manipulation ourselves to try to find it if it's not on $PATH.
Yes. The Flutter SDK contains a copy of the Dart SDK and is laid out as follows:
flutter
/bin/flutter
/bin/cache/dart-sdk/
#90 used that layout for the SDK to track down the dartfmt. Things seemed to work well for me when I removed my normal Dart SDK from my path and go through the flutter SDK for it. I think everyone should be unblocked now.
We have another option now. Both the flutter and dart SDK expose the dart command, which now supports dart format. At some point we can consider dropping support for older SDKs that don't have this support. For now things are working find.