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

"Format Changed Lines" command #630

Closed
ryaninvents opened this issue Nov 10, 2018 · 5 comments · Fixed by #2447
Closed

"Format Changed Lines" command #630

ryaninvents opened this issue Nov 10, 2018 · 5 comments · Fixed by #2447
Labels
enhancement locked Please open a new issue and fill out the template instead of commenting.

Comments

@ryaninvents
Copy link

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.

@CiGit
Copy link
Member

CiGit commented Nov 11, 2018

Some quick pointers:

Prettier's range formatter

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.

Example

myFn({
	opt1: "val",
	opt2: "val2",
})

Now adds opt3 : "val3" and range format it: It will format the entire snippet.

Multiple ranges

Prettier supports only 1 range per format call. Having multiple (one for each change) should be faster (1 parse)

Prettier VSCode

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

VSCode

We may do it as a specific action prettier.formatChangedLines or it may be something provided by vscode's formatter API. Maybe like registerChangedLinesFormatter

Linter integration

They do not support giving them a range. #137

@bjornicus
Copy link

bjornicus commented Jan 10, 2019

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

@yagudaev
Copy link

yagudaev commented Jul 9, 2019

Any updates on this?

@ntotten
Copy link
Member

ntotten commented Oct 22, 2019

VS Code doesn't support this natively. We would only add this if VS Code's edit providers add this type of API.

@ntotten ntotten closed this as completed Oct 22, 2019
@github-actions
Copy link

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.

@github-actions github-actions bot added the locked Please open a new issue and fill out the template instead of commenting. label Apr 12, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement locked Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants