Common/Debug/
DebugService.rs

1// File: Common/Source/Debug/DebugService.rs
2// Role: Defines the abstract service trait for launching and managing debug
3// sessions. Responsibilities:
4//   - Provide a contract for registering debug configuration providers and
5//     adapter factories.
6//   - Provide a contract for starting debug sessions and controlling them
7//     (e.g., sending commands).
8
9//! # DebugService Trait
10//!
11//! Defines the abstract service trait for launching and managing debug
12//! sessions.
13
14use async_trait::async_trait;
15use serde_json::Value;
16use url::Url;
17
18use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
19
20/// An abstract service contract for an environment component that can manage
21/// the entire debug lifecycle, from configuration resolution to session
22/// control.
23#[async_trait]
24pub trait DebugService: Environment + Send + Sync {
25	/// Registers a provider for resolving debug configurations from an
26	/// extension.
27	///
28	/// # Parameters
29	/// * `DebugType`: The type of debugger this provider is for (e.g., "node").
30	/// * `ProviderHandle`: A unique handle assigned by the extension host for
31	///   this provider.
32	/// * `SideCarIdentifier`: The identifier of the sidecar (e.g.,
33
34	///   "cocoon-main") hosting the provider.
35	async fn RegisterDebugConfigurationProvider(
36		&self,
37
38		DebugType:String,
39
40		ProviderHandle:u32,
41
42		SideCarIdentifier:String,
43	) -> Result<(), CommonError>;
44
45	/// Registers a factory for creating debug adapter descriptors from an
46	/// extension.
47	///
48	/// # Parameters
49	/// * `DebugType`: The type of debugger this factory is for.
50	/// * `FactoryHandle`: A unique handle assigned by the extension host for
51	///   this factory.
52	/// * `SideCarIdentifier`: The identifier of the sidecar hosting the
53	///   factory.
54	async fn RegisterDebugAdapterDescriptorFactory(
55		&self,
56
57		DebugType:String,
58
59		FactoryHandle:u32,
60
61		SideCarIdentifier:String,
62	) -> Result<(), CommonError>;
63
64	/// Starts a new debugging session based on a launch configuration.
65	///
66	/// # Parameters
67	/// * `FolderURI`: The URI of the workspace folder context for this debug
68	///   session.
69	/// * `Configuration`: The `DebugConfiguration` DTO to use for launching.
70	///
71	/// # Returns
72	/// A `Result` containing a unique session ID string on success.
73	async fn StartDebugging(&self, FolderURI:Option<Url>, Configuration:Value) -> Result<String, CommonError>;
74
75	/// Sends a command to a running debug session. This corresponds to the
76	/// Debug Adapter Protocol (DAP).
77	///
78	/// # Parameters
79	/// * `SessionID`: The unique ID of the target debug session.
80	/// * `Command`: The DAP command to send (e.g., "continue", "stepOver").
81	/// * `Arguments`: A JSON value containing the arguments for the command.
82	///
83	/// # Returns
84	/// A `Result` containing the JSON response from the debug adapter.
85	async fn SendCommand(&self, SessionID:String, Command:String, Arguments:Value) -> Result<Value, CommonError>;
86}