-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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 only modified lines #44075
Comments
Been hoping for this for a while. In the meantime, I've knocked up an extension... https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.format-modified |
Awesome! Just tried it out and it seems to work so far. |
Great job, but this shouldn't be an extension IMO, this is a legit issue with editor and i don't personally think "feature-request" label is applicable here. I'm in the same boat and i have to use external merge tool (e.g.meld) to rollback unwanted changes. |
That extension appears to be C++ only, anyone know of a Python equivalent? |
Extension appears to support many languages now, but only because clang-format supports multiple languages
|
Any update on this issue? I don't want to use the extension mentioned above because all my formatting is set up via their respective language servers. This is a very valid use-case that needs addressing. |
This will land with the August release. This is what I planning to merge later this afternoon
Note that knowing "what is modified" requires active source control, like git. Without source control there are no modifications and nothing will be formatted. |
Looks awesome, thank you! |
@jrieken This looks great, thanks! When you say that without source control there are no modifications, are you saying that the setting |
Yes - if a project is not under source control and format on save is limited to modifications then no formatting happens. Tho, when a project is under source control than all modified and added lines/files are formatted. |
I'm asking about a different setting |
Oh, misread that. Yeah, format on type has nothing to do with format on save and nothing has changed for that |
This feature is great. I like it. |
The command |
It will only show up when you have a formatter that supports formatting modified ranges, e.g one that support range formatting. The rule of thumb is that if you have "Format Selection" then you also have "Format Modified Lines" |
which popular formatters currently support this? I have prettier but cannot seem working with this feature |
A lot of people are asking for format modified on type instead of save. I didn't ask for that since I thought it does not make sense. If you format on type then you always just format the lines as you modify them. I needed format modified since I wanted to make changes to several lines and then save and see just those lines formatted. Also I was using C++ with clang_format which does not work well with formatting single lines since it sometimes removes the line you are typing on, hence the desire to format modified lines on save. |
Unfortunately this often doesn't work often giving "Overlapping ranges are not allowed! error prettier/prettier-vscode#497 |
My extension uses PHPCS/CBF to format PHP files and because many of the rules are dealing with whitespace formatting allowing format selection does not work well. PHPCBF has an option to only format modified lines. I would like to be able to implement this without also implementing format by selection and just format the document using PHPCBF's internal filter for git modified. However, it seems that as far as I can tell the Format only Modified Lines feature just piggybacks off of the already established API for format selection which I do not want to support. Also, because I do not implement |
not sure if this is the right place for this, but thank you for this @kylegmaxwell it was a sad day when i had to disable formatOnSave |
Issue Type
Feature Request
Description
It would be helpful if there were a way to format only the modified lines. What is modified would be determined by source control. Currently formatOnType only works with semi colon (see microsoft/vscode-cpptools#1419), and formatOnSave formats the entire file. This is undesirable when working on large codebases with legacy code. In that case I want to make a small change, and have it automatically formatted on save, but not modify the rest of the file, which would create a huge diff.
It would also be great to have similar behavior for trimming trailing white space.
VS Code Info
VS Code version: Code 1.20.1 (f88bbf9, 2018-02-13T15:31:21.019Z)
OS version: Linux x64 4.14.16-200.fc26.x86_64
Steps to Reproduce:
"editor.formatOnSave": true,
"C_Cpp.clang_format_path": "/usr/bin/clang-format",
Does this issue occur when all extensions are disabled?:
No, formatting does not work at all in that case.
The text was updated successfully, but these errors were encountered: