Skip to content

Commit

Permalink
update tokio and replace custom implementation of tokio::io::join
Browse files Browse the repository at this point in the history
  • Loading branch information
pr2502 committed May 16, 2024
1 parent 0e828ee commit e7cd609
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 72 deletions.
122 changes: 97 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ anyhow = "1.0.53"
clap = { version = "4.3.0", features = ["derive", "env"] }
directories = "4.0.1"
percent-encoding = "2.3.1"
pin-project-lite = "0.2.13"
serde = { version = "1.0.186" }
serde_derive = { version = "1.0.186" }
serde_json = "1.0.78"
time = "0.3.30"
tokio = { version = "1.15.0", features = ["fs", "io-std", "io-util", "macros", "net", "parking_lot", "process", "rt-multi-thread", "sync", "time"] }
tokio = { version = "1.37.0", features = ["fs", "io-std", "io-util", "macros", "net", "parking_lot", "process", "rt-multi-thread", "sync", "time"] }
toml = "0.5.8"
tracing = "0.1.39"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
Expand Down
47 changes: 2 additions & 45 deletions src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::collections::BTreeMap;
use std::env;
use std::pin::Pin;
use std::task::{Context, Poll};

use anyhow::{bail, Context as _, Result};
use pin_project_lite::pin_project;
use tokio::io::{self, AsyncRead, AsyncWrite, BufStream};
use tokio::io::{self, BufStream};
use tokio::net::TcpStream;

use crate::config::Config;
Expand All @@ -14,46 +11,6 @@ use crate::lsp::jsonrpc::Message;
use crate::lsp::transport::{LspReader, LspWriter};
use crate::lsp::{InitializationOptions, InitializeParams};

pin_project! {
struct Stdio {
#[pin]
stdin: io::Stdin,
#[pin]
stdout: io::Stdout,
}
}

fn stdio() -> Stdio {
Stdio {
stdin: io::stdin(),
stdout: io::stdout(),
}
}

impl AsyncRead for Stdio {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut io::ReadBuf,
) -> Poll<io::Result<()>> {
self.project().stdin.poll_read(cx, buf)
}
}

impl AsyncWrite for Stdio {
fn poll_write(self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll<io::Result<usize>> {
self.project().stdout.poll_write(cx, buf)
}

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
self.project().stdout.poll_flush(cx)
}

fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
self.project().stdout.poll_shutdown(cx)
}
}

pub async fn run(config: &Config, server: String, args: Vec<String>) -> Result<()> {
let cwd = env::current_dir()
.ok()
Expand All @@ -69,7 +26,7 @@ pub async fn run(config: &Config, server: String, args: Vec<String>) -> Result<(
let mut stream = TcpStream::connect(config.connect)
.await
.context("connect")?;
let mut stdio = BufStream::new(stdio());
let mut stdio = BufStream::new(io::join(io::stdin(), io::stdout()));

// Wait for the client to send `initialize` request.
let mut reader = LspReader::new(&mut stdio, "client");
Expand Down

0 comments on commit e7cd609

Please sign in to comment.