Giter Club home page Giter Club logo

Comments (5)

Tom-Bonnike avatar Tom-Bonnike commented on June 15, 2024 3

Done with 1.4.0.
Just update your extension! The setting is formattingToggle.activateFor.

Thank you! :)

from vscode-formatting-toggle.

prayash avatar prayash commented on June 15, 2024 1

@Tom-Bonnike Thanks for the prompt response! The reason I bring it up is because I've never found formatOnPaste to be desirable. In most cases it does more harm than good. Check out the demo below:

Notice how as I start to add a newProp to my React component, I paste the name of the method that I want to assign for the newProp's value. Immediately on paste, it tries to format (in my case Prettier), which leads to a lot of visual confusion as the cursor has now moved and all the formatting of the file has gone haywire simply because I pasted in a method. This is one of many situations I've run into. Now imagine if formatOnPaste is off, I would paste, and finish making my changes, and save file. At that point my formatter would kick in and make whatever changes necessary, and I see a ✅ at the bottom right. I know I've done it right and move on.

formatonpaste

Another reason is that I rely on my formatter to correct my syntax. Say if I've missed a ( somewhere, my formatter would immediately show a X at the bottom corner of VS Code. So if my code doesn't format itself, I know I've missed something somewhere. It's a nice sanity check while saving changes onto a file, and I'd rather have that check happen on Save, and not on Paste. Because a paste doesn't mean that I'm done making my changes and now want it to be formatted, but a Save does.

I think your last suggestion is great. What if we ship some default options for what most users would use, and then allow the user to override? That way current users can keep using the Plugin as normal, and picky users like me can add an extra key to their settings JSON?

Like you said, if I was able to add to my settings.json file a formattingToggle.activate = ["formatOnSave"], my Formatting toggle would only formatOnSave, and I can toggle away and live happily ever after. 😄

from vscode-formatting-toggle.

Tom-Bonnike avatar Tom-Bonnike commented on June 15, 2024 1

OK, I was just curious, but it makes a lot of sense to allow users to choose which settings are set back on anyway! I’ll try to find some time to implement it ASAP 😌

from vscode-formatting-toggle.

Tom-Bonnike avatar Tom-Bonnike commented on June 15, 2024

// `formatOnType` should only be toggled on if the user had enabled it
// beforehand.
if (setting === 'formatOnType') {
const initialValue = savedConfiguration[setting]
return editorConfiguration.update(
setting,
initialValue,
CONFIGURATION_TARGET
)
}
// The other formatting settings are *probably* safe to be toggled on.
return editorConfiguration.update(setting, true, CONFIGURATION_TARGET)

Haha “probably safe”.

In https://github.com/Tom-Bonnike/vscode-formatting-toggle/blob/master/src/initCommand.ts, I’m saving the initial editor.… configuration. This is only done once, when VSCode starts. This is useful so that I can set the value back to what it was for formatOnType, since I’m assuming very few people actually turn this setting on and so they wouldn’t want it put back to true.

I didn’t do it for formatOnPaste and formatOnSave because:

  1. If I put those settings back to their initial value, they could both be set back to false… But as a user I would expect the extension to always activate them, even if they were deactivated when I first launched VS Code.
  2. I simply assumed that’s what most people use and that it wouldn’t cause any problem.

Could you please explain why you dislike formatOnPaste? 🤔Do you have any suggestion on how I could handle that? I can’t really guess if the user wants formatOnPaste or not… :/


Maybe I could add some settings that I would use? Wouldn’t that be overkill? 😄
Something like: formattingToggle.activate = ["formatOnPaste", "formatOnSave"]?
And I could simply do what I’m doing right now if this setting isn’t found.

I might be missing a simpler solution? :)

from vscode-formatting-toggle.

prayash avatar prayash commented on June 15, 2024

Wow, that was quick! Thank you so much - this is amazing 😍

from vscode-formatting-toggle.

Related Issues (20)

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.