How to run ROOT Macros in VS Code

Visual Studio Code offers some great functionalities when it comes to coding, such as IntelliSense, debugging, built-in Git, and many more through extensions. In this blog post I’m going to show how to configure VS Code in order to use all of these awesome features when creating and editing ROOT Macros!

This is a companion discussion topic for the original entry at

Thank Alberto! It do work and will bring great convenience for using root.

1 Like

oh! It is so convenience to view root files!

1 Like

Thank Alberto! it works on my computer, and that’s really convenient.
the “args” list at launch.json need be changed when I want to run new Root Macro, I am wonder whether Is there a way to automatically run the Macro which opened by VS code.

1 Like

you can change hsimple.C in args to ${file}

1 Like

Is there anyway to change the behaviour of the F5/run button, ideally, I’d want to disable GDB attaching or change how it operates. I’ve been trying to figure this out and it doesn’t seem as simple as using the run without debugging option, which keeps trying to attach GDB anyway.

Originally I’d said the snap package of ROOT wouldn’t really work with IDE’s generally. This is mostly due to the non standard include paths and the complications of trying to work in the container vs out of it, but following this blog, VSCode can be made to get 99% of the way there, with intellisense support, but I can’t get F5 to work because GDB needs to be handled specially for snaps.

Perhaps I’m being blind to something obvious, but otherwise this does fill a huge problem with the snap package so I’d be really keen to have suggestions.

Hey many thanks for the post.
I did it like you described but I don’t have IntelliSense autocompletion or something for everything coming with root (plain C is working). Do anyone have an idea how to solve this?
I am using VS Code 1.57.1 and root 6.24.00. Did something change in the meantime?

Many thanks for any help! :slight_smile:

Does this method also work in MacOS, typically M1 silicon?

Let me invite @AlbertoPdRF over, he might not even be aware of what’s happening here :slight_smile:

Thanks Alberto, it works!

I’m new to ROOT and I’ve also started to coding in C++ very recently, so forgive me if this question sounds trivial.
In my case, VScode shows 12 problems detected because it cannot open the source files included in the script:

Does anyone know how to fix this?

If anyone has the same problem, I found a nice solution at this link:

Best regards.