1mod codelldb;
  2mod gdb;
  3mod go;
  4mod javascript;
  5mod python;
  6
  7#[cfg(test)]
  8use std::path::PathBuf;
  9use std::sync::Arc;
 10
 11use anyhow::Result;
 12use async_trait::async_trait;
 13use codelldb::CodeLldbDebugAdapter;
 14use dap::{
 15    DapRegistry,
 16    adapters::{
 17        self, AdapterVersion, DapDelegate, DebugAdapter, DebugAdapterBinary, DebugAdapterName,
 18    },
 19    configure_tcp_connection,
 20};
 21use gdb::GdbDebugAdapter;
 22use go::GoDebugAdapter;
 23use gpui::{App, BorrowAppContext};
 24use javascript::JsDebugAdapter;
 25use python::PythonDebugAdapter;
 26use serde_json::json;
 27use task::{DebugScenario, ZedDebugConfig};
 28
 29pub fn init(cx: &mut App) {
 30    cx.update_default_global(|registry: &mut DapRegistry, _cx| {
 31        registry.add_adapter(Arc::from(CodeLldbDebugAdapter::default()));
 32        registry.add_adapter(Arc::from(PythonDebugAdapter::default()));
 33        registry.add_adapter(Arc::from(JsDebugAdapter::default()));
 34        registry.add_adapter(Arc::from(GoDebugAdapter::default()));
 35        registry.add_adapter(Arc::from(GdbDebugAdapter));
 36
 37        #[cfg(any(test, feature = "test-support"))]
 38        {
 39            registry.add_adapter(Arc::from(dap::FakeAdapter {}));
 40        }
 41    })
 42}
 43
 44#[cfg(test)]
 45mod test_mocks {
 46    use super::*;
 47
 48    pub(crate) struct MockDelegate {
 49        worktree_root: PathBuf,
 50    }
 51
 52    impl MockDelegate {
 53        pub(crate) fn new() -> Arc<dyn adapters::DapDelegate> {
 54            Arc::new(Self {
 55                worktree_root: PathBuf::from("/tmp/test"),
 56            })
 57        }
 58    }
 59
 60    #[async_trait::async_trait]
 61    impl adapters::DapDelegate for MockDelegate {
 62        fn worktree_id(&self) -> settings::WorktreeId {
 63            settings::WorktreeId::from_usize(0)
 64        }
 65
 66        fn worktree_root_path(&self) -> &std::path::Path {
 67            &self.worktree_root
 68        }
 69
 70        fn http_client(&self) -> Arc<dyn http_client::HttpClient> {
 71            unimplemented!("Not needed for tests")
 72        }
 73
 74        fn node_runtime(&self) -> node_runtime::NodeRuntime {
 75            unimplemented!("Not needed for tests")
 76        }
 77
 78        fn toolchain_store(&self) -> Arc<dyn language::LanguageToolchainStore> {
 79            unimplemented!("Not needed for tests")
 80        }
 81
 82        fn fs(&self) -> Arc<dyn fs::Fs> {
 83            unimplemented!("Not needed for tests")
 84        }
 85
 86        fn output_to_console(&self, _msg: String) {}
 87
 88        async fn which(&self, _command: &std::ffi::OsStr) -> Option<PathBuf> {
 89            None
 90        }
 91
 92        async fn read_text_file(&self, _path: &util::rel_path::RelPath) -> Result<String> {
 93            Ok(String::new())
 94        }
 95
 96        async fn shell_env(&self) -> collections::HashMap<String, String> {
 97            collections::HashMap::default()
 98        }
 99
100        fn is_headless(&self) -> bool {
101            false
102        }
103    }
104}