Visual Studio Code extension 1.0.2: "Notification handler 'textDocument/didChange' failed — Cannot read properties of undefined (reading 'update')" on all openHAB files

First of all, thanks for 1.0.2 — hover on items inside .js files is exactly what I was missing, and it works nicely.

There is one side effect. Since installing 1.0.2 I get an error in the language server output channel every time I touch an openHAB configuration file. Adding a single space is enough to trigger it, and it repeats on every keystroke.

[Error - 9:27:41 AM] Notification handler 'textDocument/didOpen' failed with message: Cannot read properties of undefined (reading 'create')
[Error - 9:27:41 AM] Notification handler 'textDocument/didChange' failed with message: Cannot read properties of undefined (reading 'update')

Clearly tied to the version

  • 1.0.2 installed: the errors appear.
  • Back to 1.0.0: the errors are gone.

When it happens

  • On every openHAB file: .items, .things, .rules, .sitemap, .persist. didOpen fires once when the file is opened, didChange on every edit.
  • Not on .js files, which is the odd part given that JS support is what 1.0.2 adds.
  • Hover, validation and completion still appear to work, so this is noise rather than a broken feature — but the server’s document mirror is clearly not being updated, and I don’t know what silently depends on that.

Setup

  • openHAB 5.2.0 in Docker on Ubuntu, config on a shared folder
  • VS Code 1.140.0, openHAB extension 1.0.2
  • Remote language server enabled:
"openhab.useRestApi": true,
"openhab.connection.host": "192.168.100.52",
"openhab.connection.port": 8080,
"openhab.languageserver.remoteEnabled": true,
"openhab.languageserver.remotePort": 5007

Likely cause

The message is a JavaScript TypeError, so it comes from the JS side rather than from the Xtext server. Both messages match the signature of a TextDocuments instance created without the document factory. Since vscode-languageserver 6, the constructor requires it; without it the internal configuration is undefined, and didOpen fails on .create() while didChange fails on .update() — exactly the pair above.

// fails on didOpen/didChange with vscode-languageserver >= 6
const documents = new TextDocuments();

// expected
const { TextDocument } = require('vscode-languageserver-textdocument');
const documents = new TextDocuments(TextDocument);

Would you be able to look at this? I’d rather stay on 1.0.2 for the JS hover, so I’m happy to supply a verbose trace or test a patched build.

You should mention in the header you are talking about the Visual Studio Code extension to get better attraction. :innocent: