Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you determine which formatter is being used for VS Code?

If you have multiple extensions installed how do you determine which formatter is running on your document?

For instance I have a couple of HTML extensions that may format HTML but I'm not sure which one is actually formatting, or if multiple are. I'm not even sure which extensions may be contributing to the formatting honestly. Recently auto formatting in HTML and CSS have changed how they're formatting in ways that I do not care for, and I would like to know which extension is doing this so I may be able to change configuration or disable the extension. Currently I have something like 80-90 extensions so going through one by one is a ridiculously timely process that I would like to stay away from if there is a programmatic way of determining this. It seems that extensions have to register with the formatting service so that they can do their auto formatting, but I'm not sure if there's a way to debug, hook, or view those.

like image 632
CTS_AE Avatar asked Apr 03 '18 23:04

CTS_AE


People also ask

How do I change the format style in VS Code?

In the command palette, search for format and then choose Format Document. Then choose Prettier - Code Formatter. Note: If you do not see a prompt for selecting a default format, you can manually change this in your Settings. Set Editor: Default Formatter to esbenp.


2 Answers

Starting with the 1.33 release (March 2019), attempting to format a file for which there are multiple formatters registered results in a popup like this:

Note that the notification is "silent" if formatting happened implicitly via "format on save" or "format on paste", meaning that you need to click the bell in the lower right for it to show up:

The Configure... menu then lists all the formatters available for the current language. One of them can be selected as a default formatter for Format Document and Format Selection:

Picking for instance "Prettier" here results in this being added to the global settings.json:

"[html]": {     "editor.defaultFormatter": "esbenp.prettier-vscode" } 

There are also two new commands for formatting a file with a specific formatter, Format Document With... and Format Selection With.... This can be useful for formatting a specific file with a formatter that's not set as the default formatter. The former is also available from the context menu:

like image 189
Gama11 Avatar answered Sep 23 '22 07:09

Gama11


In addition to the answer given by Gama11 You can got to settings.json on below given path

C:\Users\<username>\AppData\Roaming\Code\User\settings.json 

I am using "prettier" formatter for my html files, also you can find the formatter been used for other extensions if configured.

Formatter configured for HTML files in settings.json

like image 44
Sameer Jadhav Avatar answered Sep 20 '22 07:09

Sameer Jadhav