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

Add a "Save Without Formatting" command #38695

Closed
coreh opened this issue Nov 18, 2017 · 10 comments
Closed

Add a "Save Without Formatting" command #38695

coreh opened this issue Nov 18, 2017 · 10 comments
Assignees
Labels
feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded workbench-editors Managing of editor widgets in workbench window

Comments

@coreh
Copy link

coreh commented Nov 18, 2017

Would be really nice to add a command that allows bypassing automatic formatting while saving a file, if the user has it enabled.

Specifically, saving using this command would skip the changes caused by enabling either:

"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.formatOnSave": true,

(Not sure if there are more transformations that can be triggered on save)

It probably doesn't need to be bound to any specific keyboard shortcut by default.

Reasoning: Very often I find myself having to patch a third-party package, by either cloning their repo and submitting a PR, or by directly editing the package inside node_modules (Using the patch-package tool), and it will usually produce a large/ugly diff because of the several changes caused by automatic formatting. I can surely disable the setting temporarily (or add a .vscode folder inside node_modules disabling the options), but neither is an ideal solution.

Thanks in advance!

@vscodebot vscodebot bot added the workbench label Nov 18, 2017
@bpasero bpasero added feature-request Request for new features or functionality editor and removed workbench labels Nov 19, 2017
@bpasero bpasero removed their assignment Nov 19, 2017
matt-tingen added a commit to matt-tingen/vscode that referenced this issue May 2, 2018
@matt-tingen
Copy link

I have a branch pretty close for this, but could use some guidance before I make it a PR.

My change uses the existing skipSaveParticipants option. However, this would also skip CodeActionOnParticipant and ExtHostSaveParticipant, which—if I understand correctly—wouldn't necessarily relate to formatting.

  1. Being personally unaware of other use cases for save participants, I'm not sure whether this is an acceptable solution or if participants would need to be categorized so we can specifically skip only those relating to formatting.
  2. I suspect that "participants" is not a well-recognized term for users and "Save without participants" would not be intuitive. What should the user facing name for this command be? Is there an existing term for this somewhere?
  3. I'm unclear on the difference between fileActions.ts and fileActions.contribution.ts when adding a command to the palette.

@bitjson
Copy link

bitjson commented Jun 8, 2018

I definitely think this should be built-in to VS Code.

Until then, here's a great workaround: https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.save-without-format#overview

@alexdima alexdima added workbench-editors Managing of editor widgets in workbench window and removed editor labels Sep 20, 2018
@bpasero bpasero self-assigned this Sep 21, 2018
@bpasero bpasero added this to the September 2018 milestone Sep 21, 2018
@bpasero
Copy link
Member

bpasero commented Sep 21, 2018

There is now a new command "Save without Formatting" with the keybinding Cmd+K S. If someone has a better name, feel free to suggest (initially I had "Save without Participants" but that seems a bit too technical).

@bpasero bpasero added the verification-needed Verification of issue is requested label Sep 24, 2018
@bpasero
Copy link
Member

bpasero commented Sep 24, 2018

Verify: see #38695 (comment)

@coreh
Copy link
Author

coreh commented Sep 24, 2018

Thanks! 🎉🎊🍕🎈

Are there extensions with participants unrelated to code formatting in common use? If so "Save without Transforms" or "Save Verbatim" might also make sense. Otherwise, "Save without Formatting" sounds good.

@bpasero
Copy link
Member

bpasero commented Sep 24, 2018

@coreh yeah "Save without Formatting" would even mean that any extensions cannot participate even if not doing any formatting.

But my rationale was to cover the 99% case of why one would actually use that action in the first place and that is probably to prevent any kind of format to happen.

@jrieken
Copy link
Member

jrieken commented Sep 25, 2018

Maybe "Save without Extensions". This will disable all kind of code actions that run on save and that's actually a thing.

@bpasero
Copy link
Member

bpasero commented Sep 25, 2018

I am not convinced. People might confuse this to "save the file without a file extension". I am not sure there is any use case for using this command other than preventing any formatting from happening, so I would stick with the name or something similar in that direction.

@sandy081 sandy081 added the verified Verification succeeded label Sep 25, 2018
@vivaldus
Copy link

@bpasero I tried to save a file without formatting following your suggestion: "Cmd+K S", but instead of saving without formatting, VSCode just brought up the menu for key bindings. (VSCode can be so confusing at times. I used to happily use shift+option+s to achieve this, then it stopped working, and now I can't seem to get a simple answer for how to achieve this. Would really appreciate some guidance here!)

@ghost
Copy link

ghost commented Oct 26, 2018

@vivaldus looks like the keybind changed...

image

Remember you can usually (if not always) search within Visual Studio Code. Yay for VS Code being such a useful tool.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded workbench-editors Managing of editor widgets in workbench window
Projects
None yet
Development

No branches or pull requests

8 participants