dap/requests.rs
1use serde::Deserialize;
2#[cfg(feature = "client")]
3use serde::Serialize;
4use serde_json::Value;
5
6use crate::{
7 errors::ServerError,
8 prelude::{Response, ResponseBody},
9 responses::ResponseMessage,
10 types::{
11 DataBreakpoint, EvaluateArgumentsContext, ExceptionFilterOptions, ExceptionOptions,
12 FunctionBreakpoint, InstructionBreakpoint, Source, SourceBreakpoint, StackFrameFormat,
13 SteppingGranularity, ValueFormat, VariablesArgumentsFilter,
14 },
15};
16
17#[cfg_attr(feature = "client", derive(Serialize))]
18#[derive(Deserialize, Debug, Clone)]
19#[serde(rename_all = "camelCase")]
20pub enum PathFormat {
21 Path,
22 Uri,
23 #[serde(untagged)]
24 Other(String),
25}
26
27/// Arguments for an Initialize request.
28/// In specification: [Initialize](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize)
29#[cfg_attr(feature = "client", derive(Serialize))]
30#[derive(Deserialize, Debug, Default, Clone)]
31#[serde(rename_all = "camelCase")]
32pub struct InitializeArguments {
33 /// The ID of the client using this adapter.
34 #[serde(rename = "clientID")]
35 pub client_id: Option<String>,
36 /// The human-readable name of the client using this adapter.
37 pub client_name: Option<String>,
38 /// The ID of the debug adapter.
39 #[serde(rename = "adapterID")]
40 pub adapter_id: String,
41 /// The ISO-639 locale of the client using this adapter, e.g. en-US or de-CH.
42 pub locale: Option<String>,
43 /// If true all line i64s are 1-based (default).
44 pub lines_start_at1: Option<bool>,
45 /// If true all column i64s are 1-based (default).
46 pub columns_start_at1: Option<bool>,
47 /// Determines in what format paths are specified. The default is `path`, which
48 /// is the native format.
49 pub path_format: Option<PathFormat>,
50 /// Client supports the `type` attribute for variables.
51 pub supports_variable_type: Option<bool>,
52 /// Client supports the paging of variables.
53 pub supports_variable_paging: Option<bool>,
54 /// Client supports the `runInTerminal` request.
55 pub supports_run_in_terminal_request: Option<bool>,
56 /// Client supports memory references.
57 pub supports_memory_references: Option<bool>,
58 /// Client supports progress reporting.
59 pub supports_progress_reporting: Option<bool>,
60 /// Client supports the `invalidated` event.
61 pub supports_invalidated_event: Option<bool>,
62 /// Client supports the `memory` event.
63 pub supports_memory_event: Option<bool>,
64 /// Client supports the `argsCanBeInterpretedByShell` attribute on the `runInTerminal` request.
65 pub supports_args_can_be_interpreted_by_shell: Option<bool>,
66 /// Client supports the `startDebugging` request.
67 pub supports_start_debugging_request: Option<bool>,
68}
69
70/// Arguments for an SetBreakpoints request.
71/// In specification: [SetBreakpoints](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize)
72#[cfg_attr(feature = "client", derive(Serialize))]
73#[derive(Deserialize, Debug, Default, Clone)]
74#[serde(rename_all = "camelCase")]
75pub struct SetBreakpointsArguments {
76 /// The source location of the breakpoints, either `source.path` or
77 /// `source.sourceReference` must be specified.
78 pub source: Source,
79 /// The code locations of the breakpoints.
80 pub breakpoints: Option<Vec<SourceBreakpoint>>,
81 /// Deprecated: The code locations of the breakpoints.
82 #[deprecated]
83 pub lines: Option<Vec<i64>>,
84 /// A value of true indicates that the underlying source has been modified
85 /// which results in new breakpoint locations.
86 pub source_modified: Option<bool>,
87}
88
89#[cfg_attr(feature = "client", derive(Serialize))]
90#[derive(Deserialize, Debug, Default, Clone)]
91#[serde(rename_all = "camelCase")]
92pub struct CancelArguments {
93 /// The ID (attribute `seq`) of the request to cancel. If missing no request is
94 /// cancelled.
95 /// Both a `requestId` and a `progressId` can be specified in one request.
96 pub request_id: Option<i64>,
97 /// The ID (attribute `progressId`) of the progress to cancel. If missing no
98 /// progress is cancelled.
99 /// Both a `requestId` and a `progressId` can be specified in one request.
100 pub progress_id: Option<String>,
101}
102
103#[cfg_attr(feature = "client", derive(Serialize))]
104#[derive(Deserialize, Debug, Default, Clone)]
105#[serde(rename_all = "camelCase")]
106pub struct SetExceptionBreakpointsArguments {
107 /// Set of exception filters specified by their ID. The set of all possible
108 /// exception filters is defined by the `exceptionBreakpointFilters`
109 /// capability. The `filter` and `filterOptions` sets are additive.
110 pub filters: Vec<String>,
111 /// Set of exception filters and their options. The set of all possible
112 /// exception filters is defined by the `exceptionBreakpointFilters`
113 /// capability. This attribute is only honored by a debug adapter if the
114 /// corresponding capability `supportsExceptionFilterOptions` is true. The
115 /// `filter` and `filterOptions` sets are additive.
116 pub filter_options: Option<Vec<ExceptionFilterOptions>>,
117 /// Configuration options for selected exceptions.
118 /// The attribute is only honored by a debug adapter if the corresponding
119 /// capability `supportsExceptionOptions` is true.
120 pub exception_options: Option<Vec<ExceptionOptions>>,
121}
122
123#[cfg_attr(feature = "client", derive(Serialize))]
124#[derive(Deserialize, Debug, Default, Clone)]
125#[serde(rename_all = "camelCase")]
126pub struct SetFunctionBreakpointsArguments {
127 /// The function names of the breakpoints.
128 pub breakpoints: Vec<FunctionBreakpoint>,
129}
130
131/// Arguments for a Launch request.
132#[cfg_attr(feature = "client", derive(Serialize))]
133#[derive(Deserialize, Debug, Default, Clone)]
134#[serde(rename_all = "camelCase")]
135pub struct LaunchRequestArguments {
136 /// If true, the launch request should launch the program without enabling
137 /// debugging.
138 pub no_debug: Option<bool>,
139 /// Arbitrary data from the previous, restarted session.
140 /// The data is sent as the `restart` attribute of the `terminated` event.
141 /// The client should leave the data intact.
142 ///
143 /// Rust-specific: this data must be a string. Server requiring storing binary data should use
144 /// an encoding that is suitable for string (e.g. base85 or similar).
145 #[serde(rename = "__restart")]
146 pub restart_data: Option<Value>,
147 /// The request may include additional implementation specific attributes.
148 #[serde(flatten)]
149 pub additional_data: Option<Value>,
150}
151
152/// Arguments for an Attach request.
153#[cfg_attr(feature = "client", derive(Serialize))]
154#[derive(Deserialize, Debug, Default, Clone)]
155#[serde(rename_all = "camelCase")]
156pub struct AttachRequestArguments {
157 /// Arbitrary data from the previous, restarted session.
158 /// The data is sent as the `restart` attribute of the `terminated` event.
159 /// The client should leave the data intact.
160 #[serde(rename = "__restart")]
161 pub restart_data: Option<Value>,
162
163 /// The request may include additional implementation specific attributes.
164 #[serde(flatten)]
165 pub additional_data: Option<Value>,
166}
167
168/// Union of Attach and Launch arguments for the Restart request.
169/// Currently the same as LaunchRequestArguments but might not be in the future.
170#[derive(Deserialize, Debug, Default, Clone)]
171#[cfg_attr(feature = "client", derive(Serialize))]
172#[serde(rename_all = "camelCase")]
173pub struct AttachOrLaunchArguments {
174 /// If true, the launch request should launch the program without enabling
175 /// debugging.
176 pub no_debug: Option<bool>,
177
178 /// Arbitrary data from the previous, restarted session.
179 /// The data is sent as the `restart` attribute of the `terminated` event.
180 /// The client should leave the data intact.
181 #[serde(rename = "__restart")]
182 pub restart_data: Option<Value>,
183
184 /// The request may include additional implementation specific attributes.
185 #[serde(flatten)]
186 pub additional_data: Option<Value>,
187}
188
189/// Arguments for a BreakpointLocations request.
190#[cfg_attr(feature = "client", derive(Serialize))]
191#[derive(Deserialize, Debug, Default, Clone)]
192#[serde(rename_all = "camelCase")]
193pub struct BreakpointLocationsArguments {
194 /// The source location of the breakpoints, either `source.path` or
195 /// `source.reference` must be specified.
196 pub source: Source,
197 /// Start line of range to search possible breakpoint locations in. If only the
198 /// line is specified, the request returns all possible locations in that line.
199 pub line: i64,
200 /// Start position within `line` to search possible breakpoint locations in. It
201 /// is measured in UTF-16 code units and the client capability
202 /// `columnsStartAt1` determines whether it is 0- or 1-based. If no column is
203 /// given, the first position in the start line is assumed.
204 pub column: Option<i64>,
205 /// End line of range to search possible breakpoint locations in. If no end
206 /// line is given, then the end line is assumed to be the start line.
207 pub end_line: Option<i64>,
208 /// End position within `endLine` to search possible breakpoint locations in.
209 /// It is measured in UTF-16 code units and the client capability
210 /// `columnsStartAt1` determines whether it is 0- or 1-based. If no end column
211 /// is given, the last position in the end line is assumed.
212 pub end_column: Option<i64>,
213}
214
215/// Arguments for a Completions request.
216#[cfg_attr(feature = "client", derive(Serialize))]
217#[derive(Deserialize, Debug, Default, Clone)]
218#[serde(rename_all = "camelCase")]
219pub struct CompletionsArguments {
220 /// Returns completions in the scope of this stack frame. If not specified, the
221 /// completions are returned for the global scope.
222 pub frame_id: Option<i64>,
223 /// One or more source lines. Typically this is the text users have typed into
224 /// the debug console before they asked for completion.
225 pub text: String,
226 /// The position within `text` for which to determine the completion proposals.
227 /// It is measured in UTF-16 code units and the client capability
228 /// `columnsStartAt1` determines whether it is 0- or 1-based.
229 pub column: i64,
230 /// A line for which to determine the completion proposals. If missing the
231 /// first line of the text is assumed.
232 pub line: Option<i64>,
233}
234
235/// Arguments for a Continue request.
236#[cfg_attr(feature = "client", derive(Serialize))]
237#[derive(Deserialize, Debug, Default, Clone)]
238#[serde(rename_all = "camelCase")]
239pub struct ContinueArguments {
240 /// Specifies the active thread. If the debug adapter supports single thread
241 /// execution (see `supportsSingleThreadExecutionRequests`) and the argument
242 /// `singleThread` is true, only the thread with this ID is resumed.
243 pub thread_id: i64,
244 /// If this flag is true, execution is resumed only for the thread with given
245 /// `threadId`.
246 pub single_thread: Option<bool>,
247}
248
249/// Arguments for a DataBreakpointInfo request.
250#[cfg_attr(feature = "client", derive(Serialize))]
251#[derive(Deserialize, Debug, Default, Clone)]
252#[serde(rename_all = "camelCase")]
253pub struct DataBreakpointInfoArguments {
254 /// Reference to the variable container if the data breakpoint is requested for
255 /// a child of the container. The `variablesReference` must have been obtained
256 /// in the current suspended state.
257 /// See [Lifetime of Object References](https://microsoft.github.io/debug-adapter-protocol/overview#lifetime-of-objects-references)
258 /// in the Overview section of the specification for details.
259 pub variables_reference: Option<i64>,
260 /// The name of the variable's child to obtain data breakpoint information for.
261 /// If `variablesReference` isn't specified, this can be an expression.
262 pub name: String,
263 /// When `name` is an expression, evaluate it in the scope of this stack frame.
264 /// If not specified, the expression is evaluated in the global scope. When
265 /// `variablesReference` is specified, this property has no effect.
266 pub frame_id: Option<i64>,
267}
268
269/// Arguments for a Disassemble request.
270#[cfg_attr(feature = "client", derive(Serialize))]
271#[derive(Deserialize, Debug, Default, Clone)]
272#[serde(rename_all = "camelCase")]
273pub struct DisassembleArguments {
274 /// Memory reference to the base location containing the instructions to
275 /// disassemble.
276 pub memory_reference: String,
277 /// Offset (in bytes) to be applied to the reference location before
278 /// disassembling. Can be negative.
279 pub offset: Option<i64>,
280 /// Offset (in instructions) to be applied after the byte offset (if any)
281 /// before disassembling. Can be negative.
282 pub instruction_offset: Option<i64>,
283 /// Number of instructions to disassemble starting at the specified location
284 /// and offset.
285 /// An adapter must return exactly this i64 of instructions - any
286 /// unavailable instructions should be replaced with an implementation-defined
287 /// 'invalid instruction' value.
288 pub instruction_count: i64,
289 /// If true, the adapter should attempt to resolve memory addresses and other
290 /// values to symbolic names.
291 pub resolve_symbols: Option<bool>,
292}
293
294/// Arguments for a Disconnect request.
295#[cfg_attr(feature = "client", derive(Serialize))]
296#[derive(Deserialize, Debug, Default, Clone)]
297#[serde(rename_all = "camelCase")]
298pub struct DisconnectArguments {
299 /// A value of true indicates that this `disconnect` request is part of a
300 /// restart sequence.
301 pub restart: Option<bool>,
302 /// Indicates whether the debuggee should be terminated when the debugger is
303 /// disconnected.
304 /// If unspecified, the debug adapter is free to do whatever it thinks is best.
305 /// The attribute is only honored by a debug adapter if the corresponding
306 /// capability `supportTerminateDebuggee` is true.
307 pub terminate_debuggee: Option<bool>,
308 /// Indicates whether the debuggee should stay suspended when the debugger is
309 /// disconnected.
310 /// If unspecified, the debuggee should resume execution.
311 /// The attribute is only honored by a debug adapter if the corresponding
312 /// capability `supportSuspendDebuggee` is true.
313 pub suspend_debuggee: Option<bool>,
314}
315
316/// Arguments for a Evaluate request.
317#[cfg_attr(feature = "client", derive(Serialize))]
318#[derive(Deserialize, Debug, Default, Clone)]
319#[serde(rename_all = "camelCase")]
320pub struct EvaluateArguments {
321 /// The expression to evaluate.
322 pub expression: String,
323 /// Evaluate the expression in the scope of this stack frame. If not specified,
324 /// the expression is evaluated in the global scope.
325 pub frame_id: Option<i64>,
326 /// The context in which the evaluate request is used.
327 /// Values:
328 /// 'variables': evaluate is called from a variables view context.
329 /// 'watch': evaluate is called from a watch view context.
330 /// 'repl': evaluate is called from a REPL context.
331 /// 'hover': evaluate is called to generate the debug hover contents.
332 /// This value should only be used if the corresponding capability
333 /// `supportsEvaluateForHovers` is true.
334 /// 'clipboard': evaluate is called to generate clipboard contents.
335 /// This value should only be used if the corresponding capability
336 /// `supportsClipboardContext` is true.
337 /// etc.
338 pub context: Option<EvaluateArgumentsContext>,
339 /// Specifies details on how to format the result.
340 /// The attribute is only honored by a debug adapter if the corresponding
341 /// capability `supportsValueFormattingOptions` is true.
342 pub format: Option<ValueFormat>,
343}
344
345/// Arguments for a ExceptionInfo request.
346#[cfg_attr(feature = "client", derive(Serialize))]
347#[derive(Deserialize, Debug, Default, Clone)]
348#[serde(rename_all = "camelCase")]
349pub struct ExceptionInfoArguments {
350 /// Thread for which exception information should be retrieved.
351 pub thread_id: i64,
352}
353
354/// Arguments for a Goto request.
355#[cfg_attr(feature = "client", derive(Serialize))]
356#[derive(Deserialize, Debug, Default, Clone)]
357#[serde(rename_all = "camelCase")]
358pub struct GotoArguments {
359 /// Set the goto target for this thread.
360 pub thread_id: i64,
361 /// The location where the debuggee will continue to run.
362 pub target_id: i64,
363}
364
365/// Arguments for a GotoTargets request.
366#[cfg_attr(feature = "client", derive(Serialize))]
367#[derive(Deserialize, Debug, Default, Clone)]
368#[serde(rename_all = "camelCase")]
369pub struct GotoTargetsArguments {
370 /// The source location for which the goto targets are determined.
371 pub source: Source,
372 /// The line location for which the goto targets are determined.
373 pub line: i64,
374 /// The position within `line` for which the goto targets are determined. It is
375 /// measured in UTF-16 code units and the client capability `columnsStartAt1`
376 /// determines whether it is 0- or 1-based.
377 pub column: Option<i64>,
378}
379
380/// Arguments for a Modules request.
381#[cfg_attr(feature = "client", derive(Serialize))]
382#[derive(Deserialize, Debug, Default, Clone)]
383#[serde(rename_all = "camelCase")]
384pub struct ModulesArguments {
385 /// The index of the first module to return, if omitted modules start at 0.
386 pub start_module: Option<i64>,
387 /// The i64 of modules to return. If `moduleCount` is not specified or 0,
388 /// all modules are returned.
389 pub module_count: Option<i64>,
390}
391
392/// Arguments for a Next request.
393#[cfg_attr(feature = "client", derive(Serialize))]
394#[derive(Deserialize, Debug, Default, Clone)]
395#[serde(rename_all = "camelCase")]
396pub struct NextArguments {
397 /// Specifies the thread for which to resume execution for one step (of the
398 /// given granularity).
399 pub thread_id: i64,
400 /// If this flag is true, all other suspended threads are not resumed.
401 pub single_thread: Option<bool>,
402 /// Stepping granularity. If no granularity is specified, a granularity of
403 /// `statement` is assumed.
404 pub granularity: Option<SteppingGranularity>,
405}
406
407/// Arguments for a Pause request.
408#[cfg_attr(feature = "client", derive(Serialize))]
409#[derive(Deserialize, Debug, Default, Clone)]
410#[serde(rename_all = "camelCase")]
411pub struct PauseArguments {
412 /// Pause execution for this thread.
413 pub thread_id: i64,
414}
415
416/// Arguments for a ReadMemory request.
417#[cfg_attr(feature = "client", derive(Serialize))]
418#[derive(Deserialize, Debug, Default, Clone)]
419#[serde(rename_all = "camelCase")]
420pub struct ReadMemoryArguments {
421 /// Memory reference to the base location from which data should be read.
422 pub memory_reference: String,
423 /// Offset (in bytes) to be applied to the reference location before reading
424 /// data. Can be negative.
425 pub offset: Option<i64>,
426 /// Number of bytes to read at the specified location and offset.
427 pub count: i64,
428}
429
430/// Arguments for a ReadMemory request.
431#[derive(Deserialize, Debug, Clone)]
432#[cfg_attr(feature = "client", derive(Serialize))]
433#[serde(rename_all = "camelCase")]
434pub struct RestartArguments {
435 pub arguments: Option<AttachOrLaunchArguments>,
436}
437
438/// Arguments for a RestartFrame request.
439#[cfg_attr(feature = "client", derive(Serialize))]
440#[derive(Deserialize, Debug, Default, Clone)]
441#[serde(rename_all = "camelCase")]
442pub struct RestartFrameArguments {
443 /// Restart this stackframe.
444 pub frame_id: i64,
445}
446
447/// Arguments for a ReverseContinue request.
448#[cfg_attr(feature = "client", derive(Serialize))]
449#[derive(Deserialize, Debug, Default, Clone)]
450#[serde(rename_all = "camelCase")]
451pub struct ReverseContinueArguments {
452 /// Specifies the active thread. If the debug adapter supports single thread
453 /// execution (see `supportsSingleThreadExecutionRequests`) and the
454 /// `singleThread` argument is true, only the thread with this ID is resumed.
455 pub thread_id: i64,
456 /// If this flag is true, backward execution is resumed only for the thread
457 /// with given `threadId`.
458 pub single_thread: Option<bool>,
459}
460
461/// Arguments for a Scopes request.
462#[cfg_attr(feature = "client", derive(Serialize))]
463#[derive(Deserialize, Debug, Default, Clone)]
464#[serde(rename_all = "camelCase")]
465pub struct ScopesArguments {
466 /// Retrieve the scopes for this stackframe.
467 pub frame_id: i64,
468}
469
470/// Arguments for a SetDataBreakpoints request.
471#[cfg_attr(feature = "client", derive(Serialize))]
472#[derive(Deserialize, Debug, Default, Clone)]
473#[serde(rename_all = "camelCase")]
474pub struct SetDataBreakpointsArguments {
475 /// The contents of this array replaces all existing data breakpoints. An empty
476 /// array clears all data breakpoints.
477 pub breakpoints: Vec<DataBreakpoint>,
478}
479
480/// Arguments for a SetExpression request.
481#[cfg_attr(feature = "client", derive(Serialize))]
482#[derive(Deserialize, Debug, Default, Clone)]
483#[serde(rename_all = "camelCase")]
484pub struct SetExpressionArguments {
485 /// The l-value expression to assign to.
486 pub expression: String,
487 /// The value expression to assign to the l-value expression.
488 pub value: String,
489 /// Evaluate the expressions in the scope of this stack frame. If not
490 /// specified, the expressions are evaluated in the global scope.
491 pub frame_id: Option<i64>,
492 /// Specifies how the resulting value should be formatted.
493 pub format: Option<ValueFormat>,
494}
495
496/// Arguments for a SetExpression request.
497#[cfg_attr(feature = "client", derive(Serialize))]
498#[derive(Deserialize, Debug, Default, Clone)]
499#[serde(rename_all = "camelCase")]
500pub struct SetInstructionBreakpointsArguments {
501 /// The instruction references of the breakpoints
502 pub breakpoints: Vec<InstructionBreakpoint>,
503}
504
505/// Arguments for a SetVariable request.
506#[cfg_attr(feature = "client", derive(Serialize))]
507#[derive(Deserialize, Debug, Default, Clone)]
508#[serde(rename_all = "camelCase")]
509pub struct SetVariableArguments {
510 /// The reference of the variable container.
511 /// See [Lifetime of Object References](https://microsoft.github.io/debug-adapter-protocol/overview#lifetime-of-objects-references)
512 /// in the Overview section of the specification for details.
513 pub variables_reference: i64,
514 /// The name of the variable in the container.
515 pub name: String,
516 /// The value of the variable.
517 pub value: String,
518 /// Specifies details on how to format the response value.
519 pub format: Option<ValueFormat>,
520}
521
522/// Arguments for a Source request.
523#[cfg_attr(feature = "client", derive(Serialize))]
524#[derive(Deserialize, Debug, Default, Clone)]
525#[serde(rename_all = "camelCase")]
526pub struct SourceArguments {
527 /// Specifies the source content to load. Either `source.path` or
528 /// `source.sourceReference` must be specified.
529 pub source: Option<Source>,
530 /// The reference to the source. This is the same as `source.sourceReference`.
531 /// This is provided for backward compatibility since old clients do not
532 /// understand the `source` attribute.
533 pub source_reference: i64,
534}
535
536/// Arguments for a StackTrace request.
537#[cfg_attr(feature = "client", derive(Serialize))]
538#[derive(Deserialize, Debug, Default, Clone)]
539#[serde(rename_all = "camelCase")]
540pub struct StackTraceArguments {
541 /// Retrieve the stacktrace for this thread.
542 pub thread_id: i64,
543 /// The index of the first frame to return, if omitted frames start at 0.
544 pub start_frame: Option<i64>,
545 /// The maximum i64 of frames to return. If levels is not specified or 0,
546 /// all frames are returned.
547 pub levels: Option<i64>,
548 /// Specifies details on how to format the stack frames.
549 /// The attribute is only honored by a debug adapter if the corresponding
550 /// capability `supportsValueFormattingOptions` is true.
551 pub format: Option<StackFrameFormat>,
552}
553
554/// Arguments for a StepBack request.
555#[cfg_attr(feature = "client", derive(Serialize))]
556#[derive(Deserialize, Debug, Default, Clone)]
557#[serde(rename_all = "camelCase")]
558pub struct StepBackArguments {
559 /// Specifies the thread for which to resume execution for one step backwards
560 /// (of the given granularity).
561 pub thread_id: i64,
562 /// If this flag is true, all other suspended threads are not resumed.
563 pub single_thread: Option<bool>,
564 /// Stepping granularity to step. If no granularity is specified, a granularity
565 /// of `statement` is assumed.
566 pub granularity: Option<SteppingGranularity>,
567}
568
569/// Arguments for a StepIn request.
570#[cfg_attr(feature = "client", derive(Serialize))]
571#[derive(Deserialize, Debug, Default, Clone)]
572#[serde(rename_all = "camelCase")]
573pub struct StepInArguments {
574 /// Specifies the thread for which to resume execution for one step-into (of
575 /// the given granularity).
576 pub thread_id: i64,
577 /// If this flag is true, all other suspended threads are not resumed.
578 pub single_thread: Option<bool>,
579 /// Id of the target to step into.
580 pub target_id: Option<i64>,
581 /// Stepping granularity. If no granularity is specified, a granularity of
582 /// `statement` is assumed.
583 pub granularity: Option<SteppingGranularity>,
584}
585
586/// Arguments for a StepInTargets request.
587#[cfg_attr(feature = "client", derive(Serialize))]
588#[derive(Deserialize, Debug, Default, Clone)]
589#[serde(rename_all = "camelCase")]
590pub struct StepInTargetsArguments {
591 /// The stack frame for which to retrieve the possible step-in targets.
592 pub frame_id: i64,
593}
594
595/// Arguments for a StepOut request.
596#[cfg_attr(feature = "client", derive(Serialize))]
597#[derive(Deserialize, Debug, Default, Clone)]
598#[serde(rename_all = "camelCase")]
599pub struct StepOutArguments {
600 /// Specifies the thread for which to resume execution for one step-out (of the
601 /// given granularity).
602 pub thread_id: i64,
603 /// If this flag is true, all other suspended threads are not resumed.
604 pub single_thread: Option<bool>,
605 /// Stepping granularity. If no granularity is specified, a granularity of
606 /// `statement` is assumed.
607 pub granularity: Option<SteppingGranularity>,
608}
609
610/// Arguments for a Terminate request.
611#[cfg_attr(feature = "client", derive(Serialize))]
612#[derive(Deserialize, Debug, Default, Clone)]
613#[serde(rename_all = "camelCase")]
614pub struct TerminateArguments {
615 /// A value of true indicates that this `terminate` request is part of a
616 /// restart sequence.
617 pub restart: Option<bool>,
618}
619
620/// Arguments for a TerminateThreads request.
621#[cfg_attr(feature = "client", derive(Serialize))]
622#[derive(Deserialize, Debug, Default, Clone)]
623#[serde(rename_all = "camelCase")]
624pub struct TerminateThreadsArguments {
625 /// Ids of threads to be terminated.
626 pub thread_ids: Option<Vec<i64>>,
627}
628
629/// Arguments for a Variables request.
630#[cfg_attr(feature = "client", derive(Serialize))]
631#[derive(Deserialize, Debug, Default, Clone)]
632#[serde(rename_all = "camelCase")]
633pub struct VariablesArguments {
634 /// The variable for which to retrieve its children. The `variablesReference`
635 /// must have been obtained in the current suspended state.
636 /// See [Lifetime of Object References](https://microsoft.github.io/debug-adapter-protocol/overview#lifetime-of-objects-references)
637 /// in the Overview section of the specification for details.
638 pub variables_reference: i64,
639 /// Filter to limit the child variables to either named or indexed. If omitted,
640 /// both types are fetched.
641 /// Values: 'indexed', 'named'
642 pub filter: Option<VariablesArgumentsFilter>,
643 /// The index of the first variable to return, if omitted children start at 0.
644 pub start: Option<i64>,
645 /// The i64 of variables to return. If count is missing or 0, all variables
646 /// are returned.
647 pub count: Option<i64>,
648 /// Specifies details on how to format the Variable values.
649 /// The attribute is only honored by a debug adapter if the corresponding
650 /// capability `supportsValueFormattingOptions` is true.
651 pub format: Option<ValueFormat>,
652}
653
654/// Arguments for a WriteMemory request.
655#[cfg_attr(feature = "client", derive(Serialize))]
656#[derive(Deserialize, Debug, Default, Clone)]
657#[serde(rename_all = "camelCase")]
658pub struct WriteMemoryArguments {
659 /// Memory reference to the base location to which data should be written.
660 pub memory_reference: String,
661 /// Offset (in bytes) to be applied to the reference location before writing
662 /// data. Can be negative.
663 pub offset: Option<i64>,
664 /// Property to control partial writes. If true, the debug adapter should
665 /// attempt to write memory even if the entire memory region is not writable.
666 /// In such a case the debug adapter should stop after hitting the first byte
667 /// of memory that cannot be written and return the i64 of bytes written in
668 /// the response via the `offset` and `bytesWritten` properties.
669 /// If false or missing, a debug adapter should attempt to verify the region is
670 /// writable before writing, and fail the response if it is not.
671 pub allow_partial: Option<bool>,
672 /// Bytes to write, encoded using base64.
673 pub data: String,
674}
675
676#[cfg_attr(feature = "client", derive(Serialize))]
677#[derive(Deserialize, Debug, Clone)]
678#[serde(tag = "command", content = "arguments", rename_all = "camelCase")]
679pub enum Command {
680 /// The attach request is sent from the client to the debug adapter to attach to a debuggee that
681 /// is already running.
682 /// kSince attaching is debugger/runtime specific, the arguments for this request are not part of
683 /// this specification.
684 ///
685 /// Specification: [Attach request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Attach)
686 Attach(AttachRequestArguments),
687 /// The `breakpointLocations` request returns all possible locations for source breakpoints in a
688 /// given range.
689 /// Clients should only call this request if the corresponding capability
690 /// `supportsBreakpointLocationsRequest` is true.
691 ///
692 /// Specification: [BreakpointLocations request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_BreakpointLocations)
693 BreakpointLocations(BreakpointLocationsArguments),
694 /// Returns a list of possible completions for a given caret position and text.
695 /// Clients should only call this request if the corresponding capability
696 /// `supportsCompletionsRequest` is true.
697 ///
698 /// Specification: [Completions request]: https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Completions
699 Completions(CompletionsArguments),
700 /// This request indicates that the client has finished initialization of the debug adapter.
701 /// So it is the last request in the sequence of configuration requests (which was started by the initialized event).
702 /// Clients should only call this request if the corresponding capability supportsConfigurationDoneRequest is true.
703 ///
704 /// Specification: [ConfigurationDone](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ConfigurationDone)
705 ConfigurationDone,
706 /// The request resumes execution of all threads. If the debug adapter supports single thread
707 /// execution (see capability `supportsSingleThreadExecutionRequests`), setting the singleThread
708 /// argument to true resumes only the specified thread. If not all threads were resumed, the
709 /// `allThreadsContinued` attribute of the response should be set to false.
710 ///
711 /// Specification: [Continue request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Continue)
712 Continue(ContinueArguments),
713 /// Obtains information on a possible data breakpoint that could be set on an expression or
714 /// variable.
715 /// Clients should only call this request if the corresponding capability supportsDataBreakpoints
716 /// is true.
717 ///
718 /// Specification: [DataBreakpointInfo request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_DataBreakpointInfo)
719 DataBreakpointInfo(DataBreakpointInfoArguments),
720 /// Disassembles code stored at the provided location.
721 /// Clients should only call this request if the corresponding capability
722 /// `supportsDisassembleRequest` is true.
723 ///
724 /// Specification: [Disassemble request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disassemble)
725 Disassemble(DisassembleArguments),
726 /// The `disconnect` request asks the debug adapter to disconnect from the debuggee (thus ending
727 /// the debug session) and then to shut down itself (the debug adapter).
728 /// In addition, the debug adapter must terminate the debuggee if it was started with the `launch`
729 /// request. If an `attach` request was used to connect to the debuggee, then the debug adapter
730 /// must not terminate the debuggee.
731 /// This implicit behavior of when to terminate the debuggee can be overridden with the
732 /// `terminateDebuggee` argument (which is only supported by a debug adapter if the corresponding
733 /// capability `supportTerminateDebuggee` is true).
734 ///
735 /// Specification: [Disconnect request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disconnect)
736 Disconnect(DisconnectArguments),
737 /// Evaluates the given expression in the context of the topmost stack frame.
738 /// The expression has access to any variables and arguments that are in scope.
739 ///
740 /// Specification: [Evaluate arguments](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Evaluate)
741 Evaluate(EvaluateArguments),
742 /// Retrieves the details of the exception that caused this event to be raised.
743 /// Clients should only call this request if the corresponding capability
744 /// `supportsExceptionInfoRequest` is true.
745 ///
746 /// Specification: [ExceptionInfo request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ExceptionInfo)
747 ExceptionInfo(ExceptionInfoArguments),
748 /// The request sets the location where the debuggee will continue to run.
749 /// This makes it possible to skip the execution of code or to execute code again.
750 /// The code between the current location and the goto target is not executed but skipped.
751 /// The debug adapter first sends the response and then a stopped event with reason goto.
752 /// Clients should only call this request if the corresponding capability
753 /// `supportsGotoTargetsRequest` is true (because only then goto targets exist that can be passed
754 /// as arguments).
755 ///
756 /// Specification: [Goto request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Goto)
757 Goto(GotoArguments),
758 /// This request retrieves the possible goto targets for the specified source location.
759 /// These targets can be used in the goto request.
760 /// Clients should only call this request if the corresponding capability
761 /// `supportsGotoTargetsRequest` is true.
762 ///
763 /// Specification: [GotoTargets request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_GotoTargets)
764 GotoTargets(GotoTargetsArguments),
765 /// The initialize request is sent as the first request from the client to the debug adapter in
766 /// order to configure it with client capabilities and to retrieve capabilities from the debug
767 /// adapter.
768 ///
769 /// Until the debug adapter has responded with an initialize response, the client must not send any
770 /// additional requests or events to the debug adapter.
771 ///
772 /// In addition the debug adapter is not allowed to send any requests or events to the client until
773 /// it has responded with an initialize response.
774 ///
775 /// The initialize request may only be sent once.
776 ///
777 /// Specification: [InitializeRequest](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize)
778 Initialize(InitializeArguments),
779 /// This launch request is sent from the client to the debug adapter to start the debuggee with
780 /// or without debugging (if noDebug is true).
781 /// Since launching is debugger/runtime specific, the arguments for this request are not part of
782 /// this specification.
783 ///
784 /// Specification: [Launch request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Launch)
785 Launch(LaunchRequestArguments),
786 /// Retrieves the set of all sources currently loaded by the debugged process.
787 /// Clients should only call this request if the corresponding capability supportsLoadedSourcesRequest is true.
788 ///
789 /// Specification: [LoadedSources request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_LoadedSources)
790 LoadedSources,
791 /// Modules can be retrieved from the debug adapter with this request which can either return
792 /// all modules or a range of modules to support paging.
793 /// Clients should only call this request if the corresponding capability
794 /// `supportsModulesRequest` is true.
795 ///
796 /// Specification: [Modules request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Modules)
797 Modules(ModulesArguments),
798 /// The request executes one step (in the given granularity) for the specified thread and allows
799 /// all other threads to run freely by resuming them.
800 /// If the debug adapter supports single thread execution (see capability
801 /// `supportsSingleThreadExecutionRequests`), setting the `singleThread` argument to true
802 /// prevents other suspended threads from resuming.
803 /// The debug adapter first sends the response and then a stopped event (with reason step) after
804 /// the step has completed.
805 ///
806 /// Specification: [Next request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Next)
807 Next(NextArguments),
808 /// The request suspends the debuggee.
809 /// The debug adapter first sends the response and then a `stopped` event (with reason pause)
810 /// after the thread has been paused successfully.
811 ///
812 /// Specification: [Pause request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Pause)
813 Pause(PauseArguments),
814 /// Reads bytes from memory at the provided location.
815 /// Clients should only call this request if the corresponding capability
816 /// `supportsReadMemoryRequest` is true.
817 ///
818 /// Specification: [ReadMemory request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ReadMemory)
819 ReadMemory(ReadMemoryArguments),
820 /// Restarts a debug session. Clients should only call this request if the corresponding
821 /// capability supportsRestartRequest is true.
822 /// If the capability is missing or has the value false, a typical client emulates restart by
823 /// terminating the debug adapter first and then launching it anew.
824 ///
825 /// Specification: [Restart request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Restart)
826 Restart(RestartArguments),
827 /// The request restarts execution of the specified stackframe.
828 /// The debug adapter first sends the response and then a `stopped` event (with reason `restart`)
829 /// after the restart has completed.
830 /// Clients should only call this request if the corresponding capability `supportsRestartFrame`
831 /// is true.
832 ///
833 /// Specification: [RestartFrame request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_RestartFrame)
834 RestartFrame(RestartFrameArguments),
835 /// The request resumes backward execution of all threads. If the debug adapter supports single
836 /// thread execution (see capability `supportsSingleThreadExecutionRequests`), setting the
837 /// singleThread argument to true resumes only the specified thread. If not all threads were
838 /// resumed, the `allThreadsContinued` attribute of the response should be set to false.
839 /// Clients should only call this request if the corresponding capability supportsStepBack is true.
840 ///
841 /// Specification: [ReverseContinue request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ReverseContinue)
842 ReverseContinue(ReverseContinueArguments),
843 /// The request returns the variable scopes for a given stackframe ID.
844 ///
845 /// Specification: [Scopes request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Scopes)
846 Scopes(ScopesArguments),
847 /// Sets multiple breakpoints for a single source and clears all previous breakpoints in that source.
848 ///
849 /// To clear all breakpoint for a source, specify an empty array.
850 ///
851 /// When a breakpoint is hit, a stopped event (with reason breakpoint) is generated.
852 ///
853 /// Specification: [SetBreakpointsRequest](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetBreakpoints)
854 SetBreakpoints(SetBreakpointsArguments),
855 /// Replaces all existing data breakpoints with new data breakpoints.
856 /// To clear all data breakpoints, specify an empty array.
857 /// When a data breakpoint is hit, a `stopped` event (with reason `data breakpoint`) is generated.
858 /// Clients should only call this request if the corresponding capability
859 /// `supportsDataBreakpoints` is true.
860 ///
861 /// Specification: [SetDataBreakpoints request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetDataBreakpoints)
862 SetDataBreakpoints(SetDataBreakpointsArguments),
863 /// The request configures the debugger’s response to thrown exceptions.
864 /// If an exception is configured to break, a stopped event is fired (with reason exception).
865 /// Clients should only call this request if the corresponding capability exceptionBreakpointFilters returns one or more filters.
866 ///
867 /// Specification: [SetExceptionBreakpoints](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetExceptionBreakpoints)
868 SetExceptionBreakpoints(SetExceptionBreakpointsArguments),
869 /// Evaluates the given `value` expression and assigns it to the `expression` which must be a
870 /// modifiable l-value.
871 /// The expressions have access to any variables and arguments that are in scope of the specified
872 /// frame.
873 /// Clients should only call this request if the corresponding capability `supportsSetExpression`
874 /// is true.
875 /// If a debug adapter implements both `setExpression` and `setVariable`, a client uses
876 /// `setExpression` if the variable has an `evaluateName` property.
877 ///
878 /// Specification: [SetExpression request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetExpression)
879 SetExpression(SetExpressionArguments),
880 /// Replaces all existing function breakpoints with new function breakpoints.
881 /// To clear all function breakpoints, specify an empty array.
882 /// When a function breakpoint is hit, a stopped event (with reason function breakpoint) is
883 /// generated.
884 /// Clients should only call this request if the corresponding capability
885 /// supportsFunctionBreakpoints is true.
886 ///
887 /// Specification: [SetFunctionBreakpointsArguments](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetFunctionBreakpoints)
888 SetFunctionBreakpoints(SetFunctionBreakpointsArguments),
889 /// Replaces all existing instruction breakpoints. Typically, instruction breakpoints would be set from a disassembly window.
890 /// To clear all instruction breakpoints, specify an empty array.
891 /// When an instruction breakpoint is hit, a `stopped` event (with reason
892 /// `instruction breakpoint`) is generated.
893 /// Clients should only call this request if the corresponding capability
894 /// `supportsInstructionBreakpoints` is true.
895 ///
896 /// Specification: [SetInstructionBreakpoints request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetInstructionBreakpoints)
897 SetInstructionBreakpoints(SetInstructionBreakpointsArguments),
898 /// Set the variable with the given name in the variable container to a new value. Clients should
899 /// only call this request if the corresponding capability `supportsSetVariable` is true.
900 /// If a debug adapter implements both `setVariable` and `setExpression`, a client will only use
901 /// `setExpression` if the variable has an `evaluateName` property.
902 ///
903 /// Specification: [SetVariable request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetVariable)
904 SetVariable(SetVariableArguments),
905 /// The request retrieves the source code for a given source reference.
906 ///
907 /// Specification: [Sources request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Source)
908 Source(SourceArguments),
909 /// The request returns a stacktrace from the current execution state of a given thread.
910 /// A client can request all stack frames by omitting the startFrame and levels arguments. For
911 /// performance-conscious clients and if the corresponding capability
912 /// `supportsDelayedStackTraceLoading` is true, stack frames can be retrieved in a piecemeal way
913 /// with the startFrame and levels arguments. The response of the stackTrace request may
914 /// contain a totalFrames property that hints at the total number of frames in the stack. If a
915 /// client needs this total number upfront, it can issue a request for a single (first) frame
916 /// and depending on the value of totalFrames decide how to proceed. In any case a client should
917 /// be prepared to receive fewer frames than requested, which is an indication that the end of
918 /// the stack has been reached.
919 ///
920 /// Specification: [StackTrace request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StackTrace)
921 StackTrace(StackTraceArguments),
922 /// The request executes one backward step (in the given granularity) for the specified thread
923 /// and allows all other threads to run backward freely by resuming them.
924 /// If the debug adapter supports single thread execution (see capability
925 /// `supportsSingleThreadExecutionRequests`), setting the `singleThread` argument to true prevents
926 /// other suspended threads from resuming.
927 /// The debug adapter first sends the response and then a stopped event (with reason step) after
928 /// the step has completed.
929 /// Clients should only call this request if the corresponding capability `supportsStepBack` is
930 /// true.
931 ///
932 /// Specification: [StepBack request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepBack)
933 StepBack(StepBackArguments),
934 /// The request resumes the given thread to step into a function/method and allows all other
935 /// threads to run freely by resuming them.
936 /// If the debug adapter supports single thread execution (see capability
937 /// `supportsSingleThreadExecutionRequests`), setting the `singleThread` argument to true
938 /// prevents other suspended threads from resuming.
939 ///
940 /// Specification: [StepIn request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepIn)
941 StepIn(StepInArguments),
942 /// This request retrieves the possible step-in targets for the specified stack frame.
943 /// These targets can be used in the `stepIn` request.
944 /// Clients should only call this request if the corresponding capability
945 /// `supportsStepInTargetsRequest` is true.
946 ///
947 /// Specification: [StepInTargets request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepInTargets)
948 StepInTargets(StepInTargetsArguments),
949 /// The request resumes the given thread to step out (return) from a function/method and allows
950 /// all other threads to run freely by resuming them.
951 /// If the debug adapter supports single thread execution (see capability
952 /// `supportsSingleThreadExecutionRequests`), setting the singleThread argument to true prevents
953 /// other suspended threads from resuming.
954 /// The debug adapter first sends the response and then a stopped event (with reason step) after
955 /// the step has completed.
956 ///
957 /// Specification: [StepOut request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_StepOut)
958 StepOut(StepOutArguments),
959 /// The terminate request is sent from the client to the debug adapter in order to shut down the
960 /// debuggee gracefully. Clients should only call this request if the capability
961 /// `supportsTerminateRequest` is true.
962 ///
963 /// Specification: [Terminate request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Terminate)
964 Terminate(TerminateArguments),
965 /// The request terminates the threads with the given ids.
966 /// Clients should only call this request if the corresponding capability
967 /// `supportsTerminateThreadsRequest` is true.
968 ///
969 /// Specification: [TerminateThreads request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_TerminateThreads)
970 TerminateThreads(TerminateThreadsArguments),
971 /// The request retrieves a list of all threads.
972 ///
973 /// Specification: [Threads request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Threads)
974 Threads,
975 /// Retrieves all child variables for the given variable reference.
976 /// A filter can be used to limit the fetched children to either named or indexed children.
977 ///
978 /// Specification: [Variables request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Variables)
979 Variables(VariablesArguments),
980 /// Writes bytes to memory at the provided location.
981 /// Clients should only call this request if the corresponding capability
982 /// `supportsWriteMemoryRequest` is true.
983 ///
984 /// Specification: [WriteMemory request](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_WriteMemory)
985 WriteMemory(WriteMemoryArguments),
986 /// The cancel request is used by the client in two situations:
987 ///
988 /// to indicate that it is no longer interested in the result produced by a specific request
989 /// issued earlier to cancel a progress sequence. Clients should only call this request if the
990 /// corresponding capability supportsCancelRequest is true.
991 ///
992 /// Specification: [CancelRequest](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Cancel)
993 Cancel(CancelArguments),
994}
995
996/// Represents a request from a client.
997///
998/// Note that unlike the specification, this implementation does not define a ProtocolMessage base
999/// interface. Instead, the only common part (the sequence number) is repeated in the struct.
1000///
1001/// Specification: [Request](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_Request)
1002#[cfg_attr(feature = "client", derive(Serialize))]
1003#[derive(Deserialize, Debug, Clone)]
1004#[serde(rename_all = "camelCase")]
1005pub struct Request {
1006 /// Sequence number for the Request.
1007 ///
1008 /// From the [specification](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_ProtocolMessage):
1009 ///
1010 /// Sequence number of the message (also known as message ID). The `seq` for
1011 /// the first message sent by a client or debug adapter is 1, and for each
1012 /// subsequent message is 1 greater than the previous message sent by that
1013 /// actor. `seq` can be used to order requests, responses, and events, and to
1014 /// associate requests with their corresponding responses. For protocol
1015 /// messages of type `request` the sequence number can be used to cancel the
1016 /// request.
1017 pub seq: i64,
1018 /// The command to execute.
1019 ///
1020 /// This is stringly typed in the specification, but represented as an enum for better
1021 /// ergonomics in Rust code, along with the arguments when present.
1022 #[serde(flatten)]
1023 pub command: Command,
1024}
1025
1026impl Request {
1027 /// Create a successful response for a given request. The sequence number will be copied
1028 /// from `request`, `message` will be `None` (as its neither cancelled nor an error).
1029 /// The `body` argument contains the response itself.
1030 pub fn success(self, body: ResponseBody) -> Response {
1031 Response {
1032 request_seq: self.seq,
1033 success: true,
1034 message: None,
1035 body: Some(body), // to love
1036 error: None,
1037 }
1038 }
1039
1040 /// Create an error response for a given request. The sequence number will be copied
1041 /// from the request, `message` will be `None` (as its neither cancelled nor an error).
1042 ///
1043 /// ## Arguments
1044 ///
1045 /// * `req`: The request this response corresponds to.
1046 /// * `body`: The body of the response to attach.
1047 pub fn error(self, error: &str) -> Response {
1048 Response {
1049 request_seq: self.seq,
1050 success: false,
1051 message: Some(ResponseMessage::Error(error.to_string())),
1052 body: None,
1053 error: None,
1054 }
1055 }
1056
1057 /// Create a cancellation response for the given request. The sequence number will be copied
1058 /// from the request, message will be [`ResponseMessage::Cancelled`], `success` will be false,
1059 /// and `body` will be `None`.
1060 pub fn cancellation(self) -> Response {
1061 Response {
1062 request_seq: self.seq,
1063 success: false,
1064 message: Some(ResponseMessage::Cancelled),
1065 body: None,
1066 error: None,
1067 }
1068 }
1069
1070 /// Create an acknowledgement response. This is a shorthand for responding to requests
1071 /// where the response does not require a body.
1072 pub fn ack(self) -> Result<Response, ServerError> {
1073 match self.command {
1074 Command::Attach(_) => Ok(Response {
1075 request_seq: self.seq,
1076 success: true,
1077 message: None,
1078 body: Some(ResponseBody::Attach),
1079 error: None,
1080 }),
1081 Command::ConfigurationDone => Ok(Response {
1082 request_seq: self.seq,
1083 success: true,
1084 message: None,
1085 body: Some(ResponseBody::ConfigurationDone),
1086 error: None,
1087 }),
1088 Command::Disconnect(_) => Ok(Response {
1089 request_seq: self.seq,
1090 success: true,
1091 message: None,
1092 body: Some(ResponseBody::Disconnect),
1093 error: None,
1094 }),
1095 Command::Goto(_) => Ok(Response {
1096 request_seq: self.seq,
1097 success: true,
1098 message: None,
1099 body: Some(ResponseBody::Goto),
1100 error: None,
1101 }),
1102 Command::Launch(_) => Ok(Response {
1103 request_seq: self.seq,
1104 success: true,
1105 message: None,
1106 body: Some(ResponseBody::Launch),
1107 error: None,
1108 }),
1109 Command::Next(_) => Ok(Response {
1110 request_seq: self.seq,
1111 success: true,
1112 message: None,
1113 body: Some(ResponseBody::Next),
1114 error: None,
1115 }),
1116 Command::Pause(_) => Ok(Response {
1117 request_seq: self.seq,
1118 success: true,
1119 message: None,
1120 body: Some(ResponseBody::Pause),
1121 error: None,
1122 }),
1123 Command::Restart(_) => Ok(Response {
1124 request_seq: self.seq,
1125 success: true,
1126 message: None,
1127 body: Some(ResponseBody::Next),
1128 error: None,
1129 }),
1130 Command::RestartFrame(_) => Ok(Response {
1131 request_seq: self.seq,
1132 success: true,
1133 message: None,
1134 body: Some(ResponseBody::RestartFrame),
1135 error: None,
1136 }),
1137 Command::ReverseContinue(_) => Ok(Response {
1138 request_seq: self.seq,
1139 success: true,
1140 message: None,
1141 body: Some(ResponseBody::ReverseContinue),
1142 error: None,
1143 }),
1144 Command::StepBack(_) => Ok(Response {
1145 request_seq: self.seq,
1146 success: true,
1147 message: None,
1148 body: Some(ResponseBody::StepBack),
1149 error: None,
1150 }),
1151 Command::StepIn(_) => Ok(Response {
1152 request_seq: self.seq,
1153 success: true,
1154 message: None,
1155 body: Some(ResponseBody::StepIn),
1156 error: None,
1157 }),
1158 Command::StepOut(_) => Ok(Response {
1159 request_seq: self.seq,
1160 success: true,
1161 message: None,
1162 body: Some(ResponseBody::StepOut),
1163 error: None,
1164 }),
1165 Command::Terminate(_) => Ok(Response {
1166 request_seq: self.seq,
1167 success: true,
1168 message: None,
1169 body: Some(ResponseBody::Terminate),
1170 error: None,
1171 }),
1172 Command::TerminateThreads(_) => Ok(Response {
1173 request_seq: self.seq,
1174 success: true,
1175 message: None,
1176 body: Some(ResponseBody::TerminateThreads),
1177 error: None,
1178 }),
1179 _ => Err(ServerError::ResponseConstructError),
1180 }
1181 }
1182}