mirror of
https://github.com/helix-editor/helix.git
synced 2025-04-05 11:57:43 +03:00
dap: make transport IO-agnostic
This commit is contained in:
parent
e11b67b0db
commit
26a55dcefd
2 changed files with 272 additions and 273 deletions
|
@ -280,7 +280,7 @@ impl Client {
|
||||||
let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin"));
|
let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin"));
|
||||||
let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
|
let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
|
||||||
|
|
||||||
let (server_rx, server_tx) = Transport::start(reader, writer, id);
|
let (server_rx, server_tx) = Transport::start(Box::new(reader), Box::new(writer), id);
|
||||||
|
|
||||||
let client = Self {
|
let client = Self {
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -6,8 +6,7 @@ use serde_json::Value;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter},
|
io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt, AsyncWrite, AsyncWriteExt},
|
||||||
process::{ChildStdin, ChildStdout},
|
|
||||||
sync::{
|
sync::{
|
||||||
mpsc::{unbounded_channel, Sender, UnboundedReceiver, UnboundedSender},
|
mpsc::{unbounded_channel, Sender, UnboundedReceiver, UnboundedSender},
|
||||||
Mutex,
|
Mutex,
|
||||||
|
@ -65,8 +64,8 @@ pub struct Transport {
|
||||||
|
|
||||||
impl Transport {
|
impl Transport {
|
||||||
pub fn start(
|
pub fn start(
|
||||||
server_stdout: BufReader<ChildStdout>,
|
server_stdout: Box<dyn AsyncBufRead + Unpin + Send>,
|
||||||
server_stdin: BufWriter<ChildStdin>,
|
server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
|
||||||
id: usize,
|
id: usize,
|
||||||
) -> (UnboundedReceiver<Payload>, UnboundedSender<Request>) {
|
) -> (UnboundedReceiver<Payload>, UnboundedSender<Request>) {
|
||||||
let (client_tx, rx) = unbounded_channel();
|
let (client_tx, rx) = unbounded_channel();
|
||||||
|
@ -86,7 +85,7 @@ impl Transport {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn recv_server_message(
|
async fn recv_server_message(
|
||||||
reader: &mut (impl AsyncBufRead + Unpin + Send),
|
reader: &mut Box<dyn AsyncBufRead + Unpin + Send>,
|
||||||
buffer: &mut String,
|
buffer: &mut String,
|
||||||
) -> Result<Payload> {
|
) -> Result<Payload> {
|
||||||
let mut content_length = None;
|
let mut content_length = None;
|
||||||
|
@ -133,7 +132,7 @@ impl Transport {
|
||||||
|
|
||||||
async fn send_payload_to_server(
|
async fn send_payload_to_server(
|
||||||
&self,
|
&self,
|
||||||
server_stdin: &mut BufWriter<ChildStdin>,
|
server_stdin: &mut Box<dyn AsyncWrite + Unpin + Send>,
|
||||||
req: Request,
|
req: Request,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let json = serde_json::to_string(&req)?;
|
let json = serde_json::to_string(&req)?;
|
||||||
|
@ -145,7 +144,7 @@ impl Transport {
|
||||||
|
|
||||||
async fn send_string_to_server(
|
async fn send_string_to_server(
|
||||||
&self,
|
&self,
|
||||||
server_stdin: &mut BufWriter<ChildStdin>,
|
server_stdin: &mut Box<dyn AsyncWrite + Unpin + Send>,
|
||||||
request: String,
|
request: String,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
info!("-> DAP {}", request);
|
info!("-> DAP {}", request);
|
||||||
|
@ -237,7 +236,7 @@ impl Transport {
|
||||||
|
|
||||||
async fn recv(
|
async fn recv(
|
||||||
transport: Arc<Self>,
|
transport: Arc<Self>,
|
||||||
mut server_stdout: BufReader<ChildStdout>,
|
mut server_stdout: Box<dyn AsyncBufRead + Unpin + Send>,
|
||||||
client_tx: UnboundedSender<Payload>,
|
client_tx: UnboundedSender<Payload>,
|
||||||
) {
|
) {
|
||||||
let mut recv_buffer = String::new();
|
let mut recv_buffer = String::new();
|
||||||
|
@ -259,7 +258,7 @@ impl Transport {
|
||||||
|
|
||||||
async fn send(
|
async fn send(
|
||||||
transport: Arc<Self>,
|
transport: Arc<Self>,
|
||||||
mut server_stdin: BufWriter<ChildStdin>,
|
mut server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
|
||||||
mut client_rx: UnboundedReceiver<Request>,
|
mut client_rx: UnboundedReceiver<Request>,
|
||||||
) {
|
) {
|
||||||
while let Some(req) = client_rx.recv().await {
|
while let Some(req) = client_rx.recv().await {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue