on master help sign in
Fix unwrap bug in DAP (#6786)
8839eb0A-Walrus
helix-dap/src/client.rs+4−6
@@ -62,12 +62,10 @@ impl Client {
62 if command.is_empty() {
62 if command.is_empty() {
63 return Result::Err(Error::Other(anyhow!("Command not provided")));
63 return Result::Err(Error::Other(anyhow!("Command not provided")));
64 }
64 }
65− if transport == "tcp" && port_arg.is_some() {
65+ match (transport, port_arg) {
66− Self::tcp_process(command, args, port_arg.unwrap(), id).await
66+ ("tcp", Some(port_arg)) => Self::tcp_process(command, args, port_arg, id).await,
67− } else if transport == "stdio" {
68− Self::stdio(command, args, id)
67+ ("stdio", _) => Self::stdio(command, args, id),
69− } else {
70− Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport)))
68+ _ => Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport))),
71 }
69 }
72 }
70 }
73
71
helix-dap/src/transport.rs+28−18
@@ -230,38 +230,48 @@ impl Transport {
230 }
230 }
231 }
231 }
232
232
233− async fn recv(
233+ async fn recv_inner(
234 transport: Arc<Self>,
234 transport: Arc<Self>,
235 mut server_stdout: Box<dyn AsyncBufRead + Unpin + Send>,
235 mut server_stdout: Box<dyn AsyncBufRead + Unpin + Send>,
236 client_tx: UnboundedSender<Payload>,
236 client_tx: UnboundedSender<Payload>,
237− ) {
237+ ) -> Result<()> {
238 let mut recv_buffer = String::new();
238 let mut recv_buffer = String::new();
239 loop {
239 loop {
240− match Self::recv_server_message(&mut server_stdout, &mut recv_buffer).await {
240+ let msg = Self::recv_server_message(&mut server_stdout, &mut recv_buffer).await?;
241− Ok(msg) => {
242− transport
243− .process_server_message(&client_tx, msg)
241+ transport.process_server_message(&client_tx, msg).await?;
244− .await
245− .unwrap();
246− }
247− Err(err) => {
248− error!("err: <- {:?}", err);
249− break;
250− }
251− }
252 }
242 }
253 }
243 }
254
244
255− async fn send(
245+ async fn recv(
246+ transport: Arc<Self>,
247+ server_stdout: Box<dyn AsyncBufRead + Unpin + Send>,
248+ client_tx: UnboundedSender<Payload>,
249+ ) {
250+ if let Err(err) = Self::recv_inner(transport, server_stdout, client_tx).await {
251+ error!("err: <- {:?}", err);
252+ }
253+ }
254+
255+ async fn send_inner(
256 transport: Arc<Self>,
256 transport: Arc<Self>,
257 mut server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
257 mut server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
258 mut client_rx: UnboundedReceiver<Payload>,
258 mut client_rx: UnboundedReceiver<Payload>,
259− ) {
259+ ) -> Result<()> {
260 while let Some(payload) = client_rx.recv().await {
260 while let Some(payload) = client_rx.recv().await {
261 transport
261 transport
262 .send_payload_to_server(&mut server_stdin, payload)
262 .send_payload_to_server(&mut server_stdin, payload)
263− .await
263+ .await?;
264− .unwrap()
264+ }
265+ Ok(())
266+ }
267+
268+ async fn send(
269+ transport: Arc<Self>,
270+ server_stdin: Box<dyn AsyncWrite + Unpin + Send>,
271+ client_rx: UnboundedReceiver<Payload>,
272+ ) {
273+ if let Err(err) = Self::send_inner(transport, server_stdin, client_rx).await {
274+ error!("err: <- {:?}", err);
265 }
275 }
266 }
276 }
267
277
helix-view/src/handlers/dap.rs+1
@@ -321,6 +321,7 @@ impl Editor {
321 }
321 }
322 }
322 }
323 None => {
323 None => {
324+ self.debugger = None;
324 self.set_status(
325 self.set_status(
325 "Terminated debugging session and disconnected debugger.",
326 "Terminated debugging session and disconnected debugger.",
326 );
327 );