Unnamed repository; edit this file 'description' to name the repository.
Successfully feature gate DAP
Blaž Hrastnik 2022-05-01
parent d7b1c40 · commit dcd1e9e
-rw-r--r--helix-term/Cargo.toml4
-rw-r--r--helix-term/src/application.rs2
-rw-r--r--helix-term/src/commands.rs23
-rw-r--r--helix-term/src/commands/typed.rs6
-rw-r--r--helix-term/src/keymap/default.rs50
-rw-r--r--helix-term/src/ui/editor.rs4
-rw-r--r--helix-view/Cargo.toml8
-rw-r--r--helix-view/src/editor.rs17
-rw-r--r--helix-view/src/lib.rs1
9 files changed, 86 insertions, 29 deletions
diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml
index 706453ae..6ddb8164 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 c4b62394..8b8f17e0 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -247,7 +247,9 @@ impl Application {
}
}
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 0c12c7f6..ec55ac66 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 @@ impl MappableCommand {
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 394760a2..d3e185c7 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<str>],
@@ -869,6 +870,7 @@ fn debug_eval(
Ok(())
}
+#[cfg(feature = "dap")]
fn debug_start(
cx: &mut compositor::Context,
args: &[Cow<str>],
@@ -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<str>],
@@ -1435,6 +1438,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
fun: tree_sitter_scopes,
completer: None,
},
+ #[cfg(feature = "dap")]
TypableCommand {
name: "debug-start",
aliases: &["dbg"],
@@ -1442,6 +1446,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
fun: debug_start,
completer: None,
},
+ #[cfg(feature = "dap")]
TypableCommand {
name: "debug-remote",
aliases: &["dbg-tcp"],
@@ -1449,6 +1454,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
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 db24e97a..a1037beb 100644
--- a/helix-term/src/keymap/default.rs
+++ b/helix-term/src/keymap/default.rs
@@ -5,7 +5,7 @@ use super::{Keymap, Mode};
use helix_core::hashmap;
pub fn default() -> HashMap<Mode, Keymap> {
- 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<Mode, Keymap> {
"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<Mode, Keymap> {
"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 d2f4d146..6775b5b2 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -80,6 +80,7 @@ impl EditorView {
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 @@ impl EditorView {
None
}
});
+ #[cfg(feature = "dap")]
if let Some(frame) = stack_frame {
if doc.path().is_some()
&& frame
@@ -957,6 +959,7 @@ impl EditorView {
) -> EventResult {
let config = cxt.editor.config();
match event {
+ #[cfg(feature = "dap")]
MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
row,
@@ -1084,6 +1087,7 @@ impl EditorView {
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 ce3f1af4..52b2077a 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 0de1732c..1d0e5ba8 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -10,8 +10,6 @@ use crate::{
};
use futures_util::future;
-use futures_util::stream::select_all::SelectAll;
-use tokio_stream::wrappers::UnboundedReceiverStream;
use std::{
borrow::Cow,
@@ -38,6 +36,13 @@ use helix_core::{
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<dap::Client>,
+ #[cfg(feature = "dap")]
pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>,
+ #[cfg(not(feature = "dap"))]
+ pub debugger_events: futures_util::stream::Empty<()>,
pub breakpoints: HashMap<PathBuf, Vec<Breakpoint>>,
pub clipboard_provider: Box<dyn ClipboardProvider>,
@@ -502,8 +511,12 @@ impl Editor {
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 788304bc..a77ce155 100644
--- a/helix-view/src/lib.rs
+++ b/helix-view/src/lib.rs
@@ -7,6 +7,7 @@ pub mod editor;
pub mod graphics;
pub mod gutter;
pub mod handlers {
+ #[cfg(feature = "dap")]
pub mod dap;
pub mod lsp;
}