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

[BUG] Guest build.rs logs output to stdout overwrites tty display using Helix editor with Rust analyzer LSP #1685

Open
nuke-web3 opened this issue Apr 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@nuke-web3
Copy link
Member

Bug Report

When using rust-analyzer as the LSP with Helix as terminal-based editor, risc0 guest crate build output will be displayed overriding the display of the code loaded in the editor. See a screen recording here: helix-editor/helix#10038

I assumed this was an issue with the editor only at first (and it should not allow this to happen IMHO) but this would not be an issue if risc0 didn't write out to the stdout/err buffer in such a way that causes this. Note that no other crates I have used with helix have had such an issue for me, but all risc0 ones with methods/build.rs do.

Steps to Reproduce

  1. Setup helix with rust analyzer
  2. Open any risc0 project (includes the standard methods/build.rs tooling that writes logs to some buffer)
  3. Text overriding display of editor

Expected behavior

No output should be displayed on the editor with the LSP running in a background task.
I would propose that the build tooling is modified to direct to stderr or other buffer that should avoid this 🤞

Your Environment

  • risc0-zkvm version: 0.2 and above
  • Rust version: 1.75 and above
  • Platform/OS: Linux

Additional context

I have not pushed to get the Helix side of things patched to mitigate this, but I would think other editors like nvim might have the same issue too...?

@nuke-web3 nuke-web3 added the bug Something isn't working label Apr 18, 2024
Copy link

linear bot commented Apr 18, 2024

@nuke-web3

This comment was marked as outdated.

@nuke-web3 nuke-web3 changed the title [BUG] Guest build.rs logs output overwrites Helix editor via Rust analyzer [BUG] Guest build.rs logs output to stdout overwrites the editor display using Helix editor with Rust analyzer LSP Apr 18, 2024
@nuke-web3
Copy link
Member Author

nuke-web3 commented Apr 18, 2024

Ah I think I found the culprit:

// HACK: Attempt to bypass the parent cargo output capture and
// send directly to the tty, if available. This way we get
// progress messages from the inner cargo so the user doesn't
// think it's just hanging.
let tty_file = env::var("RISC0_GUEST_LOGFILE").unwrap_or_else(|_| "/dev/tty".to_string());

for line in BufReader::new(stderr).lines() {
match &mut tty {
Some(tty) => writeln!(tty, "{}: {}", pkg.name, line.unwrap()).unwrap(),
None => eprintln!("{}", line.unwrap()),
}
}

So I would expect all tty based editors to have this issue, would you agree?

Thus we need some way to detect the process is run by the LSP and not write to the tty I think, not 100% sure how best to do that while preserving the behavior you want... Open to implement based on a suggestion from the team here 😀

@nuke-web3 nuke-web3 changed the title [BUG] Guest build.rs logs output to stdout overwrites the editor display using Helix editor with Rust analyzer LSP [BUG] Guest build.rs logs output to stdout overwrites tty display using Helix editor with Rust analyzer LSP Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant