DEV Community

Discussion on: Easily sort imports and remove unused declarations on each save in VS Code

Collapse
 
laxedo17 profile image
laxcivo

thx for the tip! Still, when I do that my code doesnt format on Auto Save. I gotta save manually for it to work, sigh. Any ideas? I program on C# and F#

Collapse
 
ddrempe profile image
Damir Drempetić

Hi @laxedo17! I'm glad if post was useful to you. Did it work on manual save with C# and F#?

Which preference do you use for Auto Save (afterDelay, onFocusChange, onWindowChange)?

I don't use Auto Save because I like to have full control, but tested it now and it didn't work only when I choose afterDelay.

Please check this issue on GitHub: Allow autoSave and formatOnSave. There is whole discussion about it and a possible workaround which could work for you.

Let me know whether it works. :)

Collapse
 
laxedo17 profile image
laxcivo

thanks!!!! I use afterDelay, also no change with others. Gotta test the workaround. Many many thanks

Thread Thread
 
fatihapaydin profile image
Fatih Apaydın

In order to remove C# usings from vs code solution you can follow github.com/OmniSharp/omnisharp-vsc... link also

Collapse
 
laxedo17 profile image
laxcivo

tested already. Works like a charm! Only thing I'd need is to configure it for all files (.cs .fs), and I found this easy way following the post you linked to! (changed the .cs or .fs whatever, to simply a .* )

"runOnSave.commands": [
    {
        "match": ".*",
        "command": "editor.action.formatDocument",
        "runIn": "vscode"
    }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
laxedo17 profile image
laxcivo

okayyyy. Final test made, and I chose to use onFocusChange instead of afterDelay.

The issue is that when formatting in real time, you can go crazy and delete, move, switch to certain expressions 'cos the autoformat in real time moves your cursor or displaces words to tidy everything up.

cheers m8

Thread Thread
 
ddrempe profile image
Damir Drempetić

Cool, I'm glad you quickly found a solution for your way of working. :)