Skip to main content

dap/
responses.rs

1#[cfg(feature = "integration_testing")]
2use fake::Dummy;
3#[cfg(feature = "client")]
4use serde::Deserialize;
5use serde::Serialize;
6
7use crate::types::{
8    Breakpoint, BreakpointLocation, Capabilities, CompletionItem, DataBreakpointAccessType,
9    DisassembledInstruction, ExceptionBreakMode, ExceptionDetails, GotoTarget, Message, Module,
10    Scope, Source, StackFrame, Thread, Variable, VariablePresentationHint,
11};
12
13/// Represents a response message that is either a cancellation or a short error string.
14#[derive(Serialize, Debug, Clone)]
15#[serde(rename_all = "camelCase")]
16#[cfg_attr(feature = "client", derive(Deserialize))]
17#[cfg_attr(feature = "integration_testing", derive(Dummy))]
18pub enum ResponseMessage {
19    /// Should be sent when the request was canceled
20    Cancelled,
21    /// The request may be retried once the adapter is in a 'stopped' state.
22    NotStopped,
23    /// Contains the raw error in short form if [`Response::success`](Response::success) is false.
24    /// This raw error might be interpreted by the client and is not shown in the UI.
25    #[serde(untagged)]
26    Error(String),
27}
28
29#[derive(Serialize, Debug, Default, Clone)]
30#[serde(rename_all = "camelCase")]
31#[cfg_attr(feature = "client", derive(Deserialize))]
32#[cfg_attr(feature = "integration_testing", derive(Dummy))]
33pub struct BreakpointLocationsResponse {
34    /// Sorted set of possible breakpoint locations.
35    pub breakpoints: Vec<BreakpointLocation>,
36}
37
38#[derive(Serialize, Debug, Default, Clone)]
39#[serde(rename_all = "camelCase")]
40#[cfg_attr(feature = "client", derive(Deserialize))]
41#[cfg_attr(feature = "integration_testing", derive(Dummy))]
42pub struct CompletionsResponse {
43    /// The possible completions
44    pub targets: Vec<CompletionItem>,
45}
46
47#[derive(Serialize, Debug, Default, Clone)]
48#[serde(rename_all = "camelCase")]
49#[cfg_attr(feature = "client", derive(Deserialize))]
50#[cfg_attr(feature = "integration_testing", derive(Dummy))]
51pub struct ContinueResponse {
52    /// The value true (or a missing property) signals to the client that all
53    /// threads have been resumed. The value false indicates that not all threads
54    /// were resumed.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub all_threads_continued: Option<bool>,
57}
58
59#[derive(Serialize, Debug, Default, Clone)]
60#[serde(rename_all = "camelCase")]
61#[cfg_attr(feature = "client", derive(Deserialize))]
62#[cfg_attr(feature = "integration_testing", derive(Dummy))]
63pub struct DataBreakpointInfoResponse {
64    /// An identifier for the data on which a data breakpoint can be registered
65    /// with the `setDataBreakpoints` request or null if no data breakpoint is
66    /// available. If a `variablesReference` or `frameId` is passed, the `dataId`
67    /// is valid in the current suspended state, otherwise it's valid
68    /// indefinitely. See 'Lifetime of Object References' in the Overview section
69    /// for details. Breakpoints set using the `dataId` in the
70    /// `setDataBreakpoints` request may outlive the lifetime of the associated
71    /// `dataId`.
72    pub data_id: Option<String>,
73    /// UI String that describes on what data the breakpoint is set on or why a
74    /// data breakpoint is not available.
75    pub description: String,
76    /// Attribute lists the available access types for a potential data
77    /// breakpoint. A UI client could surface this information.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub access_types: Option<Vec<DataBreakpointAccessType>>,
80    /// Attribute indicates that a potential data breakpoint could be persisted
81    /// across sessions.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub can_persist: Option<bool>,
84}
85
86#[derive(Serialize, Debug, Default, Clone)]
87#[serde(rename_all = "camelCase")]
88#[cfg_attr(feature = "client", derive(Deserialize))]
89#[cfg_attr(feature = "integration_testing", derive(Dummy))]
90pub struct DisassembleResponse {
91    /// The list of disassembled instructions.
92    pub instructions: Vec<DisassembledInstruction>,
93}
94
95#[derive(Serialize, Debug, Default, Clone)]
96#[serde(rename_all = "camelCase")]
97#[cfg_attr(feature = "client", derive(Deserialize))]
98#[cfg_attr(feature = "integration_testing", derive(Dummy))]
99pub struct EvaluateResponse {
100    /// The result of the evaluate request.
101    pub result: String,
102    /// The type of the evaluate result.
103    /// This attribute should only be returned by a debug adapter if the
104    /// corresponding capability `supportsVariableType` is true.
105    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
106    pub type_field: Option<String>,
107    /// Properties of an evaluate result that can be used to determine how to
108    /// render the result in the UI.
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub presentation_hint: Option<VariablePresentationHint>,
111    /// If `variablesReference` is > 0, the evaluate result is structured and its
112    /// children can be retrieved by passing `variablesReference` to the
113    /// `variables` request.
114    /// The value should be less than or equal to 2147483647 (2^31-1).
115    /// See [Lifetime of Object References](https://microsoft.github.io/debug-adapter-protocol/overview#lifetime-of-objects-references)
116    /// in the Overview section of the specification for details.
117    pub variables_reference: i64,
118    /// The i64 of named child variables.
119    /// The client can use this information to present the variables in a paged
120    /// UI and fetch them in chunks.
121    /// The value should be less than or equal to 2147483647 (2^31-1).
122    #[serde(skip_serializing_if = "Option::is_none")]
123    pub named_variables: Option<i64>,
124    /// The i64 of indexed child variables.
125    /// The client can use this information to present the variables in a paged
126    /// UI and fetch them in chunks.
127    /// The value should be less than or equal to 2147483647 (2^31-1).
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub indexed_variables: Option<i64>,
130    /// A memory reference to a location appropriate for this result.
131    /// For pointer type eval results, this is generally a reference to the
132    /// memory address contained in the pointer.
133    /// This attribute should be returned by a debug adapter if corresponding
134    /// capability `supportsMemoryReferences` is true.
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub memory_reference: Option<String>,
137}
138
139#[derive(Serialize, Debug, Clone, Default)]
140#[serde(rename_all = "camelCase")]
141#[cfg_attr(feature = "client", derive(Deserialize))]
142#[cfg_attr(feature = "integration_testing", derive(Dummy))]
143pub struct ExceptionInfoResponse {
144    /// ID of the exception that was thrown.
145    pub exception_id: String,
146    /// Descriptive text for the exception.
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub description: Option<String>,
149    /// Mode that caused the exception notification to be raised.
150    pub break_mode: ExceptionBreakMode,
151    /// Detailed information about the exception.
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub details: Option<ExceptionDetails>,
154}
155
156#[derive(Serialize, Debug, Default, Clone)]
157#[serde(rename_all = "camelCase")]
158#[cfg_attr(feature = "client", derive(Deserialize))]
159#[cfg_attr(feature = "integration_testing", derive(Dummy))]
160pub struct GotoTargetsResponse {
161    /// The possible goto targets of the specified location.
162    pub targets: Vec<GotoTarget>,
163}
164
165#[derive(Serialize, Debug, Default, Clone)]
166#[serde(rename_all = "camelCase")]
167#[cfg_attr(feature = "client", derive(Deserialize))]
168#[cfg_attr(feature = "integration_testing", derive(Dummy))]
169pub struct LoadedSourcesResponse {
170    /// Set of loaded sources.
171    pub sources: Vec<Source>,
172}
173
174#[derive(Serialize, Debug, Default, Clone)]
175#[serde(rename_all = "camelCase")]
176#[cfg_attr(feature = "client", derive(Deserialize))]
177#[cfg_attr(feature = "integration_testing", derive(Dummy))]
178pub struct ModulesResponse {
179    /// All modules or range of modules.
180    pub modules: Vec<Module>,
181    /// The total i64 of modules available.
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub total_modules: Option<i64>,
184}
185
186#[derive(Serialize, Debug, Default, Clone)]
187#[serde(rename_all = "camelCase")]
188#[cfg_attr(feature = "client", derive(Deserialize))]
189#[cfg_attr(feature = "integration_testing", derive(Dummy))]
190pub struct ReadMemoryResponse {
191    /// The address of the first byte of data returned.
192    /// Treated as a hex value if prefixed with `0x`, or as a decimal value
193    /// otherwise.
194    pub address: String,
195    /// The i64 of unreadable bytes encountered after the last successfully
196    /// read byte.
197    /// This can be used to determine the i64 of bytes that should be skipped
198    /// before a subsequent `readMemory` request succeeds.
199    #[serde(skip_serializing_if = "Option::is_none")]
200    pub unreadable_bytes: Option<i64>,
201    /// The bytes read from memory, encoded using base64.
202    #[serde(skip_serializing_if = "Option::is_none")]
203    pub data: Option<String>,
204}
205
206#[derive(Serialize, Debug, Default, Clone)]
207#[serde(rename_all = "camelCase")]
208#[cfg_attr(feature = "client", derive(Deserialize))]
209#[cfg_attr(feature = "integration_testing", derive(Dummy))]
210pub struct ScopesResponse {
211    /// The scopes of the stackframe. If the array has length zero, there are no
212    /// scopes available.
213    pub scopes: Vec<Scope>,
214}
215
216#[derive(Serialize, Debug, Default, Clone)]
217#[serde(rename_all = "camelCase")]
218#[cfg_attr(feature = "client", derive(Deserialize))]
219#[cfg_attr(feature = "integration_testing", derive(Dummy))]
220pub struct SetBreakpointsResponse {
221    /// Information about the breakpoints.
222    /// The array elements are in the same order as the elements of the
223    /// `breakpoints` (or the deprecated `lines`) array in the arguments.
224    pub breakpoints: Vec<Breakpoint>,
225}
226
227#[derive(Serialize, Debug, Default, Clone)]
228#[serde(rename_all = "camelCase")]
229#[cfg_attr(feature = "client", derive(Deserialize))]
230#[cfg_attr(feature = "integration_testing", derive(Dummy))]
231pub struct SetDataBreakpointsResponse {
232    /// Information about the breakpoints.
233    /// The array elements are in the same order as the elements of the `breakpoints` array
234    /// in the arguments.
235    pub breakpoints: Vec<Breakpoint>,
236}
237
238#[derive(Serialize, Debug, Default, Clone)]
239#[serde(rename_all = "camelCase")]
240#[cfg_attr(feature = "client", derive(Deserialize))]
241#[cfg_attr(feature = "integration_testing", derive(Dummy))]
242pub struct SetExceptionBreakpointsResponse {
243    /// Information about the exception breakpoints or filters.
244    /// The breakpoints returned are in the same order as the elements of the
245    /// `filters`, `filterOptions`, `exceptionOptions` arrays in the arguments.
246    /// If both `filters` and `filterOptions` are given, the returned array must
247    /// start with `filters` information first, followed by `filterOptions`
248    /// information.
249    #[serde(skip_serializing_if = "Option::is_none")]
250    pub breakpoints: Option<Vec<Breakpoint>>,
251}
252
253#[derive(Serialize, Debug, Default, Clone)]
254#[serde(rename_all = "camelCase")]
255#[cfg_attr(feature = "client", derive(Deserialize))]
256#[cfg_attr(feature = "integration_testing", derive(Dummy))]
257pub struct SetFunctionBreakpointsResponse {
258    /// Information about the breakpoints. The array elements correspond to the
259    /// elements of the `breakpoints` array.
260    pub breakpoints: Vec<Breakpoint>,
261}
262
263#[derive(Serialize, Debug, Default, Clone)]
264#[serde(rename_all = "camelCase")]
265#[cfg_attr(feature = "client", derive(Deserialize))]
266#[cfg_attr(feature = "integration_testing", derive(Dummy))]
267pub struct SetInstructionBreakpointsResponse {
268    /// Information about the breakpoints. The array elements correspond to the
269    /// elements of the `breakpoints` array.
270    pub breakpoints: Vec<Breakpoint>,
271}
272
273#[derive(Serialize, Debug, Default, Clone)]
274#[serde(rename_all = "camelCase")]
275#[cfg_attr(feature = "client", derive(Deserialize))]
276#[cfg_attr(feature = "integration_testing", derive(Dummy))]
277pub struct SetVariableResponse {
278    /// The new value of the variable.
279    pub value: String,
280    /// The type of the new value. Typically shown in the UI when hovering over
281    /// the value.
282    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
283    pub type_field: Option<String>,
284    /// If `variablesReference` is > 0, the new value is structured and its
285    /// children can be retrieved by passing `variablesReference` to the
286    /// `variables` request.
287    /// The value should be less than or equal to 2147483647 (2^31-1).
288    /// See [Lifetime of Object References](https://microsoft.github.io/debug-adapter-protocol/overview#lifetime-of-objects-references)
289    /// in the Overview section of the specification for details.
290    #[serde(skip_serializing_if = "Option::is_none")]
291    pub variables_reference: Option<i64>,
292    /// The number of named child variables.
293    /// The client can use this information to present the variables in a paged
294    /// UI and fetch them in chunks.
295    /// The value should be less than or equal to 2147483647 (2^31-1).
296    #[serde(skip_serializing_if = "Option::is_none")]
297    pub named_variables: Option<i32>,
298    /// The number of indexed child variables.
299    /// The client can use this information to present the variables in a paged
300    /// UI and fetch them in chunks.
301    /// The value should be less than or equal to 2147483647 (2^31-1).
302    #[serde(skip_serializing_if = "Option::is_none")]
303    pub indexed_variables: Option<i32>,
304}
305
306#[derive(Serialize, Debug, Default, Clone)]
307#[serde(rename_all = "camelCase")]
308#[cfg_attr(feature = "client", derive(Deserialize))]
309#[cfg_attr(feature = "integration_testing", derive(Dummy))]
310pub struct SourceResponse {
311    /// Content of the source reference.
312    pub content: String,
313    /// Content type (MIME type) of the source.
314    #[serde(skip_serializing_if = "Option::is_none")]
315    pub mime_type: Option<String>,
316}
317
318#[derive(Serialize, Debug, Default, Clone)]
319#[serde(rename_all = "camelCase")]
320#[cfg_attr(feature = "client", derive(Deserialize))]
321#[cfg_attr(feature = "integration_testing", derive(Dummy))]
322pub struct SetExpressionResponse {
323    /// The new value of the expression.
324    pub value: String,
325    /// The type of the value.
326    /// This attribute should only be returned by a debug adapter if the
327    /// corresponding capability `supportsVariableType` is true.
328    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
329    pub type_field: Option<String>,
330    /// Properties of a value that can be used to determine how to render the
331    /// result in the UI.
332    #[serde(skip_serializing_if = "Option::is_none")]
333    pub presentation_hint: Option<VariablePresentationHint>,
334    /// If `variablesReference` is > 0, the value is structured and its children
335    /// can be retrieved by passing `variablesReference` to the `variables`
336    /// request.
337    /// The value should be less than or equal to 2147483647 (2^31-1).
338    /// See [Lifetime of Object References](https://microsoft.github.io/debug-adapter-protocol/overview#lifetime-of-objects-references)
339    /// in the Overview section of the specification for details.
340    #[serde(skip_serializing_if = "Option::is_none")]
341    pub variables_reference: Option<i64>,
342    /// The number of named child variables.
343    /// The client can use this information to present the variables in a paged
344    /// UI and fetch them in chunks.
345    /// The value should be less than or equal to 2147483647 (2^31-1).
346    #[serde(skip_serializing_if = "Option::is_none")]
347    pub named_variables: Option<i32>,
348    /// The number of indexed child variables.
349    /// The client can use this information to present the variables in a paged
350    /// UI and fetch them in chunks.
351    /// The value should be less than or equal to 2147483647 (2^31-1).
352    #[serde(skip_serializing_if = "Option::is_none")]
353    pub indexed_variables: Option<i32>,
354}
355
356#[derive(Serialize, Debug, Default, Clone)]
357#[serde(rename_all = "camelCase")]
358#[cfg_attr(feature = "client", derive(Deserialize))]
359#[cfg_attr(feature = "integration_testing", derive(Dummy))]
360pub struct StackTraceResponse {
361    /// The frames of the stackframe. If the array has length zero, there are no
362    /// stackframes available.
363    /// This means that there is no location information available.
364    pub stack_frames: Vec<StackFrame>,
365    /// The total i64 of frames available in the stack. If omitted or if
366    /// `totalFrames` is larger than the available frames, a client is expected
367    /// to request frames until a request returns less frames than requested
368    /// (which indicates the end of the stack). Returning monotonically
369    /// increasing `totalFrames` values for subsequent requests can be used to
370    /// enforce paging in the client.
371    #[serde(skip_serializing_if = "Option::is_none")]
372    pub total_frames: Option<i64>,
373}
374
375#[derive(Serialize, Debug, Default, Clone)]
376#[serde(rename_all = "camelCase")]
377#[cfg_attr(feature = "client", derive(Deserialize))]
378#[cfg_attr(feature = "integration_testing", derive(Dummy))]
379pub struct ThreadsResponse {
380    /// All threads.
381    pub threads: Vec<Thread>,
382}
383
384#[derive(Serialize, Debug, Default, Clone)]
385#[serde(rename_all = "camelCase")]
386#[cfg_attr(feature = "client", derive(Deserialize))]
387#[cfg_attr(feature = "integration_testing", derive(Dummy))]
388pub struct VariablesResponse {
389    /// All (or a range) of variables for the given variable reference.
390    pub variables: Vec<Variable>,
391}
392
393#[derive(Serialize, Debug, Default, Clone)]
394#[serde(rename_all = "camelCase")]
395#[cfg_attr(feature = "client", derive(Deserialize))]
396#[cfg_attr(feature = "integration_testing", derive(Dummy))]
397pub struct WriteMemoryResponse {
398    /// Property that should be returned when `allowPartial` is true to indicate
399    /// the offset of the first byte of data successfully written. Can be
400    /// negative.
401    #[serde(skip_serializing_if = "Option::is_none")]
402    pub offset: Option<i64>,
403    /// Property that should be returned when `allowPartial` is true to indicate
404    /// the i64 of bytes starting from address that were successfully written.
405    #[serde(skip_serializing_if = "Option::is_none")]
406    pub bytes_written: Option<i64>,
407}
408
409#[derive(Serialize, Debug, Clone)]
410#[serde(tag = "command", content = "body", rename_all = "camelCase")]
411#[cfg_attr(feature = "client", derive(Deserialize))]
412#[cfg_attr(feature = "integration_testing", derive(Dummy))]
413pub enum ResponseBody {
414    /// Response to attach request. This is just an acknowledgement, so no body field is required.
415    ///
416    /// Specification: [Attach request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Attach)
417    Attach,
418    /// Response to breakpointLocations request.  Contains possible locations for source breakpoints.
419    ///
420    /// Specification: [BreakpointLocations request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_BreakpointLocations)
421    BreakpointLocations(BreakpointLocationsResponse),
422    /// Response to a `completions` request
423    ///
424    /// Specification: [Completions request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Completions)
425    Completions(CompletionsResponse),
426    /// Response to `configurationDone` request. This is just an acknowledgement, so no body field is
427    /// required.
428    ///
429    /// Specification: [ConfigurationDone request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ConfigurationDone)
430    ConfigurationDone,
431    /// Response to `continue` request.
432    ///
433    /// Specification: [Continue request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Continue)
434    Continue(ContinueResponse),
435    /// Response to `dataBreakpointInfo` request.
436    ///
437    /// Specification: [DataBreakpointInfo request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_DataBreakpointInfo)
438    DataBreakpointInfo(DataBreakpointInfoResponse),
439    /// Response to `disassemble` request.
440    ///
441    /// NOTE: we are straying away from the spec here, as the spec says that the response body is
442    /// optional, but we are always returning a body because I could not find a way to express
443    /// skipping the optional body with serde (and serializing null will make the schema validation
444    /// complain).
445    ///
446    /// Specification: [Disassembly request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disassemble)
447    Disassemble(DisassembleResponse),
448    /// Response to disconnect request. This is just an acknowledgement, so no body field is required.
449    ///
450    /// Specification: [Disconnect request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disconnect)
451    Disconnect,
452    /// Response to `evaluate` request.
453    ///
454    /// Specification: [Evaluate request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Evaluate)
455    Evaluate(EvaluateResponse),
456    /// Response to `exceptionInfo` request.
457    ///
458    /// Specification: [ExceptionInfo](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ExceptionInfo)
459    ExceptionInfo(ExceptionInfoResponse),
460    /// Response to `goto` request. This is just an acknowledgement, so no body field is required.
461    ///
462    /// Specification: [Goto request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Goto)
463    Goto,
464    /// Response to `gotoTargets` request.
465    ///
466    /// Specification: [GotoTargets request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_GotoTargets)
467    GotoTargets(GotoTargetsResponse),
468    /// Response to `initialize` request.
469    ///
470    /// NOTE: we are straying away from the spec here, as the spec says that the response body is
471    /// optional, but we are always returning a body because I could not find a way to express
472    /// skipping the optional body with serde (and serializing null will make the schema validation
473    /// complain).
474    ///
475    /// Specification: [Initialize request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize)
476    Initialize(Capabilities),
477    /// Response to launch request. This is just an acknowledgement, so no body field is required.
478    ///
479    /// Specification: [Launch request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Launch)
480    Launch,
481    /// Response to `loadedSources` request.
482    ///
483    /// Specification: [LoadedSources request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_LoadedSources)
484    LoadedSources(LoadedSourcesResponse),
485    /// Response to `modules` request.
486    ///
487    /// Specification: [Modules request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Modules)
488    Modules(ModulesResponse),
489    /// Response to next request. This is just an acknowledgement, so no body field is required.
490    ///
491    /// Specification: [Next request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Next)
492    Next,
493    /// Response to `pause` request. This is just an acknowledgement, so no body field is required.
494    ///
495    /// Specification: [Pause request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Pause)
496    Pause,
497    /// Response to readMemory request.
498    ///
499    /// NOTE: we are straying away from the spec here, as the spec says that the response body is
500    /// optional, but we are always returning a body because I could not find a way to express
501    /// skipping the optional body with serde (and serializing null will make the schema validation
502    /// complain).
503    ///
504    /// Specification: [ReadMemory request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ReadMemory)
505    ReadMemory(ReadMemoryResponse),
506    /// Response to `restart` request. This is just an acknowledgement, so no body field is required.
507    ///
508    /// Specification: [Restart request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Restart)
509    Restart,
510    /// Response to `restartFrame` request. This is just an acknowledgement, so no body field is
511    /// required.
512    ///
513    /// Specification: [RestartFrame request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_RestartFrame)
514    RestartFrame,
515    /// Response to `reverseContinue` request. This is just an acknowledgement, so no body field is
516    /// required.
517    ///
518    /// Specification: [ReverseContinue request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ReverseContinue)
519    ReverseContinue,
520    /// Response to scopes request.
521    ///
522    /// Specification: [Scopes request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Scopes)
523    Scopes(ScopesResponse),
524    /// Response to setBreakpoints request.
525    /// Returned is information about each breakpoint created by this request.
526    /// This includes the actual code location and whether the breakpoint could be verified.
527    /// The breakpoints returned are in the same order as the elements of the breakpoints
528    /// (or the deprecated lines) array in the arguments.
529    ///
530    /// Specification: [SetBreakpointsRequest](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetBreakpoints)
531    SetBreakpoints(SetBreakpointsResponse),
532    /// Replaces all existing data breakpoints with new data breakpoints.
533    /// To clear all data breakpoints, specify an empty array.
534    /// When a data breakpoint is hit, a `stopped` event (with reason `date breakpoint`) is generated.
535    /// Clients should only call this request if the corresponding capability
536    /// `supportsDataBreakpoints` is true.
537    ///
538    /// Specification: [SetDataBreakpoints request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetDataBreakpoints)
539    SetDataBreakpoints(SetDataBreakpointsResponse),
540    /// Response to `setExceptionBreakpoint` request.
541    ///
542    /// The response contains an array of `Breakpoint` objects with information about each exception
543    /// breakpoint or filter. The Breakpoint objects are in the same order as the elements of the
544    /// `filters`, `filterOptions`, `exceptionOptions` arrays given as arguments. If both `filters`
545    /// and `filterOptions` are given, the returned array must start with filters information first,
546    /// followed by `filterOptions` information.
547    ///
548    /// The `verified` property of a `Breakpoint` object signals whether the exception breakpoint or
549    /// filter could be successfully created and whether the condition or hit count expressions are
550    /// valid. In case of an error the message property explains the problem. The id property can be
551    /// used to introduce a unique ID for the exception breakpoint or filter so that it can be
552    /// updated subsequently by sending breakpoint events.
553    ///
554    /// For backward compatibility both the `breakpoints` array and the enclosing body are optional.
555    /// If these elements are missing a client is not able to show problems for individual exception
556    /// breakpoints or filters.
557    ///
558    /// NOTE: we are straying away from the spec here, as the spec says that the response body is
559    /// optional, but we are always returning a body because I could not find a way to express
560    /// skipping the optional body with serde (and serializing null will make the schema validation
561    /// complain).
562    SetExceptionBreakpoints(SetExceptionBreakpointsResponse),
563    /// Response to setExpression request.
564    ///
565    /// Specification: [SetExpression request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetExpression)
566    SetExpression(SetExpressionResponse),
567    /// Response to setFunctionBreakpoints request.
568    /// Returned is information about each breakpoint created by this request.
569    ///
570    /// Specification: [SetFunctionBreakpointsArguments](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetFunctionBreakpoints)
571    SetFunctionBreakpoints(SetFunctionBreakpointsResponse),
572    /// Response to `setInstructionBreakpoints` request
573    ///
574    /// Specification: [SetInstructionBreakpoints request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetInstructionBreakpoints)
575    SetInstructionBreakpoints(SetInstructionBreakpointsResponse),
576    /// Response to `setVariable` request.
577    ///
578    /// Specification: [SetVariable request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetVariable)
579    SetVariable(SetVariableResponse),
580    /// Response to `source` request.
581    ///
582    /// Specification: [Sources request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Source)
583    Source(SourceResponse),
584    /// Response to stackTrace request.
585    ///
586    /// Specification: [StackTrace request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StackTrace)
587    StackTrace(StackTraceResponse),
588    /// Response to `stepBack` request. This is just an acknowledgement, so no body field is required.
589    ///
590    /// Specification: [StepBack request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepBack)
591    StepBack,
592    /// Response to `stepIn` request. This is just an acknowledgement, so no body field is required.
593    ///
594    /// Specification: [StepIn request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepIn)
595    StepIn,
596    /// Response to `stepOut` request. This is just an acknowledgement, so no body field is required.
597    ///
598    /// Specification: [StepOut request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepOut)
599    StepOut,
600    /// Response to `terminate` request. This is just an acknowledgement, so no body field is required.
601    ///
602    /// Specification: [Terminate request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Terminate)
603    Terminate,
604    /// Response to `terminateThreads` request. This is just an acknowledgement, so no body field is
605    /// required.
606    ///
607    /// Specification: [TerminateThreads request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_TerminateThreads)
608    TerminateThreads,
609    /// Response to threads request.
610    ///
611    /// Specification: [Threads request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Threads)
612    Threads(ThreadsResponse),
613    /// Response to `variables` request.
614    ///
615    /// Specification: [Variables request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Variables)
616    Variables(VariablesResponse),
617    /// Response to `writeMemory` request.
618    ///
619    /// NOTE: we are straying away from the spec here, as the spec says that the response body is
620    /// optional, but we are always returning a body because I could not find a way to express
621    /// skipping the optional body with serde (and serializing null will make the schema validation
622    /// complain).
623    ///
624    /// Specification: [WriteMemory request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_WriteMemory)
625    WriteMemory(WriteMemoryResponse),
626}
627
628/// Represents response to the client.
629///
630/// The command field (which is a string) is used as a tag in the ResponseBody enum, so users
631/// of this crate will control it by selecting the appropriate enum variant for the body.
632///
633/// There is also no separate `ErrorResponse` struct. Instead, `Error` is just a variant of the
634/// ResponseBody enum.
635///
636/// Specification: [Response](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Response)
637#[derive(Serialize, Debug, Default, Clone)]
638#[serde(rename_all = "camelCase")]
639#[cfg_attr(feature = "client", derive(Deserialize))]
640#[cfg_attr(feature = "integration_testing", derive(Dummy))]
641pub struct Response {
642    /// Sequence number of the corresponding request.
643    #[serde(rename = "request_seq")]
644    pub request_seq: i64,
645    /// Outcome of the request.
646    /// If true, the request was successful and the `body` attribute may contain
647    /// the result of the request.
648    /// If the value is false, the attribute `message` contains the error in short
649    /// form and the `body` may contain additional information (see
650    /// `ErrorResponse.body.error`).
651    pub success: bool,
652    /// Contains the raw error in short form if `success` is false.
653    /// This raw error might be interpreted by the client and is not shown in the
654    /// UI.
655    /// Some predefined values exist.
656    /// Values:
657    /// 'cancelled': request was cancelled.
658    /// etc.
659    #[serde(skip_serializing_if = "Option::is_none")]
660    pub message: Option<ResponseMessage>,
661    /// Contains request result if success is true and error details if success is
662    /// false.
663    #[serde(flatten, skip_serializing_if = "Option::is_none")]
664    pub body: Option<ResponseBody>,
665    /// A structured error message.
666    pub error: Option<Message>,
667}
668
669#[cfg(test)]
670mod test {
671    use super::*;
672
673    #[test]
674    fn test_responsemessage_is_flattened() {
675        let a = Response {
676            request_seq: 1,
677            success: false,
678            message: Some(ResponseMessage::Error("test".to_string())),
679            body: None,
680            error: None,
681        };
682        let val = serde_json::to_value(a).unwrap();
683
684        assert!(val.get("message").unwrap().is_string());
685        assert!(val.get("message").unwrap().as_str().unwrap() == "test");
686        assert!(!val.get("message").unwrap().is_object());
687
688        let a = Response {
689            request_seq: 1,
690            success: false,
691            message: Some(ResponseMessage::Cancelled),
692            body: None,
693            error: None,
694        };
695        let val = serde_json::to_value(a).unwrap();
696        assert!(val.get("message").unwrap().is_string());
697        assert!(val.get("message").unwrap().as_str().unwrap() == "cancelled");
698
699        let a = Response {
700            request_seq: 1,
701            success: false,
702            message: Some(ResponseMessage::NotStopped),
703            body: None,
704            error: None,
705        };
706        let val = serde_json::to_value(a).unwrap();
707        assert!(val.get("message").unwrap().is_string());
708        assert!(val.get("message").unwrap().as_str().unwrap() == "notStopped");
709    }
710}