VS Code: Keep Your Code Clean by Running Extension Commands on Save

VS Code: Keep Your Code Clean by Running Extension Commands on Save

There are many VS Code Extensions that make our lives as developers easier. If I think of the AL programming language, for example, they help us with the following things:

  • Replace missing brackets
  • Correct the casing of words
  • Sort fields in tables
  • โ€ฆand the list could go on forever.

That’s why I thought a while back that it would actually be cool to automatically execute a few of these commands when I save a file in Visual Studio Code. The VS Code Extension AZ AL Dev Tools for example has a setting “alOutline.codeActionsOnSave” which allows us to define a few commands.

That was a good start, but I wanted to be able to use similar functionality for other extensions. So I went searching and found a cool VS Code extension that helped me do that: Run It On

After installing the extension, open your “User Settings” via the Command Palette:

And enter this code here:

Match defines for which files in Visual Studio Code the command should be executed. The command at “cmd” is interesting for you here. There you enter the command of the extension that should be executed. You can find the command by looking in the “Feature Contributions” of the extension:

In the example I have chosen the RunEditorCodeCleanup command of the AZ Al Dev Tools Extension, which in turn executes these commands:

Maybe it is also useful for one of you. Have fun with it ๐Ÿ˜‰

86 thoughts on “VS Code: Keep Your Code Clean by Running Extension Commands on Save

  1. We created a vscode account and added necessary (company) settings and extensions to it. So, if a new developer joins he just needs to login sync the settings, logout and voila … everything prepared for the start.

  2. Good point. I would put it in the project. If you have just one person with different settings your git history will be a mess.
    Also you can add the setting and perform the task i one PR.



Reposts

  • GLPI
  • Kevin
  • Sebastian Schuh
  • dtacconi
  • Koya temitope
  • Marika Zimante
  • Gerardo Renterรญa
  • Saurav Dhyani ๐Ÿ‡ฎ๐Ÿ‡ณ
  • NavBitsBytes
  • Dmitry Katson
  • David Oyebode
  • Sergio Carbajo
  • Steve Endow
  • Guido Robben
  • Thomas Guldstrand
  • Brad
  • Alberto
  • Luรญs Costa
  • JAVIER ARMESTO GONZ.
  • Natalie Karolak - ๐‘ฉ๐‘ช ๐‘ซ๐’๐’„๐’” ๐‘ณ๐’Š๐’ƒ๐’“๐’‚๐’“๐’Š๐’‚๐’

Mentions

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: