Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/commands/dap.rs')
-rw-r--r--helix-term/src/commands/dap.rs62
1 files changed, 29 insertions, 33 deletions
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs
index 4f20af4a..f6f11d12 100644
--- a/helix-term/src/commands/dap.rs
+++ b/helix-term/src/commands/dap.rs
@@ -6,12 +6,11 @@ use crate::{
};
use dap::{StackFrame, Thread, ThreadStates};
use helix_core::syntax::config::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate};
-use helix_dap::{self as dap, Client};
+use helix_dap::{self as dap, requests::TerminateArguments};
use helix_lsp::block_on;
use helix_view::editor::Breakpoint;
use serde_json::{to_value, Value};
-use tokio_stream::wrappers::UnboundedReceiverStream;
use tui::text::Spans;
use std::collections::HashMap;
@@ -59,7 +58,12 @@ fn thread_picker(
move |cx, thread, _action| callback_fn(cx.editor, thread),
)
.with_preview(move |editor, thread| {
- let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
+ let frames = editor
+ .debug_adapters
+ .get_active_client()
+ .as_ref()?
+ .stack_frames
+ .get(&thread.id)?;
let frame = frames.first()?;
let path = frame.source.as_ref()?.path.as_ref()?.as_path();
let pos = Some((
@@ -116,34 +120,16 @@ pub fn dap_start_impl(
params: Option<Vec<std::borrow::Cow<str>>>,
) -> Result<(), anyhow::Error> {
let doc = doc!(cx.editor);
-
let config = doc
.language_config()
.and_then(|config| config.debugger.as_ref())
.ok_or_else(|| anyhow!("No debug adapter available for language"))?;
- let result = match socket {
- Some(socket) => block_on(Client::tcp(socket, 0)),
- None => block_on(Client::process(
- &config.transport,
- &config.command,
- config.args.iter().map(|arg| arg.as_str()).collect(),
- config.port_arg.as_deref(),
- 0,
- )),
- };
-
- let (mut debugger, events) = match result {
- Ok(r) => r,
- Err(e) => bail!("Failed to start debug session: {}", e),
- };
-
- let request = debugger.initialize(config.name.clone());
- if let Err(e) = block_on(request) {
- bail!("Failed to initialize debug adapter: {}", e);
- }
-
- debugger.quirks = config.quirks.clone();
+ let id = cx
+ .editor
+ .debug_adapters
+ .start_client(socket, config)
+ .map_err(|e| anyhow!("Failed to start debug client: {}", e))?;
// TODO: avoid refetching all of this... pass a config in
let template = match name {
@@ -209,6 +195,13 @@ pub fn dap_start_impl(
// }
};
+ let debugger = match cx.editor.debug_adapters.get_client_mut(id) {
+ Some(child) => child,
+ None => {
+ bail!("Failed to get child debugger.");
+ }
+ };
+
match &template.request[..] {
"launch" => {
let call = debugger.launch(args);
@@ -222,14 +215,12 @@ pub fn dap_start_impl(
};
// TODO: either await "initialized" or buffer commands until event is received
- cx.editor.debugger = Some(debugger);
- let stream = UnboundedReceiverStream::new(events);
- cx.editor.debugger_events.push(stream);
Ok(())
}
pub fn dap_launch(cx: &mut Context) {
- if cx.editor.debugger.is_some() {
+ // TODO: Now that we support multiple Clients, we could run multiple debuggers at once but for now keep this as is
+ if cx.editor.debug_adapters.get_active_client().is_some() {
cx.editor.set_error("Debugger is already running");
return;
}
@@ -283,7 +274,7 @@ pub fn dap_launch(cx: &mut Context) {
}
pub fn dap_restart(cx: &mut Context) {
- let debugger = match &cx.editor.debugger {
+ let debugger = match cx.editor.debug_adapters.get_active_client() {
Some(debugger) => debugger,
None => {
cx.editor.set_error("Debugger is not running");
@@ -582,12 +573,17 @@ pub fn dap_variables(cx: &mut Context) {
}
pub fn dap_terminate(cx: &mut Context) {
+ cx.editor.set_status("Terminating debug session...");
let debugger = debugger!(cx.editor);
- let request = debugger.disconnect(None);
+ let terminate_arguments = Some(TerminateArguments {
+ restart: Some(false),
+ });
+
+ let request = debugger.terminate(terminate_arguments);
dap_callback(cx.jobs, request, |editor, _compositor, _response: ()| {
// editor.set_error(format!("Failed to disconnect: {}", e));
- editor.debugger = None;
+ editor.debug_adapters.unset_active_client();
});
}