Successfully feature gate DAP

This commit is contained in:
Blaž Hrastnik 2022-03-27 17:47:33 +09:00
parent d7b1c40452
commit dcd1e9eaa3
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640
9 changed files with 86 additions and 29 deletions

View File

@ -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"

View File

@ -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();
}

View File

@ -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",

View File

@ -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 @@ 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: &[],

View File

@ -5,7 +5,7 @@
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,

View File

@ -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,

View File

@ -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"

View File

@ -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<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 @@ 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,

View File

@ -7,6 +7,7 @@
pub mod graphics;
pub mod gutter;
pub mod handlers {
#[cfg(feature = "dap")]
pub mod dap;
pub mod lsp;
}