use serde::{ser::SerializeMap, Deserialize, Serialize, Serializer};
use std::num::NonZeroUsize;
mod request;
mod response;
mod variables_arguments;
pub use self::{request::Request, response::Response, variables_arguments::VariablesArguments};
#[derive(Clone, Debug, Serialize)]
pub struct DebugCapability {
#[serde(rename = "supportsCompletionsRequest")]
pub supports_completions_request: bool,
#[serde(rename = "supportsConditionalBreakpoints")]
pub supports_conditional_breakpoints: bool,
#[serde(rename = "supportsConfigurationDoneRequest")]
pub supports_configuration_done_request: bool,
#[serde(rename = "supportsDebuggerProperties")]
pub supports_debugger_properties: bool,
#[serde(rename = "supportsDelayedStackTraceLoading")]
pub supports_delayed_stack_trace_loading: bool,
#[serde(rename = "supportsEvaluateForHovers")]
pub supports_evaluate_for_hovers: bool,
#[serde(rename = "supportsExceptionInfoRequest")]
pub supports_exception_info_request: bool,
#[serde(rename = "supportsExceptionOptions")]
pub supports_exception_options: bool,
#[serde(rename = "supportsFunctionBreakpoints")]
pub supports_function_breakpoints: bool,
#[serde(rename = "supportsHitConditionalBreakpoints")]
pub supports_hit_conditional_breakpoints: bool,
#[serde(rename = "supportsLogPoints")]
pub supports_log_points: bool,
#[serde(rename = "supportsModulesRequest")]
pub supports_modules_request: bool,
#[serde(rename = "supportsSetExpression")]
pub supports_set_expression: bool,
#[serde(rename = "supportsSetVariable")]
pub supports_set_variable: bool,
#[serde(rename = "supportsVariablePaging")]
pub supports_variable_paging: bool,
#[serde(rename = "supportsValueFormattingOptions")]
pub supports_value_formatting_options: bool,
#[serde(rename = "supportsTerminateDebuggee")]
pub supports_terminate_debuggee: bool,
#[serde(rename = "supportsGotoTargetsRequest")]
pub supports_goto_targets_request: bool,
#[serde(rename = "supportsClipboardContext")]
pub supports_clipboard_context: bool,
#[serde(rename = "supportsStepInTargetsRequest")]
pub supports_step_in_targets_request: bool,
#[serde(rename = "exceptionBreakpointFilters")]
pub exception_breakpoint_filters: Vec<ExceptionBreakpointFilter>,
}
#[derive(Clone, Debug, Serialize)]
pub struct ExceptionBreakpointFilter {
pub filter: String,
pub label: String,
pub default: bool,
}
impl Default for DebugCapability {
fn default() -> Self {
Self {
supports_completions_request: true,
supports_conditional_breakpoints: true,
supports_configuration_done_request: true,
supports_debugger_properties: true,
supports_delayed_stack_trace_loading: true,
supports_evaluate_for_hovers: true,
supports_exception_info_request: true,
supports_exception_options: true,
supports_function_breakpoints: true,
supports_hit_conditional_breakpoints: true,
supports_log_points: true,
supports_modules_request: true,
supports_set_expression: true,
supports_set_variable: true,
supports_variable_paging: true,
supports_value_formatting_options: true,
supports_terminate_debuggee: true,
supports_goto_targets_request: true,
supports_clipboard_context: true,
supports_step_in_targets_request: true,
exception_breakpoint_filters: vec![],
}
}
}
#[derive(Clone, Debug, Serialize)]
pub struct VariablesResponseBody {
pub variables: Vec<Variable>,
}
impl<V: Into<Variable>> FromIterator<V> for VariablesResponseBody {
fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self {
VariablesResponseBody { variables: iter.into_iter().map(|v| v.into()).collect() }
}
}
#[derive(Clone, Debug, Serialize)]
pub struct Variable {
pub name: String,
pub value: String,
#[serde(rename = "type")]
pub typing: String,
#[serde(rename = "evaluateName")]
pub evaluate_name: String,
#[serde(rename = "variablesReference")]
pub variables_reference: usize,
#[serde(rename = "namedVariables")]
pub named_variables: usize,
#[serde(rename = "indexedVariables")]
pub indexed_variables: usize,
#[serde(rename = "memoryReference")]
pub memory_reference: String,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct ModulesArguments {
#[serde(rename = "startModule")]
pub start: usize,
#[serde(rename = "moduleCount")]
pub count: Option<NonZeroUsize>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ModulesResponseBody {
pub modules: Vec<Module>,
#[serde(rename = "totalModules")]
pub total_modules: usize,
}
impl<M: Into<Module>> FromIterator<M> for ModulesResponseBody {
fn from_iter<T: IntoIterator<Item = M>>(iter: T) -> Self {
let mut out = ModulesResponseBody { modules: vec![], total_modules: 0 };
for m in iter.into_iter().map(|m| m.into()) {
out.modules.push(m);
out.total_modules += 1;
}
out
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Module {
pub id: u32,
pub name: String,
pub path: String,
#[serde(rename = "isOptimized")]
pub is_optimized: bool,
#[serde(rename = "isUserCode")]
pub is_user_code: bool,
pub version: String,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum VariableFilter {
Indexed,
Named,
}
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ValueFormat {
hex: Option<bool>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum DataBreakpointAccessType {
Read,
Write,
ReadWrite,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum SteppingGranularity {
Statement,
Line,
Instruction,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct DisconnectArguments {
pub restart: bool,
#[serde(default, rename = "terminateDebuggee")]
pub terminate_debuggee: bool,
#[serde(default, rename = "suspendDebuggee")]
pub suspend_debuggee: bool,
}