serde_lsp/dap/
mod.rs

1use serde::{ser::SerializeMap, Deserialize, Serialize, Serializer};
2use std::num::NonZeroUsize;
3
4mod request;
5mod response;
6mod variables_arguments;
7
8pub use self::{request::Request, response::Response, variables_arguments::VariablesArguments};
9
10#[derive(Clone, Debug, Serialize)]
11pub struct DebugCapability {
12    #[serde(rename = "supportsCompletionsRequest")]
13    pub supports_completions_request: bool,
14    #[serde(rename = "supportsConditionalBreakpoints")]
15    pub supports_conditional_breakpoints: bool,
16    #[serde(rename = "supportsConfigurationDoneRequest")]
17    pub supports_configuration_done_request: bool,
18    #[serde(rename = "supportsDebuggerProperties")]
19    pub supports_debugger_properties: bool,
20    #[serde(rename = "supportsDelayedStackTraceLoading")]
21    pub supports_delayed_stack_trace_loading: bool,
22    #[serde(rename = "supportsEvaluateForHovers")]
23    pub supports_evaluate_for_hovers: bool,
24    #[serde(rename = "supportsExceptionInfoRequest")]
25    pub supports_exception_info_request: bool,
26    #[serde(rename = "supportsExceptionOptions")]
27    pub supports_exception_options: bool,
28    #[serde(rename = "supportsFunctionBreakpoints")]
29    pub supports_function_breakpoints: bool,
30    #[serde(rename = "supportsHitConditionalBreakpoints")]
31    pub supports_hit_conditional_breakpoints: bool,
32    #[serde(rename = "supportsLogPoints")]
33    pub supports_log_points: bool,
34    /// The debug adapter supports the `modules` request.
35    #[serde(rename = "supportsModulesRequest")]
36    pub supports_modules_request: bool,
37    #[serde(rename = "supportsSetExpression")]
38    pub supports_set_expression: bool,
39    #[serde(rename = "supportsSetVariable")]
40    pub supports_set_variable: bool,
41    /// Client supports the paging of variables.
42    #[serde(rename = "supportsVariablePaging")]
43    pub supports_variable_paging: bool,
44    /// The debug adapter supports a `format` attribute on the `stackTrace`, `variables`, and `evaluate` requests.
45    #[serde(rename = "supportsValueFormattingOptions")]
46    pub supports_value_formatting_options: bool,
47    #[serde(rename = "supportsTerminateDebuggee")]
48    pub supports_terminate_debuggee: bool,
49    #[serde(rename = "supportsGotoTargetsRequest")]
50    pub supports_goto_targets_request: bool,
51    #[serde(rename = "supportsClipboardContext")]
52    pub supports_clipboard_context: bool,
53    #[serde(rename = "supportsStepInTargetsRequest")]
54    pub supports_step_in_targets_request: bool,
55    #[serde(rename = "exceptionBreakpointFilters")]
56    pub exception_breakpoint_filters: Vec<ExceptionBreakpointFilter>,
57}
58
59#[derive(Clone, Debug, Serialize)]
60pub struct ExceptionBreakpointFilter {
61    pub filter: String,
62    pub label: String,
63    pub default: bool,
64}
65
66impl Default for DebugCapability {
67    fn default() -> Self {
68        Self {
69            supports_completions_request: true,
70            supports_conditional_breakpoints: true,
71            supports_configuration_done_request: true,
72            supports_debugger_properties: true,
73            supports_delayed_stack_trace_loading: true,
74            supports_evaluate_for_hovers: true,
75            supports_exception_info_request: true,
76            supports_exception_options: true,
77            supports_function_breakpoints: true,
78            supports_hit_conditional_breakpoints: true,
79            supports_log_points: true,
80            supports_modules_request: true,
81            supports_set_expression: true,
82            supports_set_variable: true,
83            supports_variable_paging: true,
84            supports_value_formatting_options: true,
85            supports_terminate_debuggee: true,
86            supports_goto_targets_request: true,
87            supports_clipboard_context: true,
88            supports_step_in_targets_request: true,
89            exception_breakpoint_filters: vec![],
90        }
91    }
92}
93
94#[derive(Clone, Debug, Serialize)]
95pub struct VariablesResponseBody {
96    pub variables: Vec<Variable>,
97}
98
99impl<V: Into<Variable>> FromIterator<V> for VariablesResponseBody {
100    fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self {
101        VariablesResponseBody { variables: iter.into_iter().map(|v| v.into()).collect() }
102    }
103}
104
105/// A Variable is a name/value pair.
106///
107/// The type attribute is shown if space permits or when hovering over the variable’s name.
108///
109/// The kind attribute is used to render additional properties of the variable, e.g. different icons can be used to indicate that a variable is public or private.
110///
111/// If the value is structured (has children), a handle is provided to retrieve the children with the variables request.
112///
113/// If the number of named or indexed children is large, the numbers should be returned via the namedVariables and indexedVariables attributes.
114///
115/// The client can use this information to present the children in a paged UI and fetch them in chunks.
116#[derive(Clone, Debug, Serialize)]
117pub struct Variable {
118    /// The variable's name.
119    pub name: String,
120    /// The variable's value.
121    /// This can be a multi-line text, e.g. for a function the body of a function.
122    /// For structured variables (which do not have a simple value), it is
123    /// recommended to provide a one-line representation of the structured object.
124    /// This helps to identify the structured object in the collapsed state when
125    /// its children are not yet visible.
126    /// An empty string can be used if no value should be shown in the UI.
127    pub value: String,
128    /// The type of the variable's value. Typically shown in the UI when hovering
129    /// over the value.
130    /// This attribute should only be returned by a debug adapter if the
131    /// corresponding capability `supportsVariableType` is true.
132    #[serde(rename = "type")]
133    pub typing: String,
134    /// The evaluate name of this variable which can be passed to the `evaluate`
135    /// request to fetch the variable's value.
136    #[serde(rename = "evaluateName")]
137    pub evaluate_name: String,
138    /// If `variablesReference` is > 0, the variable is structured and its children
139    /// can be retrieved by passing `variablesReference` to the `variables` request
140    /// as long as execution remains suspended. See 'Lifetime of Object References'
141    /// in the Overview section for details.
142    #[serde(rename = "variablesReference")]
143    pub variables_reference: usize,
144    /// The number of named child variables.
145    /// The client can use this information to present the children in a paged UI
146    /// and fetch them in chunks.
147    #[serde(rename = "namedVariables")]
148    pub named_variables: usize,
149    /// The number of indexed child variables.
150    /// The client can use this information to present the children in a paged UI
151    /// and fetch them in chunks.
152    #[serde(rename = "indexedVariables")]
153    pub indexed_variables: usize,
154    /// A memory reference to a location appropriate for this result.
155    /// For pointer type eval results, this is generally a reference to the
156    /// memory address contained in the pointer.
157    /// This attribute may be returned by a debug adapter if corresponding
158    /// capability `supportsMemoryReferences` is true.
159    #[serde(rename = "memoryReference")]
160    pub memory_reference: String,
161}
162
163#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
164pub struct ModulesArguments {
165    /// The index of the first module to return.
166    ///
167    /// if omitted modules start at 0.
168    #[serde(rename = "startModule")]
169    pub start: usize,
170    /// The number of modules to return.
171    ///
172    /// If `moduleCount` is not specified or 0, all modules are returned.
173    #[serde(rename = "moduleCount")]
174    pub count: Option<NonZeroUsize>,
175}
176#[derive(Clone, Debug, Serialize, Deserialize)]
177pub struct ModulesResponseBody {
178    pub modules: Vec<Module>,
179    #[serde(rename = "totalModules")]
180    pub total_modules: usize,
181}
182
183impl<M: Into<Module>> FromIterator<M> for ModulesResponseBody {
184    fn from_iter<T: IntoIterator<Item = M>>(iter: T) -> Self {
185        let mut out = ModulesResponseBody { modules: vec![], total_modules: 0 };
186        for m in iter.into_iter().map(|m| m.into()) {
187            out.modules.push(m);
188            out.total_modules += 1;
189        }
190        out
191    }
192}
193
194/// An identifier for a module.
195#[derive(Clone, Debug, Serialize, Deserialize)]
196pub struct Module {
197    /// The module's identifier.
198    pub id: u32,
199    /// The module's name.
200    pub name: String,
201    /// The module's path.
202    pub path: String,
203    /// True if the module is optimized.
204    #[serde(rename = "isOptimized")]
205    pub is_optimized: bool,
206    /// True if the module is considered 'user code' by a debugger that supports
207    /// 'Just My Code'.
208    #[serde(rename = "isUserCode")]
209    pub is_user_code: bool,
210    /// Version of Module.
211    pub version: String,
212}
213
214#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
215#[serde(rename_all = "lowercase")]
216pub enum VariableFilter {
217    Indexed,
218    Named,
219}
220
221#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
222#[serde(rename_all = "camelCase")]
223pub struct ValueFormat {
224    /// Display the value in hex.
225    hex: Option<bool>,
226}
227
228/// This enumeration defines all possible access types for data breakpoints.
229#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
230#[serde(rename_all = "camelCase")]
231pub enum DataBreakpointAccessType {
232    Read,
233    Write,
234    ReadWrite,
235}
236
237/// The granularity of one ‘step’ in the stepping requests `next`, `stepIn`, `stepOut`, and `stepBack`
238#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
239#[serde(rename_all = "camelCase")]
240pub enum SteppingGranularity {
241    /// The step should allow the program to run until the current statement has finished executing.
242    ///
243    /// The meaning of a statement is determined by the adapter and it may be considered equivalent to a line.
244    ///
245    /// For example ‘for(int i = 0; i < 10; i++)’ could be considered to have 3 statements ‘int i = 0’, ‘i < 10’, and ‘i++’.
246    Statement,
247    /// The step should allow the program to run until the current source line has executed.
248    Line,
249    /// The step should allow one instruction to execute (e.g. one x86 instruction)
250    Instruction,
251}
252
253/// The disconnect request asks the debug adapter to disconnect from the debuggee (thus ending the debug session) and then to shut down itself (the debug adapter).
254///
255/// In addition, the debug adapter must terminate the debuggee if it was started with the launch request. If an attach request was used to connect to the debuggee, then the debug adapter must not terminate the debuggee.
256///
257/// This implicit behavior of when to terminate the debuggee can be overridden with the terminateDebuggee argument (which is only supported by a debug adapter if the corresponding capability supportTerminateDebuggee is true).
258#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
259pub struct DisconnectArguments {
260    /// A value of true indicates that this `disconnect` request is part of a
261    /// restart sequence.
262    pub restart: bool,
263
264    /// Indicates whether the debuggee should be terminated when the debugger is disconnected.
265    /// If unspecified, the debug adapter is free to do whatever it thinks is best.
266    /// The attribute is only honored by a debug adapter if the corresponding
267    /// capability `supportTerminateDebuggee` is true.
268    #[serde(default, rename = "terminateDebuggee")]
269    pub terminate_debuggee: bool,
270
271    /// Indicates whether the debuggee should stay suspended when the debugger is disconnected.
272    /// If unspecified, the debuggee should resume execution.
273    /// The attribute is only honored by a debug adapter if the corresponding
274    /// capability `supportSuspendDebuggee` is true.
275    #[serde(default, rename = "suspendDebuggee")]
276    pub suspend_debuggee: bool,
277}