Skip to content

Commit

Permalink
Fix unwrap bug in DAP (helix-editor#6786)
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Walrus authored and wes-adams committed Jul 3, 2023
1 parent b994404 commit 644f17f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
10 changes: 4 additions & 6 deletions helix-dap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ impl Client {
if command.is_empty() {
return Result::Err(Error::Other(anyhow!("Command not provided")));
}
if transport == "tcp" && port_arg.is_some() {
Self::tcp_process(command, args, port_arg.unwrap(), id).await
} else if transport == "stdio" {
Self::stdio(command, args, id)
} else {
Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport)))
match (transport, port_arg) {
("tcp", Some(port_arg)) => Self::tcp_process(command, args, port_arg, id).await,
("stdio", _) => Self::stdio(command, args, id),
_ => Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport))),
}
}

Expand Down
46 changes: 28 additions & 18 deletions helix-dap/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,38 +230,48 @@ impl Transport {
}
}

async fn recv(
async fn recv_inner(
transport: Arc<Self>,
mut server_stdout: Box<dyn AsyncBufRead + Unpin + Send>,
client_tx: UnboundedSender<Payload>,
) {
) -> Result<()> {
let mut recv_buffer = String::new();
loop {
match Self::recv_server_message(&mut server_stdout, &mut recv_buffer).await {
Ok(msg) => {
transport
.process_server_message(&client_tx, msg)
.await
.unwrap();
}
Err(err) => {
error!("err: <- {:?}", err);
break;
}
}
let msg = Self::recv_server_message(&mut server_stdout, &mut recv_buffer).await?;
transport.process_server_message(&client_tx, msg).await?;
}
}

async fn send(
async fn recv(
transport: Arc<Self>,
server_stdout: Box<dyn AsyncBufRead + Unpin + Send>,
client_tx: UnboundedSender<Payload>,
) {
if let Err(err) = Self::recv_inner(transport, server_stdout, client_tx).await {
error!("err: <- {:?}", err);
}
}

async fn send_inner(
transport: Arc<Self>,
mut server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
mut client_rx: UnboundedReceiver<Payload>,
) {
) -> Result<()> {
while let Some(payload) = client_rx.recv().await {
transport
.send_payload_to_server(&mut server_stdin, payload)
.await
.unwrap()
.await?;
}
Ok(())
}

async fn send(
transport: Arc<Self>,
server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
client_rx: UnboundedReceiver<Payload>,
) {
if let Err(err) = Self::send_inner(transport, server_stdin, client_rx).await {
error!("err: <- {:?}", err);
}
}

Expand Down
1 change: 1 addition & 0 deletions helix-view/src/handlers/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ impl Editor {
}
}
None => {
self.debugger = None;
self.set_status(
"Terminated debugging session and disconnected debugger.",
);
Expand Down

0 comments on commit 644f17f

Please sign in to comment.