I'm Working on a flutter work, i'm trying to format my file but its not working. I right clicked and clicked "Format Document" it doesn't work still.
I don't understand why this is happening.
VS Code version: 1.28.2
If you click Help -> Toggle Developer Tools in VS Code, are there are any errors shown?
We can only format code that is free of syntax errors, so if you the file contains any, that could explain it (though it'll have an error explaining in the developer console if this is the case).
I'm unable to investigate this without more details as mentioned above so I'm going to close it. I'm happy to reopen it if you can provide some additional info.
Format Document and format on save was not working for me too, and there is no errors on the console in developer tools. I've ignored it and used flutter format command for a while on terminal, but as of today I've noticed an error message, thanks to the vim plugin. When I use gg=G to format document from top the bottom, it says There is no selection formatter for 'dart'-files installed. and redirects me to extensions category:formatters dart, but both flutter and dart plugins are already installed.
Version: 1.32.3
Commit: a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4
Date: 2019-03-14T23:38:49.842Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Linux x64 4.20.16-200.fc29.x86_64
@mirkancal These two issues should not be related:
Format Document and format on save was not working for me too
This definitely sounds like a bug. Does it repro if you disable other plugins (like the Vim one)? I wonder if there might be something interfering?
There is no selection formatter for 'dart'-files installed.
This one is expected - the Dart SDK formatter doesn't support selections, so we only provide a Document formatter. If you want to format a Dart file, you need to format the whole document.
I've deleted only that plugin and now it's working.
I tried installing TODO Highlight but the formatting still seems to work correctly. If you reinstall it, does formatting break again? Could it be specific to the file or something you're formatting? (I added some TODOs to mine, but it still works). I also scanned their code, but they don't seem to be registering any formatters.
Also - can you confirm your VS Code version? There are formatting changes in progress in Insiders, are you using that?
I've reproduced the error now. In settings.json, I've added this code to let the plugin search for dart files too.
"todohighlight.include": [
"**/*.dart"
],
My VSCode version:
Version: 1.32.3 Commit: a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4 Date: 2019-03-14T23:38:49.842Z Electron: 3.1.6 Chrome: 66.0.3359.181 Node.js: 10.2.0 V8: 6.6.346.32 OS: Linux x64 4.20.16-200.fc29.x86_64
@mirkancal adding that setting doesn't make any difference here (though the TODOs were already highlighted in Dart even before I added it).
Can you repro if you disable all other extensions? I checked the source for TODO highlighter, but all it does is add decorations - there's no formatter and there's no manipulation of editor contents. I think that might be a red herring.
Note that if your code has syntax errors, it will silently not format - are you sure it's not that?
I'm just adding couple of spaces, I'm sure it's not the syntax errors.
Maybe when I add that line, vscode thinks that this extension is somewhat responsible for dart files meanwhile it has no formatter in it, nothing happens.
Maybe when I add that line, vscode thinks that this extension is somewhat responsible for dart files meanwhile it has no formatter in it
I don't think so - formatters are not tied directly to extensions - an extension can choose to register a formatter (or many) based on document selectors.
Are you certain the issue goes away with the TODO extension disabled? Could you try running Dart: Capture Logs and ticking Analysis Server then reproducing, then click Stop Logging to see if there are any edit.format calls in the log?
Formatting on save used to work until it didn't 馃ぃ
Disabling/removing this in settings.json did the trick
"[dart]": {
"editor.defaultFormatter": "Dart-Code.flutter",
},
Not sure when or why I've added it and why it worked until couple of minutes ago, but anyway..
Thought it might help someone 馃挌
I surprised that that ever worked; the Dart formatter is in the Dart extension (Dart-Code.dart-code) rather than the Flutter one.
There are some extensions that encourage setting them as the default formatter (for ex. Prettier) but do not format Dart code, which results in format not working. There's not much that can be done from Dart Code here - if you've explicitly set the formatter to something that can't format Dart then it will fail by-design. If you are going to set another Default formatter and want to override the Dart one back to Dart-Code, the correct setting is:
"[dart]": {
"editor.defaultFormatter": "Dart-Code.dart-code",
},
馃槄 now it's working that's all that matters 馃榿
Thanks for the explanation and setting for next time 馃憤
Hello, I'm coding flutter in Vscode. I did a system restore on my computer a few days ago. After this process, VScode is broke down. I installed it again and now there were other problems in vscode too. For example I can't open new flutter project, it gives this error when I try to open new project => "Command 'Flutter: New Project' resulted in an error (command 'flutter.createProject' not found)". I cannot format my code When I try to format it gives this error => "There is no formatter for 'dart' files installed". And I can't debug my original code. When I press the F5 button, VScode does not react at all, I am starting from the top debug menu. I can only debug my code by typing flutter run to the terminal. There is no problem in the result I got at the flutter doctor, what should I do. Please can you help? Thanks all from now
@ricirt its not a big issue, just you have to do is. Go to environment and add the path of your flutter folder their. After that open cmd in flutter folder and then run command flutter doctor, younwill se the possible errors and they will be solved by doctor command.
@ricirt also check for the extensions of dart and flutter in your vs code, maybe after re-install they were removed.
I downloaded the flutter sdk again and threw its paths back into another folder and tried again but its didnt
environment variable at the top, system variable at the bottom
@ricirt Then please recheck for the extensions in vs code. If this didn't resolve the problem then we will look forward to the problem
its done.it happened when I reinstalled the extensions. Oh thank you very very very much @muhammad-hamza-shahid
@ricirt your welcome, keep developing and bringing issues and also give a look on our repositries may be you find some good stuff for your work
Formatting on saving used to work until it didn't 馃ぃ
Disabling/removing this in settings.json did the trick"[dart]": { "editor.defaultFormatter": "Dart-Code.flutter", },Not sure when or why I've added it and why it worked until a couple of minutes ago, but anyway..
Thought it might help someone 馃挌
this worked for me
thanks
Most helpful comment
I surprised that that ever worked; the Dart formatter is in the Dart extension (
Dart-Code.dart-code) rather than the Flutter one.There are some extensions that encourage setting them as the default formatter (for ex. Prettier) but do not format Dart code, which results in format not working. There's not much that can be done from Dart Code here - if you've explicitly set the formatter to something that can't format Dart then it will fail by-design. If you are going to set another Default formatter and want to override the Dart one back to Dart-Code, the correct setting is: