dap/reverse_requests.rs
1use std::collections::HashMap;
2
3#[cfg(feature = "client")]
4use serde::Deserialize;
5use serde::Serialize;
6
7use crate::types::{RunInTerminalRequestArgumentsKind, StartDebuggingRequestKind};
8
9#[cfg_attr(feature = "client", derive(Deserialize))]
10#[derive(Serialize, Debug, Default, Clone)]
11#[serde(rename_all = "camelCase")]
12pub struct RunInTerminalRequestArguments {
13 /// What kind of terminal to launch.
14 /// Values: 'integrated', 'external'
15 pub kind: Option<RunInTerminalRequestArgumentsKind>,
16 /// Title of the terminal.
17 pub title: Option<String>,
18 /// Working directory for the command. For non-empty, valid paths this
19 /// typically results in execution of a change directory command.
20 pub cwd: String,
21 /// List of arguments. The first argument is the command to run.
22 pub args: Vec<String>,
23 /// Environment key-value pairs that are added to or removed from the default
24 /// environment.
25 pub env: Option<HashMap<String, Option<String>>>,
26 /// This property should only be set if the corresponding capability
27 /// `supportsArgsCanBeInterpretedByShell` is true. If the client uses an
28 /// intermediary shell to launch the application, then the client must not
29 /// attempt to escape characters with special meanings for the shell. The user
30 /// is fully responsible for escaping as needed and that arguments using
31 /// special characters may not be portable across shells.
32 pub args_can_be_interpreted_by_shell: Option<bool>,
33}
34
35#[cfg_attr(feature = "client", derive(Deserialize))]
36#[derive(Serialize, Debug, Clone)]
37#[serde(rename_all = "camelCase")]
38pub struct StartDebuggingRequestArguments {
39 /// Arguments passed to the new debug session. The arguments must only contain
40 /// properties understood by the `launch` or `attach` requests of the debug
41 /// adapter and they must not contain any client-specific properties (e.g.
42 /// `type`) or client-specific features (e.g. substitutable 'variables').
43 pub configuration: HashMap<String, serde_json::Value>,
44 /// Indicates whether the new debug session should be started with a `launch`
45 /// or `attach` request.
46 /// Values: 'launch', 'attach'
47 pub request: StartDebuggingRequestKind,
48}
49
50#[cfg_attr(feature = "client", derive(Deserialize))]
51#[derive(Serialize, Debug, Clone)]
52#[serde(tag = "command", content = "arguments", rename_all = "camelCase")]
53pub enum ReverseCommand {
54 /// This request is sent from the debug adapter to the client to run a command in a terminal.
55 ///
56 /// This is typically used to launch the debuggee in a terminal provided by the client.
57 ///
58 /// This request should only be called if the corresponding client capability
59 /// `supportsRunInTerminalRequest` is true.
60 ///
61 /// Client implementations of `runInTerminal` are free to run the command however they choose
62 /// including issuing the command to a command line interpreter (aka 'shell'). Argument strings
63 /// passed to the `runInTerminal` request must arrive verbatim in the command to be run.
64 /// As a consequence, clients which use a shell are responsible for escaping any special shell
65 /// characters in the argument strings to prevent them from being interpreted (and modified) by
66 /// the shell.
67 ///
68 /// Some users may wish to take advantage of shell processing in the argument strings. For
69 /// clients which implement `runInTerminal` using an intermediary shell, the
70 /// `argsCanBeInterpretedByShell` property can be set to true. In this case the client is
71 /// requested not to escape any special shell characters in the argument strings.
72 ///
73 /// Specification: [RunInTerminal](https://microsoft.github.io/debug-adapter-protocol/specification#Reverse_Requests_RunInTerminal)
74 RunInTerminal(RunInTerminalRequestArguments),
75 /// This request is sent from the debug adapter to the client to start a new debug session of the
76 /// same type as the caller.
77 ///
78 /// This request should only be sent if the corresponding client capability
79 /// `supportsStartDebuggingRequest` is true.
80 ///
81 /// Specification: [StartDebugging](https://microsoft.github.io/debug-adapter-protocol/specification#Reverse_Requests_StartDebugging)
82 StartDebugging(StartDebuggingRequestArguments),
83}
84
85/// A debug adapter initiated request.
86///
87/// The specification treats reverse requests identically to all other requests
88/// (even though there is a separate section for them). However, in Rust, it is
89/// beneficial to separate them because then we don't need to generate a huge
90/// amount of serialization code for all requests and supporting types (that the
91/// vast majority of would never be serialized by the adapter, only deserialized).
92#[cfg_attr(feature = "client", derive(Deserialize))]
93#[derive(Serialize, Debug, Clone)]
94#[serde(rename_all = "camelCase")]
95pub struct ReverseRequest {
96 /// Sequence number for the Request.
97 ///
98 /// From the [specification](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_ProtocolMessage):
99 ///
100 /// Sequence number of the message (also known as message ID). The `seq` for
101 /// the first message sent by a client or debug adapter is 1, and for each
102 /// subsequent message is 1 greater than the previous message sent by that
103 /// actor. `seq` can be used to order requests, responses, and events, and to
104 /// associate requests with their corresponding responses. For protocol
105 /// messages of type `request` the sequence number can be used to cancel the
106 /// request.
107 pub seq: i64,
108 /// The command to execute.
109 ///
110 /// This is stringly typed in the specification, but represented as an enum for better
111 /// ergonomics in Rust code, along with the arguments when present.
112 #[serde(flatten)]
113 pub command: ReverseCommand,
114}