VS Code code completion

Hello,

there are some old threads about code completion not working and I was wondering if this was still the case.

Yesterday I set up my VS Code with the openHAB extension so that I can see the Items and Things, and I can save rules via a Samba share. However the code completion is not working. Whenever I press Ctrl + Space, the log file in openHAB server’s /var/log/openhab/openhab.log says the following:

2023-07-29 08:49:44.101 [ERROR] [st.antlr.ContentAssistContextFactory] - java.lang.RuntimeException: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.NullPointerException
        at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:?]
        at java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.doCreateContexts(ContentAssistContextFactory.java:181) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.create(ContentAssistContextFactory.java:131) ~[?:?]
        at org.eclipse.xtext.ide.server.contentassist.ContentAssistService.createProposals(ContentAssistService.java:106) ~[?:?]
        at org.eclipse.xtext.ide.server.contentassist.ContentAssistService.createCompletionList(ContentAssistService.java:78) ~[?:?]
        at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$completion$23(LanguageServerImpl.java:580) ~[?:?]
        at org.eclipse.xtext.ide.server.WorkspaceManager.doRead(WorkspaceManager.java:458) ~[?:?]
        at org.eclipse.xtext.ide.server.LanguageServerImpl.completion(LanguageServerImpl.java:579) ~[?:?]
        at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$completion$22(LanguageServerImpl.java:565) ~[?:?]
        at org.eclipse.xtext.ide.server.concurrent.ReadRequest.lambda$doRun$0(ReadRequest.java:66) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:246) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:237) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:232) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:49) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:27) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:264) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.handleLastCompleteNodeAsPartOfDatatypeNode(ContentAssistContextFactory.java:264) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$1.call(ContentAssistContextFactory.java:149) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$1.call(ContentAssistContextFactory.java:146) ~[?:?]
        ... 4 more
Caused by: java.lang.NullPointerException
        at java.util.Objects.requireNonNull(Objects.java:209) ~[?:?]
        at java.lang.Class.getMethod(Class.java:2219) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:169) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:242) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:237) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:232) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:49) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:27) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:264) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.handleLastCompleteNodeAsPartOfDatatypeNode(ContentAssistContextFactory.java:264) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$1.call(ContentAssistContextFactory.java:149) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$1.call(ContentAssistContextFactory.java:146) ~[?:?]
        ... 4 more
2023-07-29 08:49:44.103 [ERROR] [st.antlr.ContentAssistContextFactory] - java.lang.RuntimeException: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.NullPointerException
        at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:?]
        at java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.doCreateContexts(ContentAssistContextFactory.java:181) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.create(ContentAssistContextFactory.java:131) ~[?:?]
        at org.eclipse.xtext.ide.server.contentassist.ContentAssistService.createProposals(ContentAssistService.java:106) ~[?:?]
        at org.eclipse.xtext.ide.server.contentassist.ContentAssistService.createCompletionList(ContentAssistService.java:78) ~[?:?]
        at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$completion$23(LanguageServerImpl.java:580) ~[?:?]
        at org.eclipse.xtext.ide.server.WorkspaceManager.doRead(WorkspaceManager.java:458) ~[?:?]
        at org.eclipse.xtext.ide.server.LanguageServerImpl.completion(LanguageServerImpl.java:579) ~[?:?]
        at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$completion$22(LanguageServerImpl.java:565) ~[?:?]
        at org.eclipse.xtext.ide.server.concurrent.ReadRequest.lambda$doRun$0(ReadRequest.java:66) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:246) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:237) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:232) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:49) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:27) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:264) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.createContextsForLastCompleteNode(ContentAssistContextFactory.java:299) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.handleLastCompleteNodeIsPartOfLookahead(ContentAssistContextFactory.java:220) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$3.call(ContentAssistContextFactory.java:172) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$3.call(ContentAssistContextFactory.java:169) ~[?:?]
        ... 4 more
Caused by: java.lang.NullPointerException
        at java.util.Objects.requireNonNull(Objects.java:209) ~[?:?]
        at java.lang.Class.getMethod(Class.java:2219) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:169) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:242) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:237) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:232) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:49) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:27) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.BaseContentAssistParser.getFollowElements(BaseContentAssistParser.java:264) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.createContextsForLastCompleteNode(ContentAssistContextFactory.java:299) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.handleLastCompleteNodeIsPartOfLookahead(ContentAssistContextFactory.java:220) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$3.call(ContentAssistContextFactory.java:172) ~[?:?]
        at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$3.call(ContentAssistContextFactory.java:169) ~[?:?]
        ... 4 more

I was using the openHAB 3.4, but because this was not working, I upgraded it to 4.0.0. Unfortunately there was no improvement.

Any ideas? Thanks!

Nothing has changed. The issue is with the VS Code extension, so updating the server won’t do anything.

OK, thanks for the info!

I see the same problem after fresh install for version 4.1
Are there any hints what to do?

Not a solution, since I don’t use code completion. Just a suggestion, instead of using samba share, use vscode over SSH. It’s so much better working through remote vscode than over samba.

Hey guys,

I have these NullPointerExceptions too with the ContentAssistContextFactory.

I use OH 4.3.3 - clean install.

Everytime when I edit a rule with Visual Code and I am beginning to type some item-names.
The autocomplete-list doesn’t contain any item names and the OH-log is full of NullPointerExceptions.

The OH-Extension in VSCode seems to work…but still there errors.

Can somebody help?

Ralph

Hi, these NullPointerException errors are related to the VSC plugin, not the openHab version. There are various posts in this forum about the issue.
The only way to get rid of these extremely lengthy and annoying error messages is to install a logging filter. In theory, it should be possible to have a regex filter that triggers on the message content. In practice, I could not figure out a working regex, even though the online regex testers did show a full match.
What has finally worked is to add a logger that disables logging for org.eclipse.xtext.ide.editor. I did not see this error again thereafter. A more specific logger path may be possible, but I am not sure about the correct full path as the logger name is truncated in openhab.log. (If someone has a better one please speak up).
So what I did is editing log4j2.xml and adding the following logger to the logger list at the end of the file (note this will disable any logging related to any xtext ide editor):

        <!-- Filters known issues of ContentAssistContextFactory -->
        <!-- Content assist when editing config files in VSC -->
        <Logger level="OFF" name="org.eclipse.xtext.ide.editor"/>

For openhabian-based installations, this file should be in /var/lib/openhab/etc.
Adding the same logger via the openhab console should also be possible, but may not survive openhab upgrades. In any case, this file should probably be checked after an upgrade to see if the change is still there.
For future openHab versions, it might make sense to add this or something similar to the file in the distribution, similar to other entries that already exist.

1 Like