Skip to content

Commit

Permalink
Get sequence id to be incremented after getting respond and event
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Eid committed Jul 25, 2024
1 parent a136b72 commit 0975ca8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/dap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct DebugAdapterClient {
id: DebugAdapterClientId,
_process: Option<Child>,
server_tx: Sender<Payload>,
request_count: AtomicU64,
sequence_count: AtomicU64,
capabilities: Arc<Mutex<Option<dap_types::Capabilities>>>,
config: DebugAdapterConfig,
thread_states: Arc<Mutex<HashMap<u64, ThreadState>>>, // thread_id -> thread_state
Expand Down Expand Up @@ -286,7 +286,7 @@ impl DebugAdapterClient {
config,
server_tx,
_process: process,
request_count: AtomicU64::new(1),
sequence_count: AtomicU64::new(1),
capabilities: Default::default(),
thread_states: Arc::new(Mutex::new(HashMap::new())),
};
Expand Down Expand Up @@ -357,14 +357,15 @@ impl DebugAdapterClient {

let request = Request {
back_ch: Some(callback_tx),
seq: self.next_request_id(),
seq: self.next_sequence_id(),
command: R::COMMAND.to_string(),
arguments: Some(serialized_arguments),
};

self.server_tx.send(Payload::Request(request)).await?;

let response = callback_rx.recv().await??;
let _ = self.next_sequence_id();

match response.success {
true => Ok(serde_json::from_value(response.body.unwrap_or_default())?),
Expand All @@ -388,8 +389,11 @@ impl DebugAdapterClient {
self.capabilities.lock().clone().unwrap_or_default()
}

pub fn next_request_id(&self) -> u64 {
self.request_count.fetch_add(1, Ordering::Relaxed)
/// Get the next sequence id to be used in a request
/// # Side Effect
/// This function also increment's client's sequence count by one
pub fn next_sequence_id(&self) -> u64 {
self.sequence_count.fetch_add(1, Ordering::Relaxed)
}

pub fn update_thread_state_status(&self, thread_id: u64, status: ThreadStatus) {
Expand Down
3 changes: 3 additions & 0 deletions crates/debugger_ui/src/debugger_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ impl DebugPanel {
event: &Events,
cx: &mut ViewContext<Self>,
) {
// Increment the sequence id because an event is being processed
let _ = client.next_sequence_id();

match event {
Events::Initialized(event) => Self::handle_initialized_event(client, event, cx),
Events::Stopped(event) => Self::handle_stopped_event(client, event, cx),
Expand Down

0 comments on commit 0975ca8

Please sign in to comment.