summaryrefslogtreecommitdiffstats
path: root/vendor/lsp-server/src/stdio.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/lsp-server/src/stdio.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/lsp-server/src/stdio.rs')
-rw-r--r--vendor/lsp-server/src/stdio.rs71
1 files changed, 0 insertions, 71 deletions
diff --git a/vendor/lsp-server/src/stdio.rs b/vendor/lsp-server/src/stdio.rs
deleted file mode 100644
index e487b9b46..000000000
--- a/vendor/lsp-server/src/stdio.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-use std::{
- io::{self, stdin, stdout},
- thread,
-};
-
-use log::debug;
-
-use crossbeam_channel::{bounded, Receiver, Sender};
-
-use crate::Message;
-
-/// Creates an LSP connection via stdio.
-pub(crate) fn stdio_transport() -> (Sender<Message>, Receiver<Message>, IoThreads) {
- let (writer_sender, writer_receiver) = bounded::<Message>(0);
- let writer = thread::spawn(move || {
- let stdout = stdout();
- let mut stdout = stdout.lock();
- writer_receiver.into_iter().try_for_each(|it| it.write(&mut stdout))?;
- Ok(())
- });
- let (reader_sender, reader_receiver) = bounded::<Message>(0);
- let reader = thread::spawn(move || {
- let stdin = stdin();
- let mut stdin = stdin.lock();
- while let Some(msg) = Message::read(&mut stdin)? {
- let is_exit = matches!(&msg, Message::Notification(n) if n.is_exit());
-
- debug!("sending message {:#?}", msg);
- reader_sender.send(msg).expect("receiver was dropped, failed to send a message");
-
- if is_exit {
- break;
- }
- }
- Ok(())
- });
- let threads = IoThreads { reader, writer };
- (writer_sender, reader_receiver, threads)
-}
-
-// Creates an IoThreads
-pub(crate) fn make_io_threads(
- reader: thread::JoinHandle<io::Result<()>>,
- writer: thread::JoinHandle<io::Result<()>>,
-) -> IoThreads {
- IoThreads { reader, writer }
-}
-
-pub struct IoThreads {
- reader: thread::JoinHandle<io::Result<()>>,
- writer: thread::JoinHandle<io::Result<()>>,
-}
-
-impl IoThreads {
- pub fn join(self) -> io::Result<()> {
- match self.reader.join() {
- Ok(r) => r?,
- Err(err) => {
- println!("reader panicked!");
- std::panic::panic_any(err)
- }
- }
- match self.writer.join() {
- Ok(r) => r,
- Err(err) => {
- println!("writer panicked!");
- std::panic::panic_any(err);
- }
- }
- }
-}