diff --git a/Cargo.lock b/Cargo.lock index 8a775d2f85..a2c812eba6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2991,6 +2991,34 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" +[[package]] +name = "dap" +version = "0.1.0" +dependencies = [ + "anyhow", + "dap 0.4.1-alpha1", + "futures 0.3.28", + "gpui", + "log", + "parking_lot", + "postage", + "release_channel", + "serde", + "serde_json", + "smol", + "util", +] + +[[package]] +name = "dap" +version = "0.4.1-alpha1" +source = "git+https://github.com/sztomi/dap-rs?branch=main#913a2a520416a2a81a1f09a7946f595d5ae3ee4a" +dependencies = [ + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -3039,6 +3067,29 @@ dependencies = [ "util", ] +[[package]] +name = "debugger_ui" +version = "0.1.0" +dependencies = [ + "anyhow", + "dap 0.1.0", + "db", + "editor", + "gpui", + "serde", + "serde_derive", + "ui", + "workspace", +] + +[[package]] +name = "debuggers" +version = "0.1.0" +dependencies = [ + "anyhow", + "dap 0.1.0", +] + [[package]] name = "der" version = "0.6.1" @@ -12598,6 +12649,7 @@ dependencies = [ "copilot", "copilot_ui", "db", + "debugger_ui", "diagnostics", "editor", "embed-manifest", diff --git a/Cargo.toml b/Cargo.toml index 6f35a6b41a..35b9d81c95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,9 @@ members = [ "crates/command_palette_hooks", "crates/copilot", "crates/copilot_ui", + "crates/dap", + "crates/debuggers", + "crates/debugger_ui", "crates/db", "crates/diagnostics", "crates/editor", @@ -140,6 +143,9 @@ command_palette = { path = "crates/command_palette" } command_palette_hooks = { path = "crates/command_palette_hooks" } copilot = { path = "crates/copilot" } copilot_ui = { path = "crates/copilot_ui" } +dap = { path = "crates/dap" } +debuggers = { path = "crates/debuggers" } +debugger_ui = { path = "crates/debugger_ui" } db = { path = "crates/db" } diagnostics = { path = "crates/diagnostics" } editor = { path = "crates/editor" } diff --git a/crates/dap/Cargo.toml b/crates/dap/Cargo.toml new file mode 100644 index 0000000000..19d217a639 --- /dev/null +++ b/crates/dap/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "dap" +version = "0.1.0" +edition = "2021" +publish = false +license = "GPL-3.0-or-later" + +[lints] +workspace = true + +[lib] +path = "src/dap.rs" +doctest = false + +[dependencies] +anyhow.workspace = true +dap = { git = "https://github.com/sztomi/dap-rs", branch = "main" } +futures.workspace = true +gpui.workspace = true +log.workspace = true +parking_lot.workspace = true +postage.workspace = true +release_channel.workspace = true +serde.workspace = true +serde_json.workspace = true +smol.workspace = true +util.workspace = true diff --git a/crates/dap/src/dap.rs b/crates/dap/src/dap.rs new file mode 100644 index 0000000000..1b918a4f42 --- /dev/null +++ b/crates/dap/src/dap.rs @@ -0,0 +1,8 @@ +use dap::requests::InitializeArguments; +pub use dap::*; + +pub trait DebuggerAdapter { + fn initialize(&self, args: InitializeArguments) -> anyhow::Result<()>; +} + +// impl dyn DebuggerAdapter {} diff --git a/crates/debugger_ui/Cargo.toml b/crates/debugger_ui/Cargo.toml new file mode 100644 index 0000000000..0e9eebe4cb --- /dev/null +++ b/crates/debugger_ui/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "debugger_ui" +version = "0.1.0" +edition = "2021" +publish = false +license = "GPL-3.0-or-later" + +[lints] +workspace = true + +[dependencies] +anyhow.workspace = true +dap.workspace = true +db.workspace = true +editor.workspace = true +gpui.workspace = true +serde.workspace = true +serde_derive.workspace = true +ui.workspace = true +workspace.workspace = true + +[dev-dependencies] +editor = { workspace = true, features = ["test-support"] } +gpui = { workspace = true, features = ["test-support"] } diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs new file mode 100644 index 0000000000..66ff905ff4 --- /dev/null +++ b/crates/debugger_ui/src/debugger_panel.rs @@ -0,0 +1,132 @@ +use gpui::{actions, AppContext, EventEmitter, FocusHandle, FocusableView, ViewContext}; +use ui::{ + div, h_flex, prelude, px, ButtonCommon, Element, IconButton, ParentElement, Pixels, Render, + Styled, Tooltip, WindowContext, +}; +use workspace::dock::{DockPosition, Panel, PanelEvent}; + +actions!(debug, [TogglePanel]); + +pub struct DebugPanel { + pub position: DockPosition, + pub zoomed: bool, + pub active: bool, + pub focus_handle: FocusHandle, + pub size: Pixels, +} + +impl DebugPanel { + pub fn new(position: DockPosition, cx: &mut WindowContext) -> Self { + Self { + position, + zoomed: false, + active: false, + focus_handle: cx.focus_handle(), + size: px(300.), + } + } +} + +impl EventEmitter for DebugPanel {} + +impl FocusableView for DebugPanel { + fn focus_handle(&self, _cx: &AppContext) -> FocusHandle { + self.focus_handle.clone() + } +} + +impl Panel for DebugPanel { + fn persistent_name() -> &'static str { + "DebugPanel" + } + + fn position(&self, _cx: &prelude::WindowContext) -> workspace::dock::DockPosition { + self.position + } + + fn position_is_valid(&self, _position: workspace::dock::DockPosition) -> bool { + true + } + + fn set_position( + &mut self, + position: workspace::dock::DockPosition, + _cx: &mut ViewContext, + ) { + self.position = position; + // TODO: + // cx.update_global::(f) + } + + fn size(&self, _cx: &prelude::WindowContext) -> prelude::Pixels { + self.size + } + + fn set_size(&mut self, size: Option, _cx: &mut ViewContext) { + self.size = size.unwrap(); + } + + fn icon(&self, _cx: &prelude::WindowContext) -> Option { + None + } + + fn icon_tooltip(&self, _cx: &prelude::WindowContext) -> Option<&'static str> { + None + } + + fn toggle_action(&self) -> Box { + Box::new(TogglePanel) + } + + fn icon_label(&self, _: &WindowContext) -> Option { + None + } + + fn is_zoomed(&self, _cx: &WindowContext) -> bool { + false + } + + fn starts_open(&self, _cx: &WindowContext) -> bool { + false + } + + fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext) {} + + fn set_active(&mut self, _active: bool, _cx: &mut ViewContext) {} +} + +impl Render for DebugPanel { + fn render(&mut self, _: &mut ViewContext) -> impl prelude::IntoElement { + div() + .child( + h_flex() + .p_2() + .gap_2() + .child( + IconButton::new("debug-play", ui::IconName::Play) + .tooltip(move |cx| Tooltip::text("Start debug", cx)), + ) + .child( + IconButton::new("debug-step-over", ui::IconName::Play) + .tooltip(move |cx| Tooltip::text("Step over", cx)), + ) + .child( + IconButton::new("debug-go-in", ui::IconName::Play) + .tooltip(move |cx| Tooltip::text("Go in", cx)), + ) + .child( + IconButton::new("debug-go-out", ui::IconName::Play) + .tooltip(move |cx| Tooltip::text("Go out", cx)), + ) + .child( + IconButton::new("debug-restart", ui::IconName::Play) + .tooltip(move |cx| Tooltip::text("Restart", cx)), + ) + .child( + IconButton::new("debug-stop", ui::IconName::Play) + .tooltip(move |cx| Tooltip::text("Stop", cx)), + ), + ) + .into_any() + } +} diff --git a/crates/debugger_ui/src/lib.rs b/crates/debugger_ui/src/lib.rs new file mode 100644 index 0000000000..0b4539ced8 --- /dev/null +++ b/crates/debugger_ui/src/lib.rs @@ -0,0 +1,23 @@ +use debugger_panel::{DebugPanel, TogglePanel}; +use gpui::{AppContext, ViewContext}; +use serde::{Deserialize, Serialize}; +use ui::Pixels; +use workspace::Workspace; + +pub mod debugger_panel; + +#[derive(Serialize, Deserialize)] +struct SerializedDebugPanel { + width: Option, +} + +pub fn init(cx: &mut AppContext) { + cx.observe_new_views( + |workspace: &mut Workspace, _: &mut ViewContext| { + workspace.register_action(|workspace, _action: &TogglePanel, cx| { + workspace.focus_panel::(cx); + }); + }, + ) + .detach(); +} diff --git a/crates/debuggers/Cargo.toml b/crates/debuggers/Cargo.toml new file mode 100644 index 0000000000..6a3638be22 --- /dev/null +++ b/crates/debuggers/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "debuggers" +version = "0.1.0" +edition = "2021" +publish = false +license = "GPL-3.0-or-later" + +[dependencies] +dap.workspace = true +anyhow.workspace = true + +[lints] +workspace = true diff --git a/crates/debuggers/src/lib.rs b/crates/debuggers/src/lib.rs new file mode 100644 index 0000000000..a0ebc5f51b --- /dev/null +++ b/crates/debuggers/src/lib.rs @@ -0,0 +1,2 @@ +mod node; +mod xdebug; diff --git a/crates/debuggers/src/node.rs b/crates/debuggers/src/node.rs new file mode 100644 index 0000000000..a3da178bf3 --- /dev/null +++ b/crates/debuggers/src/node.rs @@ -0,0 +1,9 @@ +use dap::DebuggerAdapter; + +pub struct JsAdapter; + +impl DebuggerAdapter for JsAdapter { + fn initialize(&self, args: dap::requests::InitializeArguments) -> anyhow::Result<()> { + todo!() + } +} diff --git a/crates/debuggers/src/xdebug.rs b/crates/debuggers/src/xdebug.rs new file mode 100644 index 0000000000..89c300fd3f --- /dev/null +++ b/crates/debuggers/src/xdebug.rs @@ -0,0 +1,12 @@ +use dap::{requests::InitializeArguments, DebuggerAdapter}; + +pub struct Xdebug; + +impl DebuggerAdapter for Xdebug { + fn initialize(&self, _args: InitializeArguments) -> anyhow::Result<()> { + if true != false { + println!("Hello, world!"); + } + todo!() + } +} diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 599c9ddd16..90a0b414eb 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -35,6 +35,7 @@ collections.workspace = true command_palette.workspace = true copilot.workspace = true copilot_ui.workspace = true +debugger_ui.workspace = true db.workspace = true diagnostics.workspace = true editor.workspace = true diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index dac37ba7f0..13836c2852 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -272,6 +272,7 @@ fn main() { project_symbols::init(cx); project_panel::init(Assets, cx); tasks_ui::init(cx); + debugger_ui::init(cx); channel::init(&client, user_store.clone(), cx); search::init(cx); vim::init(cx); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index e8018b362c..b642b99452 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -7,6 +7,7 @@ use assistant::AssistantPanel; use breadcrumbs::Breadcrumbs; use client::ZED_URL_SCHEME; use collections::VecDeque; +use debugger_ui::debugger_panel::DebugPanel; use editor::{scroll::Autoscroll, Editor, MultiBuffer}; use gpui::{ actions, point, px, AppContext, AsyncAppContext, Context, FocusableView, PromptLevel, @@ -201,6 +202,11 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { workspace_handle.clone(), cx.clone(), ); + + let debug_panel = workspace_handle.update(&mut cx.clone(), |workspace, cx| { + cx.new_view(|cx| DebugPanel::new(workspace::dock::DockPosition::Bottom, cx)) + })?; + let ( project_panel, terminal_panel, @@ -224,6 +230,7 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { workspace.add_panel(channels_panel, cx); workspace.add_panel(chat_panel, cx); workspace.add_panel(notification_panel, cx); + workspace.add_panel(debug_panel, cx); cx.focus_self(); }) })