From 44f596334aeda7c540fbe12d2653c86dae686470 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 4 Jul 2022 09:30:36 -0500 Subject: [PATCH] DAP: Skip serializing `Option`s when `None` DAP follows the same strict TypeScript interface syntax as LSP which states: > The document uses TypeScript interfaces in strict mode to describe > these. This means for example that a `null` value has to be explicitly > listed and that a mandatory property must be listed even if a falsify > value might exist. So we have to skip serializing any fields that end in `?` instead of passing `null`. --- helix-dap/src/types.rs | 174 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 168 insertions(+), 6 deletions(-) diff --git a/helix-dap/src/types.rs b/helix-dap/src/types.rs index fd8456a4..71b2aa83 100644 --- a/helix-dap/src/types.rs +++ b/helix-dap/src/types.rs @@ -27,9 +27,11 @@ pub trait Request { pub struct ColumnDescriptor { pub attribute_name: String, pub label: String, + #[serde(skip_serializing_if = "Option::is_none")] pub format: Option, - #[serde(rename = "type")] + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] pub ty: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub width: Option, } @@ -38,52 +40,94 @@ pub struct ColumnDescriptor { pub struct ExceptionBreakpointsFilter { pub filter: String, pub label: String, + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub default: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_condition: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub condition_description: Option, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct DebuggerCapabilities { + #[serde(skip_serializing_if = "Option::is_none")] pub supports_configuration_done_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_function_breakpoints: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_conditional_breakpoints: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_hit_conditional_breakpoints: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_evaluate_for_hovers: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_step_back: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_set_variable: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_restart_frame: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_goto_targets_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_step_in_targets_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_completions_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_modules_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_restart_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_exception_options: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_value_formatting_options: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_exception_info_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub support_terminate_debuggee: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub support_suspend_debuggee: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_delayed_stack_trace_loading: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_loaded_sources_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_log_points: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_terminate_threads_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_set_expression: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_terminate_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_data_breakpoints: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_read_memory_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_write_memory_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_disassemble_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_cancel_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_breakpoint_locations_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_clipboard_context: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_stepping_granularity: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_instruction_breakpoints: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_exception_filter_options: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub exception_breakpoint_filters: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub completion_trigger_characters: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub additional_module_columns: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub supported_checksum_algorithms: Option>, } @@ -97,13 +141,21 @@ pub struct Checksum { #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Source { + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub path: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub source_reference: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub presentation_hint: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub origin: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub sources: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub adapter_data: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub checksums: Option>, } @@ -111,36 +163,56 @@ pub struct Source { #[serde(rename_all = "camelCase")] pub struct SourceBreakpoint { pub line: usize, + #[serde(skip_serializing_if = "Option::is_none")] pub column: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub condition: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub hit_condition: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub log_message: Option, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Breakpoint { + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, pub verified: bool, + #[serde(skip_serializing_if = "Option::is_none")] pub message: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub source: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub line: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub column: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub end_line: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub end_column: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub instruction_reference: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub offset: Option, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct StackFrameFormat { + #[serde(skip_serializing_if = "Option::is_none")] pub parameters: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parameter_types: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parameter_names: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parameter_values: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub line: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub module: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub include_all: Option, } @@ -149,14 +221,21 @@ pub struct StackFrameFormat { pub struct StackFrame { pub id: usize, pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] pub source: Option, pub line: usize, pub column: usize, + #[serde(skip_serializing_if = "Option::is_none")] pub end_line: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub end_column: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub can_restart: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub instruction_pointer_reference: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub module_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub presentation_hint: Option, } @@ -171,29 +250,41 @@ pub struct Thread { #[serde(rename_all = "camelCase")] pub struct Scope { pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] pub presentation_hint: Option, pub variables_reference: usize, + #[serde(skip_serializing_if = "Option::is_none")] pub named_variables: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub indexed_variables: Option, pub expensive: bool, + #[serde(skip_serializing_if = "Option::is_none")] pub source: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub line: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub column: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub end_line: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub end_column: Option, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct ValueFormat { + #[serde(skip_serializing_if = "Option::is_none")] pub hex: Option, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct VariablePresentationHint { + #[serde(skip_serializing_if = "Option::is_none")] pub kind: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub attributes: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub visibility: Option, } @@ -202,13 +293,18 @@ pub struct VariablePresentationHint { pub struct Variable { pub name: String, pub value: String, - #[serde(rename = "type")] + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] pub ty: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub presentation_hint: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub evaluate_name: Option, pub variables_reference: usize, + #[serde(skip_serializing_if = "Option::is_none")] pub named_variables: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub indexed_variables: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub memory_reference: Option, } @@ -217,13 +313,21 @@ pub struct Variable { pub struct Module { pub id: String, // TODO: || number pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] pub path: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub is_optimized: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub is_user_code: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub version: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub symbol_status: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub symbol_file_path: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub date_time_stamp: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub address_range: Option, } @@ -232,22 +336,31 @@ pub mod requests { #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct InitializeArguments { - #[serde(rename = "clientID")] + #[serde(rename = "clientID", skip_serializing_if = "Option::is_none")] pub client_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub client_name: Option, #[serde(rename = "adapterID")] pub adapter_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub locale: Option, - #[serde(rename = "linesStartAt1")] + #[serde(rename = "linesStartAt1", skip_serializing_if = "Option::is_none")] pub lines_start_at_one: Option, - #[serde(rename = "columnsStartAt1")] + #[serde(rename = "columnsStartAt1", skip_serializing_if = "Option::is_none")] pub columns_start_at_one: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub path_format: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_variable_type: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_variable_paging: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_run_in_terminal_request: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_memory_references: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_progress_reporting: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub supports_invalidated_event: Option, } @@ -300,14 +413,17 @@ pub mod requests { #[serde(rename_all = "camelCase")] pub struct SetBreakpointsArguments { pub source: Source, + #[serde(skip_serializing_if = "Option::is_none")] pub breakpoints: Option>, // lines is deprecated + #[serde(skip_serializing_if = "Option::is_none")] pub source_modified: Option, } #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct SetBreakpointsResponse { + #[serde(skip_serializing_if = "Option::is_none")] pub breakpoints: Option>, } @@ -329,6 +445,7 @@ pub mod requests { #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct ContinueResponse { + #[serde(skip_serializing_if = "Option::is_none")] pub all_threads_continued: Option, } @@ -345,14 +462,18 @@ pub mod requests { #[serde(rename_all = "camelCase")] pub struct StackTraceArguments { pub thread_id: ThreadId, + #[serde(skip_serializing_if = "Option::is_none")] pub start_frame: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub levels: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub format: Option, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct StackTraceResponse { + #[serde(skip_serializing_if = "Option::is_none")] pub total_frames: Option, pub stack_frames: Vec, } @@ -406,9 +527,13 @@ pub mod requests { #[serde(rename_all = "camelCase")] pub struct VariablesArguments { pub variables_reference: usize, + #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub start: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub count: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub format: Option, } @@ -431,7 +556,9 @@ pub mod requests { #[serde(rename_all = "camelCase")] pub struct StepInArguments { pub thread_id: ThreadId, + #[serde(skip_serializing_if = "Option::is_none")] pub target_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub granularity: Option, } @@ -448,6 +575,7 @@ pub mod requests { #[serde(rename_all = "camelCase")] pub struct StepOutArguments { pub thread_id: ThreadId, + #[serde(skip_serializing_if = "Option::is_none")] pub granularity: Option, } @@ -464,6 +592,7 @@ pub mod requests { #[serde(rename_all = "camelCase")] pub struct NextArguments { pub thread_id: ThreadId, + #[serde(skip_serializing_if = "Option::is_none")] pub granularity: Option, } @@ -495,8 +624,11 @@ pub mod requests { #[serde(rename_all = "camelCase")] pub struct EvaluateArguments { pub expression: String, + #[serde(skip_serializing_if = "Option::is_none")] pub frame_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub context: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub format: Option, } @@ -504,12 +636,16 @@ pub mod requests { #[serde(rename_all = "camelCase")] pub struct EvaluateResponse { pub result: String, - #[serde(rename = "type")] + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] pub ty: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub presentation_hint: Option, pub variables_reference: usize, + #[serde(skip_serializing_if = "Option::is_none")] pub named_variables: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub indexed_variables: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub memory_reference: Option, } @@ -533,6 +669,7 @@ pub mod requests { #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct SetExceptionBreakpointsResponse { + #[serde(skip_serializing_if = "Option::is_none")] pub breakpoints: Option>, } @@ -550,17 +687,23 @@ pub mod requests { #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct RunInTerminalResponse { + #[serde(skip_serializing_if = "Option::is_none")] pub process_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub shell_process_id: Option, } #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct RunInTerminalArguments { + #[serde(skip_serializing_if = "Option::is_none")] pub kind: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub cwd: Option, pub args: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub env: Option>>, } @@ -607,11 +750,17 @@ pub mod events { #[serde(rename_all = "camelCase")] pub struct Stopped { pub reason: String, + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thread_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub preserve_focus_hint: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub text: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub all_threads_stopped: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub hit_breakpoint_ids: Option>, } @@ -619,6 +768,7 @@ pub mod events { #[serde(rename_all = "camelCase")] pub struct Continued { pub thread_id: ThreadId, + #[serde(skip_serializing_if = "Option::is_none")] pub all_threads_continued: Option, } @@ -631,6 +781,7 @@ pub mod events { #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Terminated { + #[serde(skip_serializing_if = "Option::is_none")] pub restart: Option, } @@ -645,12 +796,19 @@ pub mod events { #[serde(rename_all = "camelCase")] pub struct Output { pub output: String, + #[serde(skip_serializing_if = "Option::is_none")] pub category: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub group: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub line: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub column: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub variables_reference: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub source: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub data: Option, } @@ -679,9 +837,13 @@ pub mod events { #[serde(rename_all = "camelCase")] pub struct Process { pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] pub system_process_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub is_local_process: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub start_method: Option, // TODO: use enum + #[serde(skip_serializing_if = "Option::is_none")] pub pointer_size: Option, }