debugger_settings.rs

 1use dap_types::SteppingGranularity;
 2use gpui::App;
 3use settings::{Settings, SettingsContent};
 4use util::MergeFrom;
 5
 6pub struct DebuggerSettings {
 7    /// Determines the stepping granularity.
 8    ///
 9    /// Default: line
10    pub stepping_granularity: SteppingGranularity,
11    /// Whether the breakpoints should be reused across Zed sessions.
12    ///
13    /// Default: true
14    pub save_breakpoints: bool,
15    /// Whether to show the debug button in the status bar.
16    ///
17    /// Default: true
18    pub button: bool,
19    /// Time in milliseconds until timeout error when connecting to a TCP debug adapter
20    ///
21    /// Default: 2000ms
22    pub timeout: u64,
23    /// Whether to log messages between active debug adapters and Zed
24    ///
25    /// Default: true
26    pub log_dap_communications: bool,
27    /// Whether to format dap messages in when adding them to debug adapter logger
28    ///
29    /// Default: true
30    pub format_dap_log_messages: bool,
31    /// The dock position of the debug panel
32    ///
33    /// Default: Bottom
34    pub dock: settings::DockPosition,
35}
36
37impl Settings for DebuggerSettings {
38    fn from_defaults(content: &SettingsContent, _cx: &mut App) -> Self {
39        let content = content.debugger.clone().unwrap();
40        Self {
41            stepping_granularity: dap_granularity_from_settings(
42                content.stepping_granularity.unwrap(),
43            ),
44            save_breakpoints: content.save_breakpoints.unwrap(),
45            button: content.button.unwrap(),
46            timeout: content.timeout.unwrap(),
47            log_dap_communications: content.log_dap_communications.unwrap(),
48            format_dap_log_messages: content.format_dap_log_messages.unwrap(),
49            dock: content.dock.unwrap(),
50        }
51    }
52
53    fn refine(&mut self, content: &SettingsContent, _cx: &mut App) {
54        let Some(content) = &content.debugger else {
55            return;
56        };
57        self.stepping_granularity.merge_from(
58            &content
59                .stepping_granularity
60                .map(dap_granularity_from_settings),
61        );
62        self.save_breakpoints.merge_from(&content.save_breakpoints);
63        self.button.merge_from(&content.button);
64        self.timeout.merge_from(&content.timeout);
65        self.log_dap_communications
66            .merge_from(&content.log_dap_communications);
67        self.format_dap_log_messages
68            .merge_from(&content.format_dap_log_messages);
69        self.dock.merge_from(&content.dock);
70    }
71
72    fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut SettingsContent) {}
73}
74
75fn dap_granularity_from_settings(
76    granularity: settings::SteppingGranularity,
77) -> dap_types::SteppingGranularity {
78    match granularity {
79        settings::SteppingGranularity::Instruction => dap_types::SteppingGranularity::Instruction,
80        settings::SteppingGranularity::Line => dap_types::SteppingGranularity::Line,
81        settings::SteppingGranularity::Statement => dap_types::SteppingGranularity::Statement,
82    }
83}