VSCode Guide

@Mark_Webster - you’ll be the first osx user so we may need to do some changes. Could you change that line to ${env:openhab_home}/start.sh and see if it works. Note this assumes you have set the openhab_home variable at the top of the file to “/Applications/openhab”

Hi

Sorry for not replying, I’ve been overseas for the last few days…

I’ve tried that and no luck… It now seems to ignore that text completely and comes back with…

/bin/bash: /start.sh: No such file or directory

Running on Linux (using VS Code Remote-SSH) doesn’t seem to resolve the path variables.
In tasks.json:

{
  ...
        "env": {
            "openhab_home": "/opt/oh25-test",
            "openhab_runtime": "/opt/oh25-test/runtime",
            "openhab_addons": "/opt/oh25-test/addons",
            "openhab_logs": "/opt/oh25-test/userdata/logs",
            "dist" : "org.openhab.binding.philipsairpurifier-2.5.0-SNAPSHOT.jar"
        }
    },
    "tasks": [
        {
            "label": "Start openHAB (Debug)",
            "type": "shell",
            "isBackground": true,
            "command": "$env:openhab_home/start_debug.sh",
  ...

Results in an error:

/bin/bash: :openhab_home/start_debug.sh: No such file or directory

When replacing the variable in the task entry with the absolute path, OH starts fine.

EDIT: Should I file an issue?

Maybe you can do a bit of research and help to find the correct variable that works within VScode? That’d be sweet.

Will do ;o)
UPDATE: Done.

After reading through this VS Code issue, I concluded that:

    "command": "$openhab_home/start_debug.sh",

should work. And guess what? It works. :grinning:
At least for my setup with VS Code remoting to a Linux host where OH is running and the binding files are stored (and Maven is run). So, my tasks.json now looks like this:

{
    "version": "2.0.0",
    "options": {
        "env": {
            "openhab_home": "/opt/oh25-test",
            "openhab_runtime": "/opt/oh25-test/runtime",
            "openhab_addons": "/opt/oh25-test/addons",
            "openhab_logs": "/opt/oh25-test/userdata/logs",
            "dist" : "org.openhab.binding.philipsairpurifier-2.5.0-SNAPSHOT.jar"
        }
    },
    "tasks": [
        {
            "label": "Start openHAB (Debug)",
            "type": "shell",
            "isBackground": true,
            "command": "$openhab_home/start_debug.sh",
            "windows": {
                "command": "& $env:openhab_home/start.bat debug"
            },
            "presentation": {
                "reveal": "always",
                "panel": "new"
            },
            "problemMatcher": []
        },
        {
            "label": "Stop openHAB",
            "type": "shell",
            "command": "$openhab_home/stop.sh",
            "windows": {
                "command": "& $env:openhab_runtime/bin/stop.bat"
            },
            "problemMatcher": []
        },
        {
            "label": "mvn Compile (Release)",
            "type": "shell",
            "command": "mvn",
            "args": [
                "clean",
                "install"
            ]
        },
        {
            "label": "mvn Compile (Online)",
            "type": "shell",
            "command": "mvn",
            "args": [
                "clean",
                "install",
                "-DskipChecks"
            ]
        },
        {
            "label": "mvn Compile (Offline)",
            "type": "shell",
            "command": "mvn",
            "args": [
                "-o",
                "clean",
                "install",
                "-DskipChecks"
            ]
        },
        {
            "label": "Copy Distribution to Addons",
            "type": "shell",
            "command": "cp",
            "windows": {
                "command": "copy"
            },
            "args": [
                "${workspaceFolder}/target/$env:dist",
                "/opt/oh25-test/addons"
            ],
            "dependsOn": [
                "mvn Compile (Offline)"
            ]
        },
        {
            "label": "Build",
            "dependsOn": [
                "Copy Distribution to Addons"
            ]
        },
        {
            "label": "Tail events.log",
            "type": "shell",
            "command": "tail",
            "args": [
                "-n",
                "50",
                "-f",
                "$openhab_logs/events.log"
            ],
            "windows": {
                "command": "Get-Content",
                "args": [
                    "-Last",
                    "50",
                    "-Path",
                    "$openhab_logs/events.log",
                    "-Wait"
                ]
            },
            "presentation": {
                "reveal": "always",
                "panel": "new"
            },
            "problemMatcher": []
        },
        {
            "label": "Tail openhab.log",
            "type": "shell",
            "command": "tail",
            "args": [
                "-n",
                "50",
                "-f",
                "$openhab_logs/openhab.log"
            ],
            "windows": {
                "command": "Get-Content",
                "args": [
                    "-Last",
                    "50",
                    "-Path",
                    "$env:openhab_logs/openhab.log",
                    "-Wait"
                ]
            },
            "presentation": {
                "reveal": "always",
                "panel": "new"
            },
           "problemMatcher": []
        }
    ]
}

Can anyone with another Linux setup (like running it completely local on Linux or ZSH shell) confirm this?

Great, that there is a VSCode specific thread, so I want to refer to another post of me showing an VS-Code specific problem: Beginners Guide to create an Addon without the Eclipse IDE for openHAB 2.4 and place it in your running openHAB runtime

Hate to say - that only works because the openHAB installer created that environment variable for you (I ran into that same thing when I was doing the windows side). The others (openhab_runtime, openhab_addons, openhab_logs) probably won’t work unless your environment defines those as well.

That’s why I tried the “options.env” approach (makes it independent of openhab installer and options you’ve chosen) - which works on windows but doesn’t on linux/osx based on this thread.

I’m going to spin up my linux environment and will see if I can find a solution for this…

EDIT: after reading through that thread - you may be right that it would work on linux/osx. Again - I’ll be testing shortly to find out

It works. :grin:
I run all my OH stuff in containers, except a manually installed instance, without any environment variables set, that I will use for debugging.
But I’m not sure about the behavior in other shells.

Yep - I can confirm that the $openhab... definitely work on linux environments. I’ll be making a change to the tasks.json shortly (I need to update the docs anyway for a markdown error). Hopefully the next version will run correctly for you all.

Here’s the PR if people want to try the new tasks.json (and I also included the code formatter setup)

1 Like

Hi

Can you explain how you get VS Code to access an openhab instance on a remote linux machine? This would be my preferred setup as I have a spare Raspberry Pi to run as a dev instance and will avoid having to have maven etc on my mac laptop.

Thanks

1 Like

Unfortunately it only works on x86 Linux with the current preview version, so you’ll have to be patient I guess. :slightly_smiling_face:

UPDATE: The new Insider version of July now includes support for Raspberry Pi.

Thanks - is that already part of the official set up Guide for VS Code?

Not yet - still waiting on the merge

Note: this was merged sometime over the weekend…

1 Like

Dear Community,

I try to fire up the VS Code debug task. Unfortuntely it is not possible find the corresponding task. I followed the VS Code guide here https://www.openhab.org/docs/developer/ide/vscode.html

Anyway I prepared the tasks- and launch-file in my binding .vscode folder. After hitting ctrl+shift+p and selecting Run task … I cannot pick any openHAB related task to choose from.

Thanks in advance for your replies.

Best regards,
Jochen

It is solved! The problem where the slashes - I wasn’t expecting, that on a windows box unix related paths are necessary.

Dear Community,

these days I am starting to use VS Code more intensely. Maven is able to build my addon but lots of classes and includes are not visible, see

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

What is the most preferred way to add these modules to VS Code.

Best regards,
Jochen

UPDATE: It is solved. After a new start of VS Code the imports were recognized.

The Steps for each Bundle don’t work for me.

Steps to reproduce:

  • git clone https://github.com/openhab/openhab2-addons.git
  • cd bundles/org.openhab.binding.astro
  • mvn clean install -DskipTests -DskipChecks

I get loads of compile errors like QuantityType cannot be resolved to a type.
It seems that the imports cannot be resolved.

At the beginning there are warnings like:

The POM for org.openhab.core.bom:org.openhab.core.bom.compile:pom:2.5.0-20190717.100901-102 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

I’m not an expert in maven (in the least bit) but I’d clear out the .m2/.p2 directories (usually in your home directory) and try again.