Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite global console to output to the language server connection console #41

Closed
4 tasks done
remcohaszing opened this issue Mar 30, 2022 · 6 comments
Closed
4 tasks done
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@remcohaszing
Copy link
Member

Initial checklist

Problem

If the server uses the stdio protocol for communication, stdout is used for communication. However, console.log() etc statements also write to stdout. This causes the following error:

node_modules/vscode-jsonrpc/lib/common/messageReader.js:138
                    throw new Error('Header must provide a Content-Length property.');
                    ^

Error: Header must provide a Content-Length property.
    at StreamMessageReader.onData (node_modules/vscode-jsonrpc/lib/common/messageReader.js:138:27)
    at Socket.<anonymous> (node_modules/vscode-jsonrpc/lib/common/messageReader.js:122:18)
    at Socket.emit (node:events:520:28)

The language server simply shouldn’t use console.log(), but third party plugins or other third party packages might do so.

Solution

The language server can rewrite the global console, so its calls are rerouted to connection.console.

Alternatives

The output could be disabled entirely.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Mar 30, 2022
@wooorm
Copy link
Member

wooorm commented Mar 30, 2022

Could this be an upstream fix?

@remcohaszing
Copy link
Member Author

remcohaszing commented Aug 22, 2023

I created upstream issue microsoft/vscode-languageserver-node#1299. Also a pull request microsoft/vscode-languageserver-node#1301.

@remcohaszing
Copy link
Member Author

This has been solved upstream. It’s a matter of waiting for a new release now.

@remcohaszing remcohaszing closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2023
@github-actions

This comment has been minimized.

@remcohaszing remcohaszing added the 👀 no/external This makes more sense somewhere else label Sep 18, 2023
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Sep 18, 2023
@wooorm
Copy link
Member

wooorm commented Sep 18, 2023

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants