Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I configure this to run in VSCode? #825

Closed
ghost opened this issue Jun 26, 2019 · 8 comments
Closed

How can I configure this to run in VSCode? #825

ghost opened this issue Jun 26, 2019 · 8 comments

Comments

@ghost
Copy link

ghost commented Jun 26, 2019

Hi,

I've spent hours trying to figure out how to get this to run in VS Code. Running Format Document does not format the Dart code.

I can run dartfmt from the command line and it works great, just not in the IDE.

Any suggestions?

Thank you!

@natebosch
Copy link
Member

The Dart Code plugin can set things up to run dartfmt.

https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code

@ghost
Copy link
Author

ghost commented Jun 26, 2019

@natebosch I could not find any instructions for setting this up in the docs you pointed me to. I had read this before posting this.

Do you know how to do this?

@a14n
Copy link
Contributor

a14n commented Jun 26, 2019

@ghost
Copy link
Author

ghost commented Jun 26, 2019

@natebosch @a14n, with outstanding assistance from @DanTup I got this sorted out.

I manually added the below [dart] formatter config and everything is working. What I found strange was the other languages offered me an option in vscode to make these the formatter for their language. But I never got the prompt nor extra menu option in the document context menu to set this.

At any rate this work for me.
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[scss]": {
"editor.defaultFormatter": "sibiraj-s.vscode-scss-formatter"
},
"[dart]": {
"editor.defaultFormatter": "Dart-Code.dart-code"
},

Thank you,

Karl

@DanTup
Copy link
Contributor

DanTup commented Jun 26, 2019

For anyone else coming across this, the issue here was that VS Code had written the editor.defaultFormatter setting globally as the VS code settings formatter for @kdawg1406, so it was being used to format everything. It's not clear why that happened, and it didn't seem easily reproducible.

It's not necessary to set:

"[dart]": {
"editor.defaultFormatter": "Dart-Code.dart-code"
},

unless you have a global default formatter (which doesn't seem like it should happen, it's unlikely any formatter can format every language), however that is the correct way to select the Dart-Code formatter if you do happen to have another extension that advertises to VS Code that it can format Dart (though VS Code should prompt you about this so you don't need to set it manually).

@shamilovtim
Copy link

@DanTup This was a lifesaver, thank you! VSCode team needs to fix this badly and I think Flutter extension needs to add the [dart] configuration by default so this doesn't happen. In my case prettier was dominating all of my formatters.

@DanTup
Copy link
Contributor

DanTup commented Jan 9, 2020

@shamilovtim the problem with setting Dart-specific configurations in VS Code is that they're not discoverable to the user (see microsoft/vscode#58995), which means if the user did set a global one, it wouldn't be clear why Dart is ignoring it (we do this for indent spaces, and it catches people out that want to globally use tabs).

Maybe we could add it to the recommended settings (which has a command to automatically write into your user settings file)? Though really, if something is causing VS Code to unexpectedly write a global formatter, that sounds like a bug (as far as I know, there are no formatters that handle every language, and I don't think VS Code makes it easy to set globally?).

@DanTup
Copy link
Contributor

DanTup commented Jan 9, 2020

(I posted this on the VS Code issue.. it somewhat seems to be working as intended if people are copy/pasting the config from its readme which explicitly sets it as the default formatter for all languages)


Oh, I found this:

https://github.com/prettier/prettier-vscode#default-formatter

It seems like that extension is specifically encouraging this. In which case this somewhat seems working as intended. If you configure a formatter for every language, then of course it will run for every language. I think really that readme should only include languages that it actually formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants