Skip to content

bug: Sending `TextDocument` objects to the Language Server fails in the Web IDE

Checklist

Summary

When using the Language Server in the Web IDE, the following error occurs when I open a document:

main.js:2123 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Worker': save(){return n.r()} could not be cloned.
	at uS.write (http://localhost:8000/web-ide/public/vscode/extensions/gitlab-vscode-extension/browser.js#vscode-extension:56:17065)
	at Object.sendNotification (http://localhost:8000/web-ide/public/vscode/extensions/gitlab-vscode-extension/browser.js#vscode-extension:56:2000)
	at $D.sendNotification (http://localhost:8000/web-ide/public/vscode/extensions/gitlab-vscode-extension/browser.js#vscode-extension:155:106205)
	at async R.eval [as value] (http://localhost:8000/web-ide/public/vscode/extensions/gitlab-vscode-extension/browser.js#vscode-extension:303:11848)
workbench.web.main.js:748 Client GitLab Language Server: connection to server is erroring. Failed to execute 'postMessage' on 'Worker': save(){return n.r()} could not be cloned.

Investigation

In the Web Browser, the Language Server runs in a sandboxed environment implemented in a Web Worker. The Web Worker and the Web IDE communicate using the postMessage secure channel. postMessage serializes the objects that are sent through this channel. Functions aren't serializable and if an object with functions is passed to postMessage , the error above will occur.

In language_server_manager.ts, we are sending a vscode.TextDocument object to the language server. vscode.TextDocument contains functions therefore the underlying postMessage call fails. In the gitlab-lsp project side, we receive the document in supported_language_policy.ts.

Steps to reproduce

  1. Go to https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit/master/-/
  2. Open User Settings (just like in VSCode) and set the following setting: "gitlab.featureFlags.languageServerWebIDE": true . This setting will enable the Language Server in the Web IDE.
  3. Open a source file in the project.
  4. As soon as you open the file, you will see the error reported in the bug.

What is the current bug behavior?

Language Server error in the Web IDE

What is the expected correct behavior?

The Language Server works properly in the Web IDE

Relevant logs and/or screenshots

Possible fixes

Pass a serializable version of the TextDocument object to the RPC methods that communicate with the language server

Edited by Enrique Alcántara