dap_adapters.rs

 1mod codelldb;
 2mod gdb;
 3mod go;
 4mod javascript;
 5mod php;
 6mod python;
 7
 8use std::{net::Ipv4Addr, sync::Arc};
 9
10use anyhow::{Result, anyhow};
11use async_trait::async_trait;
12use codelldb::CodeLldbDebugAdapter;
13use dap::{
14    DapRegistry, DebugRequestType,
15    adapters::{
16        self, AdapterVersion, DapDelegate, DebugAdapter, DebugAdapterBinary, DebugAdapterName,
17        GithubRepo,
18    },
19};
20use gdb::GdbDebugAdapter;
21use go::GoDebugAdapter;
22use javascript::JsDebugAdapter;
23use php::PhpDebugAdapter;
24use python::PythonDebugAdapter;
25use serde_json::{Value, json};
26use task::TCPHost;
27
28pub fn init(registry: Arc<DapRegistry>) {
29    registry.add_adapter(Arc::from(CodeLldbDebugAdapter::default()));
30    registry.add_adapter(Arc::from(PythonDebugAdapter));
31    registry.add_adapter(Arc::from(PhpDebugAdapter));
32    registry.add_adapter(Arc::from(JsDebugAdapter));
33    registry.add_adapter(Arc::from(GoDebugAdapter));
34    registry.add_adapter(Arc::from(GdbDebugAdapter));
35}
36
37pub(crate) async fn configure_tcp_connection(
38    tcp_connection: TCPHost,
39) -> Result<(Ipv4Addr, u16, Option<u64>)> {
40    let host = tcp_connection.host();
41    let timeout = tcp_connection.timeout;
42
43    let port = if let Some(port) = tcp_connection.port {
44        port
45    } else {
46        dap::transport::TcpTransport::port(&tcp_connection).await?
47    };
48
49    Ok((host, port, timeout))
50}
51
52trait ToDap {
53    fn to_dap(&self) -> dap::StartDebuggingRequestArgumentsRequest;
54}
55
56impl ToDap for DebugRequestType {
57    fn to_dap(&self) -> dap::StartDebuggingRequestArgumentsRequest {
58        match self {
59            Self::Launch(_) => dap::StartDebuggingRequestArgumentsRequest::Launch,
60            Self::Attach(_) => dap::StartDebuggingRequestArgumentsRequest::Attach,
61        }
62    }
63}