VSCode Profiles - Arduino Flavored
Tags: vscode, productivity, arduino, cpp
Published: 2020-11-07 02:47:25

> ⚠ Outdated: now VSCode support [profiles](https://code.visualstudio.com/docs/editor/profiles)

VSCode without a doubt it's an amazing tool, but for me, is missing an important setting to enable/disable extensions depending on language or workspace.

Almost me, jump all day between projects in different languages and I have a lot of extensions and settings that are useless in each scenario consuming resources. You can disable it manually on each project, but if you create a new one, you gonna need to make it all again. That's a waste of time.

While the VSCode team solves that, we can use a little workaround, creating our dedicated profile for **Arduino** development.

It's not perfect, because you can share those extensions that you use in multiples scenarios. But I prefer missing a little space on the disk in favor of fast settings configurations.

# Create Profile

We are going to create a new profile folder for extensions and data using `--extensions-dir` and `--user-data-dir` parameters.

| OS | Command |
|---|---|
|mac|`code --extensions-dir "$HOME/.vscode/profiles/arduino/extensions" --user-data-dir "$HOME/.vscode/profiles/arduino/data"`|
|linux|`code --extensions-dir "$HOME/.vscode/profiles/arduino/extensions" --user-data-dir "$HOME/.vscode/profiles/arduino/data"`|
|win|`code --extensions-dir "%HOMEPATH%/.vscode/profiles/arduino/extensions" --user-data-dir "%HOMEPATH%/.vscode/profiles/arduino/data"`| 

>⚠️ WSL2 does not support `--extensions-dir` or `--user-data-dir` flags

# How to use?

Are you crazy? We need to write and memorize this long command each time we want to work with Arduino?. 

No, of course not.

## On macOS/Linux

On this path `$HOME/.vscode/profiles/arduino/` [download](https://raw.githubusercontent.com/equiman/vscode-flavors/master/icons/icon-arduino.png) this image:

![icon-mac](https://dev-to-uploads.s3.amazonaws.com/i/js6wt7fhca4nulg8eluo.png)

### Dock Launcher

On same path, create a file called `code-arduino.command` with this code inside:

```bash
open -n -a "Visual Studio Code.app" --args --extensions-dir="$HOME/.vscode/profiles/arduino/extensions" --user-data-dir="$HOME/.vscode/profiles/arduino/data"
```

Save it and execute permission with `chmod +x code-arduino.command`.

Copy the `icon-arduino.png` content on the Clipboard. One way to do this is to open the picture in Preview, choose `Edit > Select All`, then choose `Edit > Copy` or press `Command-C`.

Select `code-arduino.command` file, then choose `File > Get Info`. At the top of the Info window, click the picture of the icon to select it, then choose `Edit > Paste` or press `Command-V`.

Select `code-arduino.command` file, then choose `File > Make Alias` or press `Command-L` name it as **VSCode Arduino** (with blank space between). Just drag and drop this alias shortcut to your Dock or Desktop.

![dock-macos](https://dev-to-uploads.s3.amazonaws.com/i/r2k7s25xrt8smpro7i3s.png)

> Recommended configurations: Open a terminal window, go to 'Preference > Profiles. Set Auto close terminal on exit: inside 'Shell' tab, select "Close if the shell exited cleanly" on "When the shell exits" option.

### Alias

An alias can be our best friend in those cases. Open your `.zshrc` or `.bash_profile` and paste this.

```bash
alias code-arduino="code --extensions-dir \"$HOME/.vscode/profiles/arduino/extensions\" --user-data-dir \"$HOME/.vscode/profiles/arduino/data\""
```

Save your file and restart your terminal window. Now you can open a folder project in VSCode with `code .` command, but now, if you going to work with Arduino use `code-arduino .` instead.

## On Windows

On this path `%HOMEPATH%/.vscode/profiles/arduino/extensions` [download](https://raw.githubusercontent.com/equiman/vscode-flavors/master/icons/icon-arduino.ico) this icon:

![icon-win](https://dev-to-uploads.s3.amazonaws.com/i/js6wt7fhca4nulg8eluo.png)

### Shortcut

On the same path, create a shortcut file and set with these properties:

Named as: `VSCode Arduino`

Set target as:

```bash
"C:\Users\%USERNAME%\AppData\Local\Programs\Microsoft VS Code\Code.exe" --extensions-dir "%HOMEPATH%/.vscode/profiles/arduino/extensions" --user-data-dir "%HOMEPATH%/.vscode/profiles/arduino/data"
```

Start In as :

```bash
"C:\Users\%USERNAME%\AppData\Local\Programs\Microsoft VS Code"
```

And use the icon downloaded previously.

> Sadly on Windows create an alias it slightly more complicated than macOS/Linux, then you only can open it using the shortcut and can't open it directly from the project path. But if you are using WSL you can use the same alias approach from mac/linux.

---

# Colors

It will be good to recognize when are using your VSCode and your Arduino flavored VSCode version.

```json
{
    "workbench.colorCustomizations": {
        "activityBar.background": "#009B9A",
        "activityBar.foreground": "#ffffff",
        "activityBar.inactiveForeground": "#ffffff99",
        "activityBarBadge.background": "#ffffff",
        "activityBarBadge.foreground": "#000000",
        "statusBar.noFolderBackground": "#00716F",
        "statusBar.background": "#009B9A",
        "statusBar.foreground": "#eedcdc",
        "statusBarItem.hoverBackground": "#00716F"
    },
}
```
<figcaption>settings.json</figcaption>

![vscode-arduino](https://dev-to-uploads.s3.amazonaws.com/i/6utcjep3i6935bi8cgug.png)

---

That's all. Now it's up to you what settings and extensions do you want to install. Those are my favorite recommendations.


# Extensions

## Prerequisites

As a prerequisite, you need to have installed **The Arduino IDE** that can be [download](https://www.arduino.cc/en/main/software#download) from the official site or just can be installed with a package manager.

| OS | Manager | Command |
|---|---|---|
|win|[Chocholatey](https://chocolatey.org/)|`choco install arduino`|
|mac|[Brew](https://brew.sh/)|`brew cask install arduino`|

Hope in a near future can be used only with `arduino-cli` instead of the complete IDE.

## Editor

- [Arduino](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino)

- [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)

## Snippets

- [arduino-snippets](https://marketplace.visualstudio.com/items?itemName=ronaldosena.arduino-snippets)

---

# Auto Formating

It's recommended to make these configurations on **project settings** and not in the global settings.

```json
{
    "editor.formatOnSave": true
}
```
<figcaption>settings.json</figcaption>

# Intellisense

Before using the command `Arduino: Initialize` need to fix some reference configurations. Adding those values.

## On Windows

```json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                ...
                "C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\**",
                "${workspaceFolder}"
            ],
            ...,
            "defines": ["USBCON"]
        }
    ],
}
```
<figcaption>c_cpp_properties.json</figcaption>

## On macOS

```json
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                ...
                "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/**",
                "${workspaceFolder}"
            ],
            ...,
            "defines": ["USBCON"]
        }
    ],
}
```
<figcaption>c_cpp_properties.json</figcaption>

## On Linux

```json
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                ...
                "/<user_path>/arduino-#.#.#/hardware/tools/avr/**",
                "${workspaceFolder}"
            ],
            ...,
            "defines": ["USBCON"]
        }
    ],
}
```
<figcaption>c_cpp_properties.json</figcaption>

Change `/<user_path>/arduino-#.#.#/` with your Arduino installation path.

---

# Sync

I'm not a big fan of the built-in VSCode Sync option because you can use more than one GitHub user account and also you can't create profiles.

But don't worry, we can use the well known [Setting Sync](https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync) extension.

Please [create another GitHub account](https://github.com/join), adding `-arduino` to your username and `+arduino` to your Gmail account.

![github-user](https://dev-to-uploads.s3.amazonaws.com/i/2eahc85oo99xeqy2ikp5.png)

With this trick, you can have another GitHub account without creating a new email account. Just use your new `username-arduino` account and voilà, your Arduino flavored VSCode version can be sync across multiple devices.

---

**That’s All Folks!**
**Happy Coding** 🖖

[![beer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mkgsx4aw6qn9i9ax6as9.png)](https://github.com/sponsors/deinsoftware)