Giter Club home page Giter Club logo

vscode-formatting-toggle's Introduction

Formatting Toggle

A VS Code extension that allows you to toggle your formatting settings ON and OFF with a simple click.

Installation

In the command palette (CMD + SHIFT + P) select “Install Extension” and choose “Formatting Toggle”.

Usage

The extension should show up on the right side of the status bar. Simply click it to toggle the formatting settings ON and OFF. Alternatively, in the command palette (CMD + SHIFT + P), run the “Toggle Formatting” command.

⚠️ Formatting Toggle doesn’t override your workspace settings as these are usually tracked by Git. Consider using ignore configurations (like .prettierignore) to ignore specific files for all contributors of your project.

Customization

By default, Formatting Toggle toggles all formatting settings: editor.formatOnPaste, editor.formatOnSave and editor.formatOnType. To toggle different settings, or to prevent a specific setting from being toggled, you can use the formattingToggle.affects setting in your editor settings (Code › Preferences › Settings).

💡 Formatting Toggle was created with formatting settings in mind but allows you to toggle any boolean setting that lives at the root of the VSCode configuration. editor.codeActionsOnSave is currently the only deeply nested setting supported.

The status bar text can also be customized via the formattingToggle.statusBarText setting. Values for formattingEnabled and formattingDisabled are distinct, and can include different codicons for each state. See Product Icon Reference for all options.

Examples

Keeping editor.formatOnPaste and editor.formatOnType enabled at all times:

{
  "editor.formatOnPaste": true,
  "editor.formatOnType": true,
  "formattingToggle.affects": ["editor.formatOnSave"]
}

Keeping editor.formatOnType disabled at all times:

{
  "editor.formatOnType": false,
  "formattingToggle.affects": ["editor.formatOnPaste", "editor.formatOnSave"]
}

Allowing editor.codeActionsOnSave to be toggled:

{
  "formattingToggle.affects": ["editor.codeActionsOnSave.source.fixAll.eslint"]
}

Allowing all formatting settings to to be toggled (default):

{
  "formattingToggle.affects": [
    "editor.formatOnPaste",
    "editor.formatOnSave",
    "editor.formatOnType"
  ]
}

Customizing the status bar text:

{
  "formattingToggle.statusBarText": {
    "formattingEnabled": "On $(heart-filled)",
    "formattingDisabled": "Off $(heart)"
  },
}

vscode-formatting-toggle's People

Contributors

coliff avatar dgrebb avatar imgbotapp avatar rickstaa avatar tom-bonnike avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vscode-formatting-toggle's Issues

Incorrect Formatting Issue

I am facing an issue with the "Formatting Toggle" extension in Visual Studio Code. The extension is adding unwanted spaces in my code when formatting is enabled, causing errors in my script.

Infer `formattingToggle.affects` from the initial user configuration

For months, I've been confused about why formatOnPaste kept getting re-enabled, and I've finally tracked it down to this extension. affects fixes the issue, but it took a lot of digging to find this as the cause.

It would be great if this behavior were either more prominently presented, or if this plugin could somehow infer what affects should be when it's installed.

Formatting Toggle does not work?

A few weeks ago, your extension stopped working on all my machines. All I see in the panel is an icon. There are no other errors in the terminal. When i click on the icon, nothing happens. Complete uninstallation VSC and reinstallation did not help.

What could be the problem?

Windows 10 (x64) 1803
VSC 1.62.3
Formatting Toggle (v3.0.0)

Screenshot_1

Possible to disable `editor.formatOnPaste` permanently?

I've never had success with the editor.formatOnPaste setting so I have that set to false but this plugin overrides it whenever it is toggled. I'm mostly interested in toggling formatOnSave.

Any thoughts on adding a flag to disable that? I can take a crack at it and open a PR 😄

The status bar element disappears from the status bar when switching to a code editor

I have a problem with the status bar "Formatting" element - it disappears when I'm switching to a code editor tab from the Extension page in the VS Code Remote instance (Dev containers).

Reproduce steps:

  1. Open a remote session (attach to a Docker container)
  2. Open the "Formatting toggle" extension page.
  3. Click on the "Enable" button.
  4. See that the "Formatting" element has successfully appeared in the status bar.
  5. Switch to another tab with a code editor.
  6. See that the "Formatting" element has disappeared in the status bar.
  7. Use the "Toggle formatting" action in the command palette to switch the mode.
  8. See that the "Formatting" element has again successfully appeared in the status bar.
  9. Switch to another tab with a code editor.
  10. See that the "Formatting" element has disappeared in the status bar again.

It also appears back if I disable the extension, then reload, and enable it again. But still until I switch the current tab.

On the local instance (without Remote) it works well.

Could you please try to reproduce this on your side and invent some fix for it? Thanks!

Add an icon

would be nice to have an icon for this extension.

[Feature Request] Indentation of Preprocess Instructions

Thank you for make this great extension, but preprocess intructions in c++ doesn't indent properly, blocks start with # are always formatted to start at the beginning of the line:

void ExampleMethod()
{
	if (1)
	{
#if DEBUG
		int value = 0;
#endif
	}
}

I suppose it should be better if they are indented to desired level :

void ExampleMethod()
{
	if (1)
	{
	#if DEBUG
		int value = 0;
	#endif
	}
}

or:

void ExampleMethod()
{
	if (1)
	{
		#if DEBUG
		int value = 0;
		#endif
	}
}

or:

void ExampleMethod()
{
	if (1)
	{
		#if DEBUG
			int value = 0;
		#endif
	}
}

No toggle in my status bar

It's just Formatting: <checkmark icon> - so I have no idea if it is toggled on or off, nor how I can toggle it. Note it does not change when I run CMD + Shift + P and select "Toggle Formatting".

bisect results

Issue Type: Bug

extension bisect identified as a problem extension

Extension version: 2.0.0
VS Code version: Code 1.55.2 (3c4e3df9e89829dce27b7b5c24508306b151f30d, 2021-04-13T09:35:57.887Z)
OS version: Windows_NT x64 10.0.19042

System Info
Item Value
CPUs AMD Ryzen 7 3700X 8-Core Processor (16 x 3593)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 31.95GB (17.06GB free)
Process Argv \\wsl$\Debian\home\dev1\.profile --crash-reporter-id deb06a08-2e95-455c-be88-6e5d4c5b1a89
Screen Reader yes
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
pythonvspyt678:30270856
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstry244:30276681
pythonvsdeb440:30248342
pythonvsded773:30248341
pythonvspyt875:30259475
pythonvsnew554:30281908
pythontb:30283811
openwsldoc:30282072
vspre833:30267464
pythonptprofiler:30281270
vshan820:30276952
pythondataviewer:30285071
vscus158cf:30286554

Implement disabling formatting on save via keybinding override

There are a lot of VSCode settings that makes IDE format the code on save:

  • editor.formatOnSave
  • editor.codeActionsOnSave (#54)
  • files.trimTrailingWhitespace
  • files.trimFinalNewlines
  • and even more...

Also extensions can format documents via vscode.workspace.onWillSaveTextDocument. I don't think it can be disabled with any setting.

It is much easier and more reliable to disable any possible formatting via overriding ctrl+s shortcut to workbench.action.files.saveWithoutFormatting.

I propose to add a boolean setting which would also enable this behavior.

I'd like to implement this, however I still in doubt how we can write to keybindings.json.
AFAIK we don't have direct access to neither settings.json nor keybindings.json via API, but we want this to also work in web.

formattingToggle.deactivateFor

Thanks for your extension 🙂

That would be nice to have an option formattingToggle.deactivateFor, in my case I would like to disable formatOnSave but keep formatOnPaste and formatOnType when I'm contributing to existing code.

Thanks

Toggle not working if editor.formatOnSave is set both on user and workspace settings

I have editor.formatOnSave set on user settings to be able to sync with my home preferences and also have it set on workspace settings to make some settings default for our company workspace.

Apparently it only takes the user settings in consideration, because once I disable editor.formatOnSave manually on my workspace settings it works as it should.

It happens using prettier on ts and beautify in html files

Please add "deactivateFor"

Originally posted by @Tom-Bonnike in #47 (comment)

I’ll close this, happy to reconsider if more people want something like this

As the other poster requested, please add "deactiveFor" to allow us to configure the behaviour to our liking.

As for the value, here is my scenario:

  1. I've configured editor's formatOnPaste and formatOnType to be always true.
  2. I want "formattingToggle" button to only affect formatOnSave (toggle on and off)

Why 1)?
Cause for the code I edit (i.e. paste and type), I want it nice and organized.

Why 2)?
Cause not everyone uses VScode. In a big company, on a big project, there are tons of people writing code, and not always following formatting guides (whether I should re-format everyone else's file is outside the scope of this discussion). So, majority is existing code is not formatted to the same standards

If, every time I modify a single line for a fix and save, it will reformat the whole file, it will make huge changes on commits, resulting in potential conflicts on many lines when merged back to other branches (with other non-formatting people working on same files). So no, I don't want "formatOnSave" to be on when working on collaborative work (but I still want my changes formatted, so I have editor setup to always format on paste and type)

But when working on my own files, I want to toggle "formatOnSave" to true.

Yes, I could achieve this through different .vscode per-workspace files... Or through that other extension that binds keyboard shortcuts to different settings....
But the whole point of the quick status bar toggle is to avoid setting up custom workspace settings per each folder I work on, and to avoid remembering keyboard shortcuts.

We are not asking to change default behaviour. We are asking to give us the option to configure our custom behaviour.

Thank you.

Ability to toggle when using language scoped settings

Maybe I'm missing a way this can work out the box but if not it would be great if you could support the toggling of format on save when you are using it scoped to each language. Doesn't seem to be able to toggle it currently.

"editor.formatOnSave": false,
"[php]": {
  "editor.formatOnSave": true
},
"[javascript]": {
  "editor.formatOnSave": true
}

I had to work around a similar situation so just to possibly save you a couple minutes of looking it up, this is how I went about checking for it. Using the always handy lodash has and get methods.

const config = vscode.workspace.getConfiguration();
if (has(config, '[php]')) {
  const phpScopedObj = get(config, '[php]');
  if (phpScopedObj['editor.formatOnSave']) {
    // Things to do when it exists.
  }
}

You would really make my day if you could somehow work out a way to toggle these as well, I haven't found anything yet to cover this situation and it gets old editing the settings file everytime so I don't polute the git logs of older sites without explicit formating settings in them with a bunch of formatting changes from my user settings.

Make sure user’s config is not overriden

Settings should:

  • Be toggled to undefined when not previously specified in the user’s config, false otherwise
  • Be toggled to true only if they are specified in the user’s config

Add Setting for Status Bar Text

It would be excellent if one could define the text accompanying $(check) and $(x) in the Status Bar.

I'm also curious if anyone would be interested in customizing the icons, as well. Personally, I quite like $(check) and $(x).

How this extension work?

First thanks for such a great plugin.

Do it uses prettier or what? How do I identify it bro? Currently I was having problem with laravel blade so It will be easy for me :) Is there way I can customize the formatting .

Issues with Version: 1.85.0 and/or workspace settings

Version: 1.85.0
Formatting Toggle v3.2.0

I was using the Status Bar Toggle Button to disable autoformatting on file save. However, that stopped working.
Could this be due to changes in a recent VS Code Update?
One thing I noticed is, that I have the setting on workspace level, not on user level. However the toggle is active but does not toggle…
image
image
image

Removing quote from an object property with string key

Thank you for developing this very nice plugin
Please can your make it not to remove an object property with a string key
like that $route thanks

<script>
export default {
  name: "app",
  methods: {
  aMethod(to, from){
}

},
  watch: {
   "$route": "aMethod"
  }
};
</script>

doesn't work with multiple vscode windows

With multiple vscode windows open if you toggle it in one it effects the other. This will also result in a inconsistent state where one window will show "formatting:x" indicating disabled when in fact its enabled and vice versa.

Not working with "Javascript React" files

Regardless of toggle (via clicking on the "formatting" in the bottom right corner), it formats.

I'm using "React native tools" which include Beautify.

This is happening in a .js code file listed as "JavaScript React".

Not sure what information you require to determine the problem.

vscode: 1.25.1
user settings:
"editor.formatOnSave": false,
"files.autoSave": "afterDelay",
"files.associations": {
"*.js": "javascriptreact"
},
"emmet.includeLanguages": {
"javascript": "javascriptreact"
},
"emmet.triggerExpansionOnTab": true,
"prettier.singleQuote": true,
"javascript.validate.enable": false,

Please add scope parameter to disable formatting for current workspace

Hi,

Thank you for your extension. I use it all the time to switch between personal and professional projects.

In this case, it might be nice to have an option to have the extension turn off formatting only for the workspace or folder scope.

For example, in my work, projects use only Eslint on the command line for formatting, which works fine.
In my personal projects, I have all the tools configured: Eslint, Prettier, Stylelint... that I don't want to disable manually one by one and depending on the projects.

Another example, in some cases you want to disable formatting just because it creates multiple diffs on a file, but you don't want to disable formatting across all your vscode windows for that!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.