dap_adapters.rs

  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)]
 45struct MockDelegate {
 46    worktree_root: PathBuf,
 47}
 48
 49#[cfg(test)]
 50impl MockDelegate {
 51    fn new() -> Arc<dyn adapters::DapDelegate> {
 52        Arc::new(Self {
 53            worktree_root: PathBuf::from("/tmp/test"),
 54        })
 55    }
 56}
 57
 58#[cfg(test)]
 59#[async_trait::async_trait]
 60impl adapters::DapDelegate for MockDelegate {
 61    fn worktree_id(&self) -> settings::WorktreeId {
 62        settings::WorktreeId::from_usize(0)
 63    }
 64
 65    fn worktree_root_path(&self) -> &std::path::Path {
 66        &self.worktree_root
 67    }
 68
 69    fn http_client(&self) -> Arc<dyn http_client::HttpClient> {
 70        unimplemented!("Not needed for tests")
 71    }
 72
 73    fn node_runtime(&self) -> node_runtime::NodeRuntime {
 74        unimplemented!("Not needed for tests")
 75    }
 76
 77    fn toolchain_store(&self) -> Arc<dyn language::LanguageToolchainStore> {
 78        unimplemented!("Not needed for tests")
 79    }
 80
 81    fn fs(&self) -> Arc<dyn fs::Fs> {
 82        unimplemented!("Not needed for tests")
 83    }
 84
 85    fn output_to_console(&self, _msg: String) {}
 86
 87    async fn which(&self, _command: &std::ffi::OsStr) -> Option<PathBuf> {
 88        None
 89    }
 90
 91    async fn read_text_file(&self, _path: &util::rel_path::RelPath) -> Result<String> {
 92        Ok(String::new())
 93    }
 94
 95    async fn shell_env(&self) -> collections::HashMap<String, String> {
 96        collections::HashMap::default()
 97    }
 98
 99    fn is_headless(&self) -> bool {
100        false
101    }
102}