Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Avoid printing to stdout from Client or Ruby activation #868

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

vinistock
Copy link
Member

Motivation

This may be the solution for Shopify/ruby-lsp#1723.

I suspect the issue is that RVM is somehow causing something to be printed to STDOUT, which is basically left in the pipe until the LSP starts. When it finally does start, it reads STDOUT and gets the stuff that was printed, which is invalid from the LSP's perspective.

I'm not 100% sure this is the fix, but in general we should simply never use STDOUT or STDIN for anything when it comes to the client, because it may mess up the client-server communication.

Implementation

I switched all places in Client and Ruby where we were using STDOUT to get versions or perform activation. We now rely only on STDERR, which in LSPs is only used for printing and not for communication.

@vinistock vinistock added the bugfix This PR will fix an existing bug label Nov 1, 2023
@vinistock vinistock self-assigned this Nov 1, 2023
@vinistock vinistock requested a review from a team as a code owner November 1, 2023 16:56
@andyw8
Copy link
Contributor

andyw8 commented Nov 1, 2023

Might another approach be to 'flush' stdout before starting ruby-lsp?

@vinistock
Copy link
Member Author

I'm not sure how we'd go about doing that. It's the LSP package that owns the pipes, we don't have access to them.

@vinistock vinistock force-pushed the vs/avoid_printing_to_stdout branch from 7c484b8 to e197571 Compare November 2, 2023 14:48
@vinistock vinistock merged commit 16494c4 into main Nov 2, 2023
4 checks passed
@vinistock vinistock deleted the vs/avoid_printing_to_stdout branch November 2, 2023 17:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix This PR will fix an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants