When I use "Format on Save", it formats the entire document. This introduces changes on lines I have not touched, making code review much more difficult.
I would like to have the option to check only changed lines, as measured by the active SCM plugin. This would prevent formatting changes from concealing the actual work done in a pull request, while still ensuring that the code I have modified is "Prettier".
I'd be willing to take a shot at this. Please let me know if this would be better handled in the Prettier project or the VS Code project.
Some quick pointers:
Currently prettier as a range formatter which is far from prefect and works only on some languages. It formats the first common parent of your range which is a valid Program.
myFn({
opt1: "val",
opt2: "val2",
})
Now adds opt3 : "val3" and range format it: It will format the entire snippet.
Prettier supports only 1 range per format call. Having multiple (one for each change) should be faster (1 parse)
We should have a way to obtain _changed_ ranges. This is maybe already possible. We shouldn't have to include a dependency on every SCM out there.
This would allow us -- with the help of first point -- to format changed lines
We may do it as a specific action prettier.formatChangedLines or it may be something provided by vscode's formatter API. Maybe like registerChangedLinesFormatter
They do not support giving them a range. #137
FWIW, there's an extension that does something like this: https://github.com/Gruntfuggly/format-modified but it looks like it's using clang-format instead of prettier; perhaps that can help with adding this functionality to Prettier VSCode
Any updates on this?
VS Code doesn't support this natively. We would only add this if VS Code's edit providers add this type of API.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Any updates on this?