diff --git a/crates/dap/src/debugger_settings.rs b/crates/dap/src/debugger_settings.rs index 0d5a744a84936..4594a1785039e 100644 --- a/crates/dap/src/debugger_settings.rs +++ b/crates/dap/src/debugger_settings.rs @@ -19,6 +19,10 @@ pub struct DebuggerSettings { /// /// Default: true pub button: bool, + /// Time in milliseconds until timeout error when connecting to a TCP debug adapter + /// + /// Default: 2000ms + pub timeout: u64, } impl Default for DebuggerSettings { @@ -27,6 +31,7 @@ impl Default for DebuggerSettings { button: true, save_breakpoints: true, stepping_granularity: SteppingGranularity::Line, + timeout: 2000, } } } diff --git a/crates/dap/src/transport.rs b/crates/dap/src/transport.rs index 7037377e1ba37..e68d1590c2a34 100644 --- a/crates/dap/src/transport.rs +++ b/crates/dap/src/transport.rs @@ -6,6 +6,7 @@ use dap_types::{ }; use futures::{select, AsyncBufRead, AsyncReadExt as _, AsyncWrite, FutureExt as _}; use gpui::AsyncAppContext; +use settings::Settings as _; use smallvec::SmallVec; use smol::{ channel::{unbounded, Receiver, Sender}, @@ -23,7 +24,7 @@ use std::{ }; use task::TCPHost; -use crate::adapters::DebugAdapterBinary; +use crate::{adapters::DebugAdapterBinary, debugger_settings::DebuggerSettings}; pub type IoHandler = Box; @@ -373,8 +374,6 @@ pub struct TcpTransport { } impl TcpTransport { - const DEFAULT_TIMEOUT: u64 = 2000; - pub fn new(host: Ipv4Addr, port: u16, timeout: Option) -> Self { Self { port, @@ -425,7 +424,10 @@ impl Transport for TcpTransport { let address = SocketAddrV4::new(self.host, self.port); - let timeout = self.timeout.unwrap_or(Self::DEFAULT_TIMEOUT); + let timeout = self.timeout.unwrap_or_else(|| { + cx.update(|cx| DebuggerSettings::get_global(cx).timeout) + .unwrap_or(2000u64) + }); let (rx, tx) = select! { _ = cx.background_executor().timer(Duration::from_millis(timeout)).fuse() => {