debug_adapter_protocol/
responses.rs

1use crate::{
2    types::{
3        Breakpoint, BreakpointLocation, Capabilities, CompletionItem, DataBreakpointAccessType,
4        DisassembledInstruction, ExceptionBreakMode, ExceptionDetails, GotoTarget, Message, Module,
5        Scope, Source, StackFrame, StepInTarget, Thread, Variable, VariablePresentationHint,
6    },
7    utils::{eq_default, true_},
8    ProtocolMessageContent, SequenceNumber,
9};
10use serde::{
11    de::{Error, Unexpected},
12    Deserialize, Deserializer, Serialize, Serializer,
13};
14use serde_json::{Number, Value};
15use typed_builder::TypedBuilder;
16
17/// Response for a request.
18#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
19pub struct Response {
20    /// Sequence number of the corresponding request.
21    pub request_seq: SequenceNumber,
22
23    #[serde(
24        flatten,
25        deserialize_with = "deserialize_response_result",
26        serialize_with = "serialize_response_result"
27    )]
28    pub result: Result<SuccessResponse, ErrorResponse>,
29}
30impl From<Response> for ProtocolMessageContent {
31    fn from(response: Response) -> Self {
32        Self::Response(response)
33    }
34}
35
36#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
37pub struct ErrorResponse {
38    /// The command requested.
39    pub command: String,
40
41    /// Contains the raw error in short form if 'success' is false.
42    /// This raw error might be interpreted by the frontend and is not shown in the
43    /// UI.
44    /// Some predefined values exist.
45    /// Values:
46    /// 'cancelled': request was cancelled.
47    /// etc.
48    pub message: String,
49
50    #[builder(default)]
51    pub body: ErrorResponseBody,
52
53    #[serde(skip)]
54    #[builder(default, setter(skip))]
55    private: (),
56}
57
58#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
59pub struct ErrorResponseBody {
60    /// An optional, structured error message.
61    pub error: Option<Message>,
62
63    #[serde(skip)]
64    private: (),
65}
66impl ErrorResponseBody {
67    pub fn new(error: Option<Message>) -> Self {
68        Self { error, private: () }
69    }
70}
71impl Default for ErrorResponseBody {
72    fn default() -> Self {
73        ErrorResponseBody::new(None)
74    }
75}
76
77/// Contains request result if success is true and optional error details if success is false.
78#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
79#[serde(rename_all = "camelCase", tag = "command", content = "body")]
80pub enum SuccessResponse {
81    /// Response to 'attach' request. This is just an acknowledgement, so no body field is required.
82    Attach,
83
84    /// Response to 'breakpointLocations' request.
85    ///
86    /// Contains possible locations for source breakpoints.
87    BreakpointLocations(BreakpointLocationsResponseBody),
88
89    /// Response to 'cancel' request. This is just an acknowledgement, so no body field is required.
90    Cancel,
91
92    /// Response to 'completions' request.
93    Completions(CompletionsResponseBody),
94
95    /// Response to 'configurationDone' request. This is just an acknowledgement, so no body field is required.
96    ConfigurationDone,
97
98    /// Response to 'continue' request.
99    Continue(ContinueResponseBody),
100
101    /// Response to 'dataBreakpointInfo' request.
102    DataBreakpointInfo(DataBreakpointInfoResponseBody),
103
104    /// Response to 'disassemble' request.
105    Disassemble(DisassembleResponseBody),
106
107    /// Response to 'disconnect' request. This is just an acknowledgement, so no body field is required.
108    Disconnect,
109
110    /// Response to 'evaluate' request.
111    Evaluate(EvaluateResponseBody),
112
113    /// Response to 'exceptionInfo' request.
114    ExceptionInfo(ExceptionInfoResponseBody),
115
116    /// Response to 'goto' request. This is just an acknowledgement, so no body field is required.
117    Goto,
118
119    /// Response to 'gotoTargets' request.
120    GotoTargets(GotoTargetsResponseBody),
121
122    /// Response to 'initialize' request.
123    Initialize(Capabilities),
124
125    /// Response to 'launch' request. This is just an acknowledgement, so no body field is required.
126    Launch,
127
128    /// Response to 'loadedSources' request.
129    LoadedSources(LoadedSourcesResponseBody),
130
131    /// Response to 'modules' request.
132    Modules(ModulesResponseBody),
133
134    /// Response to 'next' request. This is just an acknowledgement, so no body field is required.
135    Next,
136
137    /// Response to 'pause' request. This is just an acknowledgement, so no body field is required.
138    Pause,
139
140    /// Response to 'readMemory' request.
141    ReadMemory(ReadMemoryResponseBody),
142
143    /// Response to 'restartFrame' request. This is just an acknowledgement, so no body field is required.
144    RestartFrame,
145
146    /// Response to 'restart' request. This is just an acknowledgement, so no body field is required.
147    Restart,
148
149    /// Response to 'reverseContinue' request. This is just an acknowledgement, so no body field is required.
150    ReverseContinue,
151
152    /// Response to 'runInTerminal' request.
153    RunInTerminal(RunInTerminalResponseBody),
154
155    /// Response to 'scopes' request.
156    Scopes(ScopesResponseBody),
157
158    /// Response to 'setBreakpoints' request.
159    ///
160    /// Returned is information about each breakpoint created by this request.
161    ///
162    /// This includes the actual code location and whether the breakpoint could be verified.
163    ///
164    /// The breakpoints returned are in the same order as the elements of the 'breakpoints'
165    ///
166    /// (or the deprecated 'lines') array in the arguments.
167    SetBreakpoints(SetBreakpointsResponseBody),
168
169    /// Response to 'setDataBreakpoints' request.
170    ///
171    /// Returned is information about each breakpoint created by this request.
172    SetDataBreakpoints(SetDataBreakpointsResponseBody),
173
174    /// Response to 'setExceptionBreakpoints' request.
175    ///
176    /// The response contains an array of Breakpoint objects with information about each exception breakpoint or filter. The Breakpoint objects are in the same order as the elements of the 'filters', 'filterOptions', 'exceptionOptions' arrays given as arguments. If both 'filters' and 'filterOptions' are given, the returned array must start with 'filters' information first, followed by 'filterOptions' information.
177    ///
178    /// The mandatory 'verified' property of a Breakpoint object signals whether the exception breakpoint or filter could be successfully created and whether the optional condition or hit count expressions are valid. In case of an error the 'message' property explains the problem. An optional 'id' property can be used to introduce a unique ID for the exception breakpoint or filter so that it can be updated subsequently by sending breakpoint events.
179    ///
180    /// For backward compatibility both the 'breakpoints' array and the enclosing 'body' are optional. If these elements are missing a client will not be able to show problems for individual exception breakpoints or filters.
181    SetExceptionBreakpoints(SetExceptionBreakpointsResponseBody),
182
183    /// Response to 'setExpression' request.
184    SetExpression(SetExpressionResponseBody),
185
186    /// Response to 'setFunctionBreakpoints' request.
187    ///
188    /// Returned is information about each breakpoint created by this request.
189    SetFunctionBreakpoints(SetFunctionBreakpointsResponseBody),
190
191    /// Response to 'setInstructionBreakpoints' request
192    SetInstructionBreakpoints(SetInstructionBreakpointsResponseBody),
193
194    /// Response to 'setVariable' request.
195    SetVariable(SetVariableResponseBody),
196
197    /// Response to 'source' request.
198    Source(SourceResponseBody),
199
200    /// Response to 'stackTrace' request.
201    StackTrace(StackTraceResponseBody),
202
203    /// Response to 'stepBack' request. This is just an acknowledgement, so no body field is required.
204    StepBack,
205
206    /// Response to 'stepIn' request. This is just an acknowledgement, so no body field is required.
207    StepIn,
208
209    /// Response to 'stepInTargets' request.
210    StepInTargets(StepInTargetsResponseBody),
211
212    /// Response to 'stepOut' request. This is just an acknowledgement, so no body field is required.
213    StepOut,
214
215    /// Response to 'terminate' request. This is just an acknowledgement, so no body field is required.
216    Terminate,
217
218    /// Response to 'terminateThreads' request. This is just an acknowledgement, so no body field is required.
219    TerminateThreads,
220
221    /// Response to 'threads' request.
222    Threads(ThreadsResponseBody),
223
224    /// Response to 'variables' request.
225    Variables(VariablesResponseBody),
226}
227
228#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
229pub struct BreakpointLocationsResponseBody {
230    /// Sorted set of possible breakpoint locations.
231    #[serde(rename = "breakpoints")]
232    pub breakpoints: Vec<BreakpointLocation>,
233
234    #[serde(skip)]
235    #[builder(default, setter(skip))]
236    private: (),
237}
238impl From<BreakpointLocationsResponseBody> for SuccessResponse {
239    fn from(args: BreakpointLocationsResponseBody) -> Self {
240        Self::BreakpointLocations(args)
241    }
242}
243
244#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
245pub struct CompletionsResponseBody {
246    /// The possible completions for .
247    #[serde(rename = "targets")]
248    pub targets: Vec<CompletionItem>,
249
250    #[serde(skip)]
251    #[builder(default, setter(skip))]
252    private: (),
253}
254impl From<CompletionsResponseBody> for SuccessResponse {
255    fn from(args: CompletionsResponseBody) -> Self {
256        Self::Completions(args)
257    }
258}
259
260#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
261pub struct ContinueResponseBody {
262    /// If true, the 'continue' request has ignored the specified thread and continued all threads instead.
263    ///
264    /// If this attribute is missing a value of 'true' is assumed for backward compatibility.
265    #[serde(rename = "allThreadsContinued", default = "true_")]
266    #[builder(default)]
267    pub all_threads_continued: bool,
268
269    #[serde(skip)]
270    #[builder(default, setter(skip))]
271    private: (),
272}
273impl From<ContinueResponseBody> for SuccessResponse {
274    fn from(args: ContinueResponseBody) -> Self {
275        Self::Continue(args)
276    }
277}
278
279#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
280pub struct DataBreakpointInfoResponseBody {
281    /// An identifier for the data on which a data breakpoint can be registered with the setDataBreakpoints request or null if no data breakpoint is available.
282    #[serde(rename = "dataId")]
283    #[builder(default)]
284    pub data_id: Option<String>,
285
286    /// UI string that describes on what data the breakpoint is set on or why a data breakpoint is not available.
287    #[serde(rename = "description")]
288    pub description: String,
289
290    /// Optional attribute listing the available access types for a potential data breakpoint. A UI frontend could surface this information.
291    #[serde(rename = "accessTypes", skip_serializing_if = "Option::is_none")]
292    #[builder(default)]
293    pub access_types: Option<Vec<DataBreakpointAccessType>>,
294
295    /// Optional attribute indicating that a potential data breakpoint could be persisted across sessions.
296    #[serde(rename = "canPersist", default, skip_serializing_if = "eq_default")]
297    #[builder(default)]
298    pub can_persist: bool,
299
300    #[serde(skip)]
301    #[builder(default, setter(skip))]
302    private: (),
303}
304impl From<DataBreakpointInfoResponseBody> for SuccessResponse {
305    fn from(args: DataBreakpointInfoResponseBody) -> Self {
306        Self::DataBreakpointInfo(args)
307    }
308}
309
310#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
311pub struct DisassembleResponseBody {
312    /// The list of disassembled instructions.
313    #[serde(rename = "instructions")]
314    pub instructions: Vec<DisassembledInstruction>,
315
316    #[serde(skip)]
317    #[builder(default, setter(skip))]
318    private: (),
319}
320impl From<DisassembleResponseBody> for SuccessResponse {
321    fn from(args: DisassembleResponseBody) -> Self {
322        Self::Disassemble(args)
323    }
324}
325
326#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
327pub struct EvaluateResponseBody {
328    /// The result of the evaluate request.
329    #[serde(rename = "result")]
330    pub result: String,
331
332    /// The optional type of the evaluate result.
333    ///
334    /// This attribute should only be returned by a debug adapter if the client has passed the value true for the 'supportsVariableType' capability of the 'initialize' request.
335    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
336    #[builder(default)]
337    pub type_: Option<String>,
338
339    /// Properties of a evaluate result that can be used to determine how to render the result in the UI.
340    #[serde(rename = "presentationHint", skip_serializing_if = "Option::is_none")]
341    #[builder(default)]
342    pub presentation_hint: Option<VariablePresentationHint>,
343
344    /// If variablesReference is > 0, the evaluate result is structured and its children can be retrieved by passing variablesReference to the VariablesRequest.
345    ///
346    /// The value should be less than or equal to 2147483647 (2^31-1).
347    #[serde(rename = "variablesReference")]
348    pub variables_reference: i32,
349
350    /// The number of named child variables.
351    ///
352    /// The client can use this optional information to present the variables in a paged UI and fetch them in chunks.
353    ///
354    /// The value should be less than or equal to 2147483647 (2^31-1).
355    #[serde(rename = "namedVariables", skip_serializing_if = "Option::is_none")]
356    #[builder(default)]
357    pub named_variables: Option<i32>,
358
359    /// The number of indexed child variables.
360    ///
361    /// The client can use this optional information to present the variables in a paged UI and fetch them in chunks.
362    ///
363    /// The value should be less than or equal to 2147483647 (2^31-1).
364    #[serde(rename = "indexedVariables", skip_serializing_if = "Option::is_none")]
365    #[builder(default)]
366    pub indexed_variables: Option<i32>,
367
368    /// Optional memory reference to a location appropriate for this result.
369    ///
370    /// For pointer type eval results, this is generally a reference to the memory address contained in the pointer.
371    ///
372    /// This attribute should be returned by a debug adapter if the client has passed the value true for the 'supportsMemoryReferences' capability of the 'initialize' request.
373    #[serde(rename = "memoryReference", skip_serializing_if = "Option::is_none")]
374    #[builder(default)]
375    pub memory_reference: Option<String>,
376
377    #[serde(skip)]
378    #[builder(default, setter(skip))]
379    private: (),
380}
381impl From<EvaluateResponseBody> for SuccessResponse {
382    fn from(args: EvaluateResponseBody) -> Self {
383        Self::Evaluate(args)
384    }
385}
386
387#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
388pub struct ExceptionInfoResponseBody {
389    /// ID of the exception that was thrown.
390    #[serde(rename = "exceptionId")]
391    pub exception_id: String,
392
393    /// Descriptive text for the exception provided by the debug adapter.
394    #[serde(rename = "description", skip_serializing_if = "Option::is_none")]
395    #[builder(default)]
396    pub description: Option<String>,
397
398    /// Mode that caused the exception notification to be raised.
399    #[serde(rename = "breakMode")]
400    pub break_mode: ExceptionBreakMode,
401
402    /// Detailed information about the exception.
403    #[serde(rename = "details", skip_serializing_if = "Option::is_none")]
404    #[builder(default)]
405    pub details: Option<ExceptionDetails>,
406
407    #[serde(skip)]
408    #[builder(default, setter(skip))]
409    private: (),
410}
411impl From<ExceptionInfoResponseBody> for SuccessResponse {
412    fn from(args: ExceptionInfoResponseBody) -> Self {
413        Self::ExceptionInfo(args)
414    }
415}
416
417#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
418pub struct GotoTargetsResponseBody {
419    /// The possible goto targets of the specified location.
420    #[serde(rename = "targets")]
421    pub targets: Vec<GotoTarget>,
422
423    #[serde(skip)]
424    #[builder(default, setter(skip))]
425    private: (),
426}
427impl From<GotoTargetsResponseBody> for SuccessResponse {
428    fn from(args: GotoTargetsResponseBody) -> Self {
429        Self::GotoTargets(args)
430    }
431}
432
433#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
434pub struct LoadedSourcesResponseBody {
435    /// Set of loaded sources.
436    #[serde(rename = "sources")]
437    pub sources: Vec<Source>,
438
439    #[serde(skip)]
440    #[builder(default, setter(skip))]
441    private: (),
442}
443impl From<LoadedSourcesResponseBody> for SuccessResponse {
444    fn from(args: LoadedSourcesResponseBody) -> Self {
445        Self::LoadedSources(args)
446    }
447}
448
449#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
450pub struct ModulesResponseBody {
451    /// All modules or range of modules.
452    #[serde(rename = "modules")]
453    pub modules: Vec<Module>,
454
455    /// The total number of modules available.
456    #[serde(rename = "totalModules", skip_serializing_if = "Option::is_none")]
457    #[builder(default)]
458    pub total_modules: Option<i32>,
459
460    #[serde(skip)]
461    #[builder(default, setter(skip))]
462    private: (),
463}
464impl From<ModulesResponseBody> for SuccessResponse {
465    fn from(args: ModulesResponseBody) -> Self {
466        Self::Modules(args)
467    }
468}
469
470#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
471pub struct ReadMemoryResponseBody {
472    /// The address of the first byte of data returned.
473    ///
474    /// Treated as a hex value if prefixed with '0x', or as a decimal value otherwise.
475    #[serde(rename = "address")]
476    pub address: String,
477
478    /// The number of unreadable bytes encountered after the last successfully read byte.
479    ///
480    /// This can be used to determine the number of bytes that must be skipped before a subsequent 'readMemory' request will succeed.
481    #[serde(rename = "unreadableBytes", skip_serializing_if = "Option::is_none")]
482    #[builder(default)]
483    pub unreadable_bytes: Option<i32>,
484
485    /// The bytes read from memory, encoded using base64.
486    #[serde(rename = "data", skip_serializing_if = "Option::is_none")]
487    #[builder(default)]
488    pub data: Option<String>,
489
490    #[serde(skip)]
491    #[builder(default, setter(skip))]
492    private: (),
493}
494impl From<ReadMemoryResponseBody> for SuccessResponse {
495    fn from(args: ReadMemoryResponseBody) -> Self {
496        Self::ReadMemory(args)
497    }
498}
499
500#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
501pub struct RunInTerminalResponseBody {
502    /// The process ID. The value should be less than or equal to 2147483647 (2^31-1).
503    #[serde(rename = "processId", skip_serializing_if = "Option::is_none")]
504    #[builder(default)]
505    pub process_id: Option<i32>,
506
507    /// The process ID of the terminal shell. The value should be less than or equal to 2147483647 (2^31-1).
508    #[serde(rename = "shellProcessId", skip_serializing_if = "Option::is_none")]
509    #[builder(default)]
510    pub shell_process_id: Option<i32>,
511
512    #[serde(skip)]
513    #[builder(default, setter(skip))]
514    private: (),
515}
516impl From<RunInTerminalResponseBody> for SuccessResponse {
517    fn from(args: RunInTerminalResponseBody) -> Self {
518        Self::RunInTerminal(args)
519    }
520}
521
522#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
523pub struct ScopesResponseBody {
524    /// The scopes of the stackframe. If the array has length zero, there are no scopes available.
525    #[serde(rename = "scopes")]
526    pub scopes: Vec<Scope>,
527
528    #[serde(skip)]
529    #[builder(default, setter(skip))]
530    private: (),
531}
532impl From<ScopesResponseBody> for SuccessResponse {
533    fn from(args: ScopesResponseBody) -> Self {
534        Self::Scopes(args)
535    }
536}
537
538#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
539pub struct SetBreakpointsResponseBody {
540    /// Information about the breakpoints.
541    ///
542    /// The array elements are in the same order as the elements of the 'breakpoints' (or the deprecated 'lines') array in the arguments.
543    #[serde(rename = "breakpoints")]
544    pub breakpoints: Vec<Breakpoint>,
545
546    #[serde(skip)]
547    #[builder(default, setter(skip))]
548    private: (),
549}
550impl From<SetBreakpointsResponseBody> for SuccessResponse {
551    fn from(args: SetBreakpointsResponseBody) -> Self {
552        Self::SetBreakpoints(args)
553    }
554}
555
556#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
557pub struct SetDataBreakpointsResponseBody {
558    /// Information about the data breakpoints. The array elements correspond to the elements of the input argument 'breakpoints' array.
559    #[serde(rename = "breakpoints")]
560    pub breakpoints: Vec<Breakpoint>,
561
562    #[serde(skip)]
563    #[builder(default, setter(skip))]
564    private: (),
565}
566impl From<SetDataBreakpointsResponseBody> for SuccessResponse {
567    fn from(args: SetDataBreakpointsResponseBody) -> Self {
568        Self::SetDataBreakpoints(args)
569    }
570}
571
572#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
573pub struct SetExceptionBreakpointsResponseBody {
574    /// Information about the exception breakpoints or filters.
575    ///
576    /// The breakpoints returned are in the same order as the elements of the 'filters', 'filterOptions', 'exceptionOptions' arrays in the arguments. If both 'filters' and 'filterOptions' are given, the returned array must start with 'filters' information first, followed by 'filterOptions' information.
577    #[serde(rename = "breakpoints", skip_serializing_if = "Option::is_none")]
578    #[builder(default)]
579    pub breakpoints: Option<Vec<Breakpoint>>,
580
581    #[serde(skip)]
582    #[builder(default, setter(skip))]
583    private: (),
584}
585impl From<SetExceptionBreakpointsResponseBody> for SuccessResponse {
586    fn from(args: SetExceptionBreakpointsResponseBody) -> Self {
587        Self::SetExceptionBreakpoints(args)
588    }
589}
590
591#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
592pub struct SetExpressionResponseBody {
593    /// The new value of the expression.
594    #[serde(rename = "value")]
595    pub value: String,
596
597    /// The optional type of the value.
598    ///
599    /// This attribute should only be returned by a debug adapter if the client has passed the value true for the 'supportsVariableType' capability of the 'initialize' request.
600    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
601    #[builder(default)]
602    pub type_: Option<String>,
603
604    /// Properties of a value that can be used to determine how to render the result in the UI.
605    #[serde(rename = "presentationHint", skip_serializing_if = "Option::is_none")]
606    #[builder(default)]
607    pub presentation_hint: Option<VariablePresentationHint>,
608
609    /// If variablesReference is > 0, the value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest.
610    ///
611    /// The value should be less than or equal to 2147483647 (2^31-1).
612    #[serde(rename = "variablesReference", skip_serializing_if = "Option::is_none")]
613    #[builder(default)]
614    pub variables_reference: Option<i32>,
615
616    /// The number of named child variables.
617    ///
618    /// The client can use this optional information to present the variables in a paged UI and fetch them in chunks.
619    ///
620    /// The value should be less than or equal to 2147483647 (2^31-1).
621    #[serde(rename = "namedVariables", skip_serializing_if = "Option::is_none")]
622    #[builder(default)]
623    pub named_variables: Option<i32>,
624
625    /// The number of indexed child variables.
626    ///
627    /// The client can use this optional information to present the variables in a paged UI and fetch them in chunks.
628    ///
629    /// The value should be less than or equal to 2147483647 (2^31-1).
630    #[serde(rename = "indexedVariables", skip_serializing_if = "Option::is_none")]
631    #[builder(default)]
632    pub indexed_variables: Option<i32>,
633
634    #[serde(skip)]
635    #[builder(default, setter(skip))]
636    private: (),
637}
638impl From<SetExpressionResponseBody> for SuccessResponse {
639    fn from(args: SetExpressionResponseBody) -> Self {
640        Self::SetExpression(args)
641    }
642}
643
644#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
645pub struct SetFunctionBreakpointsResponseBody {
646    /// Information about the breakpoints. The array elements correspond to the elements of the 'breakpoints' array.
647    #[serde(rename = "breakpoints")]
648    pub breakpoints: Vec<Breakpoint>,
649
650    #[serde(skip)]
651    #[builder(default, setter(skip))]
652    private: (),
653}
654impl From<SetFunctionBreakpointsResponseBody> for SuccessResponse {
655    fn from(args: SetFunctionBreakpointsResponseBody) -> Self {
656        Self::SetFunctionBreakpoints(args)
657    }
658}
659
660#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
661pub struct SetInstructionBreakpointsResponseBody {
662    /// Information about the breakpoints. The array elements correspond to the elements of the 'breakpoints' array.
663    #[serde(rename = "breakpoints")]
664    pub breakpoints: Vec<Breakpoint>,
665
666    #[serde(skip)]
667    #[builder(default, setter(skip))]
668    private: (),
669}
670impl From<SetInstructionBreakpointsResponseBody> for SuccessResponse {
671    fn from(args: SetInstructionBreakpointsResponseBody) -> Self {
672        Self::SetInstructionBreakpoints(args)
673    }
674}
675
676#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
677pub struct SetVariableResponseBody {
678    /// The new value of the variable.
679    #[serde(rename = "value")]
680    pub value: String,
681
682    /// The type of the new value. Typically shown in the UI when hovering over the value.
683    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
684    #[builder(default)]
685    pub type_: Option<String>,
686
687    /// If variablesReference is > 0, the new value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest.
688    ///
689    /// The value should be less than or equal to 2147483647 (2^31-1).
690    #[serde(rename = "variablesReference", skip_serializing_if = "Option::is_none")]
691    #[builder(default)]
692    pub variables_reference: Option<i32>,
693
694    /// The number of named child variables.
695    ///
696    /// The client can use this optional information to present the variables in a paged UI and fetch them in chunks.
697    ///
698    /// The value should be less than or equal to 2147483647 (2^31-1).
699    #[serde(rename = "namedVariables", skip_serializing_if = "Option::is_none")]
700    #[builder(default)]
701    pub named_variables: Option<i32>,
702
703    /// The number of indexed child variables.
704    ///
705    /// The client can use this optional information to present the variables in a paged UI and fetch them in chunks.
706    ///
707    /// The value should be less than or equal to 2147483647 (2^31-1).
708    #[serde(rename = "indexedVariables", skip_serializing_if = "Option::is_none")]
709    #[builder(default)]
710    pub indexed_variables: Option<i32>,
711
712    #[serde(skip)]
713    #[builder(default, setter(skip))]
714    private: (),
715}
716impl From<SetVariableResponseBody> for SuccessResponse {
717    fn from(args: SetVariableResponseBody) -> Self {
718        Self::SetVariable(args)
719    }
720}
721
722#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
723pub struct SourceResponseBody {
724    /// Content of the source reference.
725    #[serde(rename = "content")]
726    pub content: String,
727
728    /// Optional content type (mime type) of the source.
729    #[serde(rename = "mimeType", skip_serializing_if = "Option::is_none")]
730    #[builder(default)]
731    pub mime_type: Option<String>,
732
733    #[serde(skip)]
734    #[builder(default, setter(skip))]
735    private: (),
736}
737impl From<SourceResponseBody> for SuccessResponse {
738    fn from(args: SourceResponseBody) -> Self {
739        Self::Source(args)
740    }
741}
742
743#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
744pub struct StackTraceResponseBody {
745    /// The frames of the stackframe. If the array has length zero, there are no stackframes available.
746    ///
747    /// This means that there is no location information available.
748    #[serde(rename = "stackFrames")]
749    pub stack_frames: Vec<StackFrame>,
750
751    /// The total number of frames available in the stack. If omitted or if totalFrames is larger than the available frames, a client is expected to request frames until a request returns less frames than requested (which indicates the end of the stack). Returning monotonically increasing totalFrames values for subsequent requests can be used to enforce paging in the client.
752    #[serde(rename = "totalFrames", skip_serializing_if = "Option::is_none")]
753    #[builder(default)]
754    pub total_frames: Option<i32>,
755
756    #[serde(skip)]
757    #[builder(default, setter(skip))]
758    private: (),
759}
760impl From<StackTraceResponseBody> for SuccessResponse {
761    fn from(args: StackTraceResponseBody) -> Self {
762        Self::StackTrace(args)
763    }
764}
765
766#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
767pub struct StepInTargetsResponseBody {
768    /// The possible stepIn targets of the specified source location.
769    #[serde(rename = "targets")]
770    pub targets: Vec<StepInTarget>,
771
772    #[serde(skip)]
773    #[builder(default, setter(skip))]
774    private: (),
775}
776impl From<StepInTargetsResponseBody> for SuccessResponse {
777    fn from(args: StepInTargetsResponseBody) -> Self {
778        Self::StepInTargets(args)
779    }
780}
781
782#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
783pub struct ThreadsResponseBody {
784    /// All threads.
785    #[serde(rename = "threads")]
786    pub threads: Vec<Thread>,
787
788    #[serde(skip)]
789    #[builder(default, setter(skip))]
790    private: (),
791}
792impl From<ThreadsResponseBody> for SuccessResponse {
793    fn from(args: ThreadsResponseBody) -> Self {
794        Self::Threads(args)
795    }
796}
797
798#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TypedBuilder)]
799pub struct VariablesResponseBody {
800    /// All (or a range) of variables for the given variable reference.
801    #[serde(rename = "variables")]
802    pub variables: Vec<Variable>,
803
804    #[serde(skip)]
805    #[builder(default, setter(skip))]
806    private: (),
807}
808impl From<VariablesResponseBody> for SuccessResponse {
809    fn from(args: VariablesResponseBody) -> Self {
810        Self::Variables(args)
811    }
812}
813
814// Workaround from https://stackoverflow.com/a/65576570
815// for https://github.com/serde-rs/serde/issues/745
816
817fn deserialize_response_result<'de, D>(
818    deserializer: D,
819) -> Result<Result<SuccessResponse, ErrorResponse>, D::Error>
820where
821    D: Deserializer<'de>,
822{
823    let value = Value::deserialize(deserializer)?;
824
825    let success = value
826        .get("success")
827        .ok_or_else(|| Error::missing_field("success"))?
828        .as_bool()
829        .ok_or_else(|| Error::invalid_type(unexpected_value(&value), &"success bool"))?;
830
831    Ok(if success {
832        Ok(Deserialize::deserialize(value).map_err(|e| Error::custom(e.to_string()))?)
833    } else {
834        Err(Deserialize::deserialize(value).map_err(|e| Error::custom(e.to_string()))?)
835    })
836}
837
838fn unexpected_value<'l>(value: &'l Value) -> Unexpected<'l> {
839    match value {
840        Value::Null => Unexpected::Other("null"),
841        Value::Bool(b) => Unexpected::Bool(*b),
842        Value::Number(n) => unexpected_number(n),
843        Value::String(s) => Unexpected::Str(s),
844        Value::Array(_) => Unexpected::Seq,
845        Value::Object(_) => Unexpected::Map,
846    }
847}
848
849fn unexpected_number(number: &Number) -> Unexpected<'static> {
850    if number.is_f64() {
851        return Unexpected::Float(number.as_f64().unwrap());
852    }
853    if number.is_u64() {
854        return Unexpected::Unsigned(number.as_u64().unwrap());
855    }
856    if number.is_i64() {
857        return Unexpected::Signed(number.as_i64().unwrap());
858    }
859    panic!("Unknown number {}", number)
860}
861
862fn serialize_response_result<S>(
863    result: &Result<SuccessResponse, ErrorResponse>,
864    serializer: S,
865) -> Result<S::Ok, S::Error>
866where
867    S: Serializer,
868{
869    #[derive(Clone, Serialize)]
870    #[serde(untagged)]
871    enum Content<'l> {
872        Success(&'l SuccessResponse),
873        Error(&'l ErrorResponse),
874    }
875
876    #[derive(Clone, Serialize)]
877    struct TaggedContent<'l> {
878        success: bool,
879        #[serde(flatten)]
880        content: Content<'l>,
881    }
882
883    let serializable = match result {
884        Ok(response) => TaggedContent {
885            success: true,
886            content: Content::Success(response),
887        },
888        Err(response) => TaggedContent {
889            success: false,
890            content: Content::Error(response),
891        },
892    };
893    serializable.serialize(serializer)
894}