[SOLVED] VS Code not resolving item in rules

I’m running OH 2.5 release (openhabian) on an RPi4. I mount a samba share on my Mac and use VS Code to edit the files. I’ve consolidating some of my items to different files and have run into a problem where an item name is not being resolved. VSC highlights the item in the new file and when I hover over it, the message says “The method name or field Garage_Light_Switch is undefined”. If I copy that item definition back to the original file, the item is resolves and is not highlighted. Here is the item definition:

Switch Garage_Light_Switch "Garage light" <light> (gOutsideLights) {mqtt="<[openHabBroker:outside/zgarage_on:command:ON],<[openHabBroker:outside/zgarage_off:command:OFF]"}

The switch works when placed in the new file, but the sitemap only display the item name listed in the items definition in the sitemap, and a generic switch icon:

Switch item=Garage_Light_Switch

I’ve uninstalled and reinstalled the openhab extension from VSC. Closed VSC and unmounted/mounted the volume and opened VSC again, with a OH service restart before re-mounting and launching VSC again. I’m at a loss, does anyone have any ideas what the issue is?
I’ve seen one relevant post via Google, which referred to an UNC on a Windows box. The solution there was to assign the UNC share to a drive letter. Not sure what to do here.

When you edit/save these files, you should see messages in your openhab.log along the lines of Loading model 'xxx.rules'

Loading model 'outside.items'
Refreshing model 'outside.items'

Ok, just call it a Christmas miracle. I was making more changes to that and other files and finally, it started resolving the items. I wish I had a better answer for others who may run into this issue.

I am not sure if it fits to the whole problem here,
but i would like to give some additional information about how the hover display works:

The vscode extension will fetch all available items of your openHAB environment once on vscode startup.
So it won’t have informations about newly created items until you restart vscode, which will lead to a item lookup again.

So it is totally possible and fine that an item is shown as undefined in vscode, when it has been defined just a short time ago until the next start of vscode.

This is a known problem and i hav already opened a reminder issue for me.
In future i would like to fetch the available items again when an items file is saved.
This should then prevent users from confusion with this.

1 Like

In this case, OP also complained about sitemap display i.e. outside of VSCode.

I would imagine OH got a bit confused about duplicate Items when copied from one file to another, my next suggestion would have been an OH reboot after edits completed.

Yep. But I got the impression there was some additional confusion because of the misleading hover.
So I wanted to clarify this, for a better experience while searching for a problems source. :slight_smile:

1 Like

If its a bug, I can live with it until its fixed. The target item, a bulb works as expected, but yes, it is a bit disconcerting.

Just a small update.

the problem of “undefined” items in a hover will be fixed. :slight_smile:



I have today the same problem. I didn’t change anything in my rules and items files but all items are reported as undefined.
“owner”: “generated_diagnostic_collection_name#0”,
“code”: “org.eclipse.xtext.diagnostics.Diagnostic.Linking”
“severity”: 8,
“message”: “The method or field HuidigKeukenRadioVolume is undefined”,
I restarted everything but can’t solve it. Any idea?

Probably the LSP server in your environment does not know the item.
The Message is not coming from the openHAB extension directly.

You could try to restart the language server bundle in your openHAB installation via console.