Skip to main content

DapClient

Struct DapClient 

Source
pub struct DapClient {
    pub capabilities: Capabilities,
    /* private fields */
}
Expand description

DAP client for communicating with a debug adapter

Fields§

§capabilities: Capabilities

Adapter capabilities (populated after initialize)

Implementations§

Source§

impl DapClient

Source

pub async fn spawn(adapter_path: &Path, args: &[String]) -> Result<Self>

Spawn a new DAP adapter and create a client

Source

pub async fn spawn_tcp(adapter_path: &Path, args: &[String]) -> Result<Self>

Spawn a new DAP adapter that uses TCP for communication (e.g., Delve)

This spawns the adapter with a –listen flag, waits for it to output the port it’s listening on, then connects via TCP.

Source

pub fn take_event_receiver(&mut self) -> Option<UnboundedReceiver<Event>>

Take the event receiver (can only be called once)

Source

pub async fn request<T: DeserializeOwned>( &mut self, command: &str, arguments: Option<Value>, ) -> Result<T>

Send a request and wait for the response with timeout

Source

pub async fn request_with_timeout<T: DeserializeOwned>( &mut self, command: &str, arguments: Option<Value>, timeout: Duration, ) -> Result<T>

Send a request and wait for the response with configurable timeout

Note: We register the pending response handler BEFORE sending the request to avoid a race condition where a fast adapter response arrives before we’ve set up the handler.

Source

pub async fn poll_event(&mut self) -> Result<Option<Event>>

Poll for events - this is now non-blocking since events are already in the channel Note: This method is kept for API compatibility but is no longer necessary since the background reader task handles all event ingestion

Source

pub async fn initialize(&mut self, adapter_id: &str) -> Result<Capabilities>

Initialize the debug adapter

Source

pub async fn initialize_with_timeout( &mut self, adapter_id: &str, timeout: Duration, ) -> Result<Capabilities>

Initialize the debug adapter with configurable timeout

Source

pub async fn wait_initialized(&mut self) -> Result<()>

Wait for the initialized event with timeout

This method waits for the initialized event which comes through the event channel. It’s called before the session takes the event receiver.

Source

pub async fn wait_initialized_with_timeout( &mut self, timeout: Duration, ) -> Result<()>

Wait for the initialized event with configurable timeout

§Event Ordering Note

This method consumes events from the channel until it sees Initialized. Non-Initialized events are re-sent to the channel so they won’t be lost. This is safe because:

  1. The session hasn’t taken the receiver yet (wait_initialized is called during setup)
  2. The re-sent events go back to the same unbounded channel
  3. The background reader task continues adding new events after our re-sent ones

Events will be received in order: [re-sent events] + [new events from reader]

Source

pub async fn launch(&mut self, args: LaunchArguments) -> Result<()>

Launch a program for debugging

Source

pub async fn launch_no_wait(&mut self, args: LaunchArguments) -> Result<i64>

Launch a program for debugging without waiting for response

Some debuggers (like debugpy) don’t respond to launch until after configurationDone is sent. This sends the launch request but doesn’t wait for the response.

Source

pub async fn attach(&mut self, args: AttachArguments) -> Result<()>

Attach to a running process

Source

pub async fn configuration_done(&mut self) -> Result<()>

Signal that configuration is done

Source

pub async fn set_breakpoints( &mut self, source_path: &Path, breakpoints: Vec<SourceBreakpoint>, ) -> Result<Vec<Breakpoint>>

Set breakpoints for a source file

Source

pub async fn set_function_breakpoints( &mut self, breakpoints: Vec<FunctionBreakpoint>, ) -> Result<Vec<Breakpoint>>

Set function breakpoints

Source

pub async fn continue_execution(&mut self, thread_id: i64) -> Result<bool>

Continue execution

Source

pub async fn next(&mut self, thread_id: i64) -> Result<()>

Step over (next)

Source

pub async fn step_in(&mut self, thread_id: i64) -> Result<()>

Step into

Source

pub async fn step_out(&mut self, thread_id: i64) -> Result<()>

Step out

Source

pub async fn pause(&mut self, thread_id: i64) -> Result<()>

Pause execution

Source

pub async fn stack_trace( &mut self, thread_id: i64, levels: i64, ) -> Result<Vec<StackFrame>>

Get stack trace

Source

pub async fn threads(&mut self) -> Result<Vec<Thread>>

Get threads

Source

pub async fn scopes(&mut self, frame_id: i64) -> Result<Vec<Scope>>

Get scopes for a frame

Source

pub async fn variables( &mut self, variables_reference: i64, ) -> Result<Vec<Variable>>

Get variables

Source

pub async fn evaluate( &mut self, expression: &str, frame_id: Option<i64>, context: &str, ) -> Result<EvaluateResponseBody>

Evaluate an expression

Source

pub async fn disconnect(&mut self, terminate_debuggee: bool) -> Result<()>

Disconnect from the debug adapter

Source

pub async fn terminate(&mut self) -> Result<()>

Terminate the adapter process and clean up resources

Source

pub fn is_running(&mut self) -> bool

Check if the adapter is still running

Source

pub async fn restart(&mut self, no_debug: bool) -> Result<()>

Restart the debug session (for adapters that support it)

Trait Implementations§

Source§

impl Drop for DapClient

Source§

fn drop(&mut self)

Best-effort cleanup on drop.

§Limitations

Since we can’t await in drop(), this is necessarily imperfect:

  • try_send may fail if the shutdown channel is full (unlikely with capacity 1)
  • task.abort() is immediate; the reader may be mid-operation
  • start_kill() is non-blocking; the adapter may not exit immediately

For graceful cleanup, prefer calling terminate() before dropping. This Drop impl exists as a safety net to avoid leaking resources if terminate() wasn’t called.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more