diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 706453ae6..6ddb81648 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -16,6 +16,8 @@ build = true app = true [features] +# default = ["dap"] +dap = ["helix-dap", "helix-view/dap"] unicode-lines = ["helix-core/unicode-lines"] [[bin]] @@ -26,7 +28,7 @@ path = "src/main.rs" helix-core = { version = "0.6", path = "../helix-core" } helix-view = { version = "0.6", path = "../helix-view" } helix-lsp = { version = "0.6", path = "../helix-lsp" } -helix-dap = { version = "0.6", path = "../helix-dap" } +helix-dap = { version = "0.6", path = "../helix-dap", optional = true } helix-loader = { version = "0.6", path = "../helix-loader" } anyhow = "1" diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index c4b623948..8b8f17e05 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -247,7 +247,9 @@ pub async fn event_loop(&mut self) { } } Some(payload) = self.editor.debugger_events.next() => { + #[cfg(feature = "dap")] let needs_render = self.editor.handle_debugger_message(payload).await; + #[cfg(feature = "dap")] if needs_render { self.render(); } diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 0c12c7f65..ec55ac66a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1,7 +1,9 @@ +#[cfg(feature = "dap")] pub(crate) mod dap; pub(crate) mod lsp; pub(crate) mod typed; +#[cfg(feature = "dap")] pub use dap::*; pub use lsp::*; pub use typed::*; @@ -139,8 +141,10 @@ pub enum MappableCommand { } macro_rules! static_commands { - ( $($name:ident, $doc:literal,)* ) => { + ( $($(#[cfg($attr:meta)])? $name:ident, $doc:literal,)* ) => { $( + + $(#[cfg($attr)])? #[allow(non_upper_case_globals)] pub const $name: Self = Self::Static { name: stringify!($name), @@ -150,7 +154,7 @@ macro_rules! static_commands { )* pub const STATIC_COMMAND_LIST: &'static [Self] = &[ - $( Self::$name, )* + $( $(#[cfg($attr)])? Self::$name, )* ]; } } @@ -389,20 +393,35 @@ pub fn doc(&self) -> &str { goto_prev_comment, "Goto previous comment", goto_next_paragraph, "Goto next paragraph", goto_prev_paragraph, "Goto previous paragraph", + #[cfg(feature = "dap")] dap_launch, "Launch debug target", + #[cfg(feature = "dap")] dap_toggle_breakpoint, "Toggle breakpoint", + #[cfg(feature = "dap")] dap_continue, "Continue program execution", + #[cfg(feature = "dap")] dap_pause, "Pause program execution", + #[cfg(feature = "dap")] dap_step_in, "Step in", + #[cfg(feature = "dap")] dap_step_out, "Step out", + #[cfg(feature = "dap")] dap_next, "Step to next", + #[cfg(feature = "dap")] dap_variables, "List variables", + #[cfg(feature = "dap")] dap_terminate, "End debug session", + #[cfg(feature = "dap")] dap_edit_condition, "Edit condition of the breakpoint on the current line", + #[cfg(feature = "dap")] dap_edit_log, "Edit log message of the breakpoint on the current line", + #[cfg(feature = "dap")] dap_switch_thread, "Switch current thread", + #[cfg(feature = "dap")] dap_switch_stack_frame, "Switch stack frame", + #[cfg(feature = "dap")] dap_enable_exceptions, "Enable exception breakpoints", + #[cfg(feature = "dap")] dap_disable_exceptions, "Disable exception breakpoints", shell_pipe, "Pipe selections through shell command", shell_pipe_to, "Pipe selections into shell command, ignoring command output", diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 394760a2f..d3e185c79 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -847,6 +847,7 @@ fn hsplit_new( Ok(()) } +#[cfg(feature = "dap")] fn debug_eval( cx: &mut compositor::Context, args: &[Cow], @@ -869,6 +870,7 @@ fn debug_eval( Ok(()) } +#[cfg(feature = "dap")] fn debug_start( cx: &mut compositor::Context, args: &[Cow], @@ -882,6 +884,7 @@ fn debug_start( dap_start_impl(cx, name.as_deref(), None, Some(args)) } +#[cfg(feature = "dap")] fn debug_remote( cx: &mut compositor::Context, args: &[Cow], @@ -1435,6 +1438,7 @@ fn pipe( fun: tree_sitter_scopes, completer: None, }, + #[cfg(feature = "dap")] TypableCommand { name: "debug-start", aliases: &["dbg"], @@ -1442,6 +1446,7 @@ fn pipe( fun: debug_start, completer: None, }, + #[cfg(feature = "dap")] TypableCommand { name: "debug-remote", aliases: &["dbg-tcp"], @@ -1449,6 +1454,7 @@ fn pipe( fun: debug_remote, completer: None, }, + #[cfg(feature = "dap")] TypableCommand { name: "debug-eval", aliases: &[], diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index db24e97a7..a1037beb8 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -5,7 +5,7 @@ use helix_core::hashmap; pub fn default() -> HashMap { - let normal = keymap!({ "Normal mode" + let mut normal = keymap!({ "Normal mode" "h" | "left" => move_char_left, "j" | "down" => move_line_down, "k" | "up" => move_line_up, @@ -202,26 +202,6 @@ pub fn default() -> HashMap { "S" => workspace_symbol_picker, "a" => code_action, "'" => last_picker, - "d" => { "Debug (experimental)" sticky=true - "l" => dap_launch, - "b" => dap_toggle_breakpoint, - "c" => dap_continue, - "h" => dap_pause, - "i" => dap_step_in, - "o" => dap_step_out, - "n" => dap_next, - "v" => dap_variables, - "t" => dap_terminate, - "C-c" => dap_edit_condition, - "C-l" => dap_edit_log, - "s" => { "Switch" - "t" => dap_switch_thread, - "f" => dap_switch_stack_frame, - // sl, sb - }, - "e" => dap_enable_exceptions, - "E" => dap_disable_exceptions, - }, "w" => { "Window" "C-w" | "w" => rotate_view, "C-s" | "s" => hsplit, @@ -285,6 +265,34 @@ pub fn default() -> HashMap { "C-a" => increment, "C-x" => decrement, }); + + // DAP + #[cfg(feature = "dap")] + normal.merge_nodes(keymap!({ "Normal mode" + "space" => { "Space" + "d" => { "Debug (experimental)" sticky=true + "l" => dap_launch, + "b" => dap_toggle_breakpoint, + "c" => dap_continue, + "h" => dap_pause, + "i" => dap_step_in, + "o" => dap_step_out, + "n" => dap_next, + "v" => dap_variables, + "t" => dap_terminate, + "C-c" => dap_edit_condition, + "C-l" => dap_edit_log, + "s" => { "Switch" + "t" => dap_switch_thread, + "f" => dap_switch_stack_frame, + // sl, sb + }, + "e" => dap_enable_exceptions, + "E" => dap_disable_exceptions, + }, + }, + })); + let mut select = normal.clone(); select.merge_nodes(keymap!({ "Select mode" "h" | "left" => extend_char_left, diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index d2f4d1467..6775b5b2d 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -80,6 +80,7 @@ pub fn render_view( let theme = &editor.theme; // DAP: Highlight current stack frame position + #[cfg(feature = "dap")] let stack_frame = editor.debugger.as_ref().and_then(|debugger| { if let (Some(frame), Some(thread_id)) = (debugger.active_frame, debugger.thread_id) { debugger @@ -90,6 +91,7 @@ pub fn render_view( None } }); + #[cfg(feature = "dap")] if let Some(frame) = stack_frame { if doc.path().is_some() && frame @@ -957,6 +959,7 @@ fn handle_mouse_event( ) -> EventResult { let config = cxt.editor.config(); match event { + #[cfg(feature = "dap")] MouseEvent { kind: MouseEventKind::Down(MouseButton::Left), row, @@ -1084,6 +1087,7 @@ fn handle_mouse_event( EventResult::Consumed(None) } + #[cfg(feature = "dap")] MouseEvent { kind: MouseEventKind::Up(MouseButton::Right), row, diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index ce3f1af4b..52b2077a5 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -10,7 +10,8 @@ repository = "https://github.com/helix-editor/helix" homepage = "https://helix-editor.com" [features] -default = [] +# default = ["dap"] +dap = ["helix-dap", "tokio-stream"] term = ["crossterm"] [dependencies] @@ -18,7 +19,9 @@ bitflags = "1.3" anyhow = "1" helix-core = { version = "0.6", path = "../helix-core" } helix-lsp = { version = "0.6", path = "../helix-lsp" } -helix-dap = { version = "0.6", path = "../helix-dap" } +helix-dap = { version = "0.6", path = "../helix-dap", optional = true } +tokio-stream = { version = "0.1", optional = true } + crossterm = { version = "0.23", optional = true } # Conversion traits @@ -28,7 +31,6 @@ url = "2" arc-swap = { version = "1.5.0" } tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } -tokio-stream = "0.1" futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false } slotmap = "1" diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 0de1732c3..1d0e5ba8a 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -10,8 +10,6 @@ }; use futures_util::future; -use futures_util::stream::select_all::SelectAll; -use tokio_stream::wrappers::UnboundedReceiverStream; use std::{ borrow::Cow, @@ -38,6 +36,13 @@ Change, }; use helix_core::{Position, Selection}; + +#[cfg(feature = "dap")] +use futures_util::stream::select_all::SelectAll; +#[cfg(feature = "dap")] +use tokio_stream::wrappers::UnboundedReceiverStream; + +#[cfg(feature = "dap")] use helix_dap as dap; use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer}; @@ -433,8 +438,12 @@ pub struct Editor { pub theme: Theme, pub language_servers: helix_lsp::Registry, + #[cfg(feature = "dap")] pub debugger: Option, + #[cfg(feature = "dap")] pub debugger_events: SelectAll>, + #[cfg(not(feature = "dap"))] + pub debugger_events: futures_util::stream::Empty<()>, pub breakpoints: HashMap>, pub clipboard_provider: Box, @@ -502,8 +511,12 @@ pub fn new( macro_recording: None, theme: theme_loader.default(), language_servers, + #[cfg(feature = "dap")] debugger: None, + #[cfg(feature = "dap")] debugger_events: SelectAll::new(), + #[cfg(not(feature = "dap"))] + debugger_events: futures_util::stream::empty(), breakpoints: HashMap::new(), syn_loader, theme_loader, diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs index 788304bce..a77ce1556 100644 --- a/helix-view/src/lib.rs +++ b/helix-view/src/lib.rs @@ -7,6 +7,7 @@ pub mod graphics; pub mod gutter; pub mod handlers { + #[cfg(feature = "dap")] pub mod dap; pub mod lsp; }