I made changes to 2 lines in a file and the rest of the file and other files that I opened but didn’t change were formatted. I figured that this was due to the Editor: Format on Save
option being on. It was for the user but not the workspace.
Secondary question: Isn’t the workspace supposed to override the user?
The main question relates to the options for the mode, that is, Editor: Format on Save Mode
. I found the solution to my problem in this Stackoverflow question. I switched the mode option from file
to modifications
and after git checkout .
and making changes to the 2 lines, the saving didn’t affect formatting elsewhere.
However, I wasn’t sure what the reference to source control in the description of the 2 options (modifications
and modificationsIfAvailable
) was for. Why do these option explanations say that they require source control
to function? Is VS Code figuring out what the formatting style is from source control by parsing the entire file? If not, how is source control used for formatting specifically?
Related source code is in https://github.com/microsoft/vscode/blob/5f326ba3ef08e9ffb3392fdcc6685351f776f9eb/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts#L255. In this context, “modifications” refers to modified ranges of a document. I.e. With these modes, an attempt will be made to only format ranges of a document that have been modified.