bug: Sending `TextDocument` objects to the Language Server fails in the Web IDE
Checklist
-
I'm using the latest version of the extension (see the latest version in the right column of this page) - Extension version: Put your extension version here
-
I'm using the latest VS Code version (find the latest version here) - VS Code version: The Web IDE is based on VSCode v1.89.1.
-
I'm using a supported version of GitLab (see README for the supported version) - GitLab version: Put your GitLab version here, or say "happens on
gitlab.com
"
- GitLab version: Put your GitLab version here, or say "happens on
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
- Go to https://gitlab.com/-/ide/project/gitlab-org/gitlab/edit/master/-/
- 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. - Open a source file in the project.
- As soon as you open the file, you will see the error reported in the bug.
What is the current bug behavior?
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