VSC - Multiple OH Environments

Hi All

I’ve just setup a new Linux server which I’m now running as my “production” environment and my existing RPi setup will become my “development” environment.

My next step is to start the configuration which has led me back into VSCode, however, is there a way to have multiple OH environments in the VSCode openHAB extension? I’ve had a look but can’t see a way, but some of you with more VSC experience maybe able to point me in the right directions.

TIA

OS: Windows 10
VSC: V1.49.2
OH Extension: 0.7.0

Have you tried changing the address of you second server in VSCode/OH extension settings?

I can change the address in the settings and I’d be able to see the other server instead. What I’m questioning is whether it’s possible to have VSC configured so I can select the environment I’m working on at the time, without having to change the settings each time and then loose connection to my other environment.

I’m not in front of VSC right now, but I’m pretty sure it’s just a setting so you can put it in a settings file in the folder you’re working in instead of global settings. You can also define workspace settings if you’re using workspace files.

I use remote dev in VSC so when I connect to ssh it will install vscode server on the PI and run the extention on the pi.

Then you can have settings on each server and connect with differnet PC’s and have the same setup

1 Like

I’m not that familiar with VSC but I’m used to workspaces in Eclipse so I can see how that would work, still not a perfect solution but more than happy as a work around. I might see if it’s possible to put it in folder as well as that would be even better.

Yes, I keep my workspace files in the root folder they are dealing with. I have only recently started using them after having my dev machine die on me and installing VSC again and again between that and updating to Ubuntu 20 just prior. Now I don’t have to keep restoring my global VSC settings, they are just there in the workspace file which is in source control. Bonus of it being in source control is that for shared projects I can have some control over the IDE of contributors to enable things like linting and code formatting.

I have not worked on my openhab config since I started using workspaces, but here is an example of what I might setup:

{
    "folders": [
        {
            "path": "."
        }
    ],
    "settings": {
        "python.autoComplete.extraPaths": [
            "./automation/lib/python"
        ],
        "openhab.host": "OH_HOST",
        "openhab.port": 8080,
        "openhab.remoteLspPort": 5007,
        "python.formatting.provider": "black",
        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
        "files.trimTrailingWhitespace": true,
        "files.insertFinalNewline": true,
        "editor.renderWhitespace": "all",
        "editor.formatOnSave": true,
        "editor.rulers": [
            88
        ],
    }
}

If you don’t want black code formatting, remove python.formatting.provider and editor.formatOnSave.

Edit: of course it would be a better example if I included the relevant openhab settings…

1 Like