extension/dap: Add resolve_tcp_template function (#31010)

Extensions cannot look up available port themselves, hence the new API.
With this I'm able to port our Ruby implementation into an extension.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-05-20 15:17:13 +02:00 committed by GitHub
parent e4262f97af
commit e5670ba081
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 48 additions and 24 deletions

View file

@ -6,7 +6,7 @@ mod php;
mod python;
mod ruby;
use std::{net::Ipv4Addr, sync::Arc};
use std::sync::Arc;
use anyhow::{Result, anyhow};
use async_trait::async_trait;
@ -17,6 +17,7 @@ use dap::{
self, AdapterVersion, DapDelegate, DebugAdapter, DebugAdapterBinary, DebugAdapterName,
GithubRepo,
},
configure_tcp_connection,
inline_value::{PythonInlineValueProvider, RustInlineValueProvider},
};
use gdb::GdbDebugAdapter;
@ -27,7 +28,6 @@ use php::PhpDebugAdapter;
use python::PythonDebugAdapter;
use ruby::RubyDebugAdapter;
use serde_json::{Value, json};
use task::TcpArgumentsTemplate;
pub fn init(cx: &mut App) {
cx.update_default_global(|registry: &mut DapRegistry, _cx| {
@ -45,21 +45,6 @@ pub fn init(cx: &mut App) {
})
}
pub(crate) async fn configure_tcp_connection(
tcp_connection: TcpArgumentsTemplate,
) -> Result<(Ipv4Addr, u16, Option<u64>)> {
let host = tcp_connection.host();
let timeout = tcp_connection.timeout;
let port = if let Some(port) = tcp_connection.port {
port
} else {
dap::transport::TcpTransport::port(&tcp_connection).await?
};
Ok((host, port, timeout))
}
trait ToDap {
fn to_dap(&self) -> dap::StartDebuggingRequestArgumentsRequest;
}