Skip to content

Commit

Permalink
chore: address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Dutescu <[email protected]>
  • Loading branch information
filipdutescu committed Feb 1, 2023
1 parent 6e22a8b commit bde318b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
16 changes: 7 additions & 9 deletions helix-dap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Client {
_process: Option<Child>,
server_tx: UnboundedSender<Payload>,
request_counter: AtomicU64,
starting_request: StartingRequest,
starting_request: Option<ConnectionType>,
pub caps: Option<DebuggerCapabilities>,
// thread_id -> frames
pub stack_frames: HashMap<ThreadId, Vec<StackFrame>>,
Expand All @@ -44,10 +44,9 @@ pub struct Client {
}

#[derive(Clone, Copy, Debug)]
pub enum StartingRequest {
pub enum ConnectionType {
Launch,
Attach,
None,
}

impl Client {
Expand Down Expand Up @@ -87,8 +86,7 @@ impl Client {
server_tx,
request_counter: AtomicU64::new(0),
caps: None,
starting_request: StartingRequest::None,
//
starting_request: None,
stack_frames: HashMap::new(),
thread_states: HashMap::new(),
thread_id: None,
Expand Down Expand Up @@ -217,7 +215,7 @@ impl Client {
self.id
}

pub fn starting_request(&self) -> StartingRequest {
pub fn starting_request(&self) -> Option<ConnectionType> {
self.starting_request
}

Expand Down Expand Up @@ -352,17 +350,17 @@ impl Client {
&mut self,
args: Option<DisconnectArguments>,
) -> impl Future<Output = Result<Value>> {
self.starting_request = StartingRequest::None;
self.starting_request = None;
self.call::<requests::Disconnect>(args)
}

pub fn launch(&mut self, args: serde_json::Value) -> impl Future<Output = Result<Value>> {
self.starting_request = StartingRequest::Launch;
self.starting_request = Some(ConnectionType::Launch);
self.call::<requests::Launch>(args)
}

pub fn attach(&mut self, args: serde_json::Value) -> impl Future<Output = Result<Value>> {
self.starting_request = StartingRequest::Attach;
self.starting_request = Some(ConnectionType::Attach);
self.call::<requests::Attach>(args)
}

Expand Down
2 changes: 1 addition & 1 deletion helix-dap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod client;
mod transport;
mod types;

pub use client::{Client, StartingRequest};
pub use client::{Client, ConnectionType};
pub use events::Event;
pub use transport::{Payload, Response, Transport};
pub use types::*;
Expand Down
39 changes: 21 additions & 18 deletions helix-view/src/handlers/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::editor::{Action, Breakpoint};
use crate::{align_view, Align, Editor};
use dap::requests::DisconnectArguments;
use helix_core::Selection;
use helix_dap::{self as dap, Client, Payload, Request, StartingRequest, ThreadId};
use helix_dap::{self as dap, Client, ConnectionType, Payload, Request, ThreadId};
use helix_lsp::block_on;
use log::warn;
use std::fmt::Write;
Expand Down Expand Up @@ -292,25 +292,28 @@ impl Editor {
let result = debugger.disconnect(disconnect_args).await;
if result.is_ok() {
if restart {
if let StartingRequest::None = starting_request {
self.set_error("No starting request found, to be used in restarting the debugging session.");
} else {
log::info!("Attempting to restart debug session.");
let restart_args = restart_args.unwrap();
let relaunch_resp =
if let StartingRequest::Launch = starting_request {
debugger.launch(restart_args).await
} else {
debugger.attach(restart_args).await
};
match starting_request {
None => {
self.set_error("No starting request found, to be used in restarting the debugging session.");
}
Some(starting_request) => {
log::info!("Attempting to restart debug session.");
let restart_args = restart_args.unwrap();
let relaunch_resp =
if let ConnectionType::Launch = starting_request {
debugger.launch(restart_args).await
} else {
debugger.attach(restart_args).await
};

if let Err(err) = relaunch_resp {
self.set_error(format!(
"Failed to restart debugging session: {:?}",
err
));
if let Err(err) = relaunch_resp {
self.set_error(format!(
"Failed to restart debugging session: {:?}",
err
));
}
}
}
};
} else {
self.set_status(
"Terminated debugging session and disconnected debugger.",
Expand Down

0 comments on commit bde318b

Please sign in to comment.