Skip to content

Commit

Permalink
WIP refactor (zed-industries#110)
Browse files Browse the repository at this point in the history
* WIP

Co-Authored-By: Piotr Osiewicz <[email protected]>
Co-Authored-By: Anthony Eid <[email protected]>

* Tear stuff out and make the world burn

Co-authored-by: Remco Smits <[email protected]>
Co-authored-by: Piotr <[email protected]>

* Fix compile errors

* Remove dap_store from module list and fix some warnings

Module list now uses Entity<DebugSession> to get active modules and handle remote/local state
so dap_store is no longer needed

* Add Cacheable Command trait

This gets rid of ClientRequest or whatever the name was; we don't need to enumerate every possible request and repeat ourselves, instead letting you mark any request as cached with no extra boilerplate.

* Add Eq requirement for RequestSlot

* Implement DapCommand for Arc<DapCommand>

That way we can use a single allocated block for each dap command to store it as both the cache key and the command itself.

* Clone Arc on demand

* Add request helper

* Start work on setting up a new dap_command_handler

* Make clippy pass

* Add loaded sources dap command

* Set up module list test to see if Modules request is called

* Fix compile warnings

* Add basic local module_list test

* Add module list event testing to test_module_list

* Bring back as_any_arc

* Only reset module list's list state when modules_len changes

---------

Co-authored-by: Piotr Osiewicz <[email protected]>
Co-authored-by: Anthony Eid <[email protected]>
Co-authored-by: Anthony Eid <[email protected]>
Co-authored-by: Piotr <[email protected]>
  • Loading branch information
5 people authored Feb 7, 2025
1 parent 16eff80 commit af77b2f
Show file tree
Hide file tree
Showing 21 changed files with 969 additions and 328 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions crates/collab/src/tests/debug_panel_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,15 +1255,15 @@ async fn test_module_list(
"Local supports modules request should be true"
);

let local_module_list = item.module_list().read(cx).modules();
let local_module_list = item.module_list().update(cx, |list, cx| list.modules(cx));

assert_eq!(
2usize,
local_module_list.len(),
"Local module list should have two items in it"
);
assert_eq!(
&modules.clone(),
modules.clone(),
local_module_list,
"Local module list should match module list from response"
);
Expand All @@ -1282,15 +1282,15 @@ async fn test_module_list(
item.capabilities(cx).supports_modules_request.unwrap(),
"Remote capabilities supports modules request should be true"
);
let remote_module_list = item.module_list().read(cx).modules();
let remote_module_list = item.module_list().update(cx, |list, cx| list.modules(cx));

assert_eq!(
2usize,
remote_module_list.len(),
"Remote module list should have two items in it"
);
assert_eq!(
&modules.clone(),
modules.clone(),
remote_module_list,
"Remote module list should match module list from response"
);
Expand All @@ -1313,15 +1313,15 @@ async fn test_module_list(
item.capabilities(cx).supports_modules_request.unwrap(),
"Remote (mid session join) capabilities supports modules request should be true"
);
let remote_module_list = item.module_list().read(cx).modules();
let remote_module_list = item.module_list().update(cx, |list, cx| list.modules(cx));

assert_eq!(
2usize,
remote_module_list.len(),
"Remote (mid session join) module list should have two items in it"
);
assert_eq!(
&modules.clone(),
modules.clone(),
remote_module_list,
"Remote (mid session join) module list should match module list from response"
);
Expand Down
2 changes: 1 addition & 1 deletion crates/dap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async-tar.workspace = true
async-trait.workspace = true
client.workspace = true
collections.workspace = true
dap-types = { git = "https://github.com/zed-industries/dap-types", rev = "f44d7d8af3a8af3e0ca09933271bee17c99e15b1" }
dap-types = { git = "https://github.com/zed-industries/dap-types", rev = "bf5632dc19f806e8a435c9f04a4bfe7322badea2" }
fs.workspace = true
futures.workspace = true
gpui.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/dap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod adapters;
pub mod client;
pub mod debugger_settings;
pub mod proto_conversions;
pub mod session;
pub mod transport;

pub use dap_types::*;
Expand Down
146 changes: 0 additions & 146 deletions crates/dap/src/session.rs

This file was deleted.

7 changes: 5 additions & 2 deletions crates/debugger_tools/src/dap_log.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use dap::{
client::{DebugAdapterClient, DebugAdapterClientId},
debugger_settings::DebuggerSettings,
session::{DebugSession, DebugSessionId},
transport::{IoKind, LogKind},
};
use editor::{Editor, EditorEvent};
Expand All @@ -13,7 +12,11 @@ use gpui::{
actions, div, App, AppContext, Context, Empty, Entity, EventEmitter, FocusHandle, Focusable,
IntoElement, ParentElement, Render, SharedString, Styled, Subscription, WeakEntity, Window,
};
use project::{search::SearchQuery, Project};
use project::{
dap_session::{DebugSession, DebugSessionId},
search::SearchQuery,
Project,
};
use settings::Settings as _;
use std::{
borrow::Cow,
Expand Down
3 changes: 1 addition & 2 deletions crates/debugger_ui/src/attach_modal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use dap::client::DebugAdapterClientId;
use dap::session::DebugSessionId;
use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::Subscription;
use gpui::{DismissEvent, Entity, EventEmitter, Focusable, Render};
use picker::{Picker, PickerDelegate};
use project::dap_store::DapStore;
use project::{dap_session::DebugSessionId, dap_store::DapStore};
use std::sync::Arc;
use sysinfo::System;
use ui::{prelude::*, Context, Tooltip};
Expand Down
5 changes: 2 additions & 3 deletions crates/debugger_ui/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use crate::{
variable_list::VariableList,
};
use dap::{
client::DebugAdapterClientId, proto_conversions::ProtoConversion, session::DebugSession,
OutputEvent, OutputEventGroup,
client::DebugAdapterClientId, proto_conversions::ProtoConversion, OutputEvent, OutputEventGroup,
};
use editor::{
display_map::{Crease, CreaseId},
Expand All @@ -14,7 +13,7 @@ use fuzzy::StringMatchCandidate;
use gpui::{Context, Entity, Render, Subscription, Task, TextStyle, WeakEntity};
use language::{Buffer, CodeLabel, LanguageServerId, ToOffsetUtf16};
use menu::Confirm;
use project::{dap_store::DapStore, Completion};
use project::{dap_session::DebugSession, dap_store::DapStore, Completion};
use rpc::proto;
use settings::Settings;
use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion crates/debugger_ui/src/debugger_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use dap::{
debugger_settings::DebuggerSettings,
messages::{Events, Message},
requests::{Request, RunInTerminal, StartDebugging},
session::DebugSessionId,
Capabilities, CapabilitiesEvent, ContinuedEvent, ErrorResponse, ExitedEvent, LoadedSourceEvent,
ModuleEvent, OutputEvent, RunInTerminalRequestArguments, RunInTerminalResponse, StoppedEvent,
TerminatedEvent, ThreadEvent, ThreadEventReason,
Expand All @@ -18,6 +17,7 @@ use gpui::{
Focusable, Subscription, Task, WeakEntity,
};
use project::{
dap_session::DebugSessionId,
dap_store::{DapStore, DapStoreEvent},
terminals::TerminalKind,
};
Expand Down
32 changes: 19 additions & 13 deletions crates/debugger_ui/src/debugger_panel_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::stack_frame_list::{StackFrameList, StackFrameListEvent};
use crate::variable_list::VariableList;

use dap::proto_conversions::{self, ProtoConversion};
use dap::session::DebugSession;
use dap::{
client::DebugAdapterClientId, debugger_settings::DebuggerSettings, Capabilities,
ContinuedEvent, LoadedSourceEvent, ModuleEvent, OutputEvent, OutputEventCategory, StoppedEvent,
Expand All @@ -16,6 +15,7 @@ use editor::Editor;
use gpui::{
AnyElement, App, Entity, EventEmitter, FocusHandle, Focusable, Subscription, Task, WeakEntity,
};
use project::dap_session::DebugSession;
use project::dap_store::DapStore;
use rpc::proto::{self, DebuggerThreadStatus, PeerId, SetDebuggerPanelItem, UpdateDebugAdapter};
use settings::Settings;
Expand All @@ -33,6 +33,16 @@ pub enum DebugPanelItemEvent {
}

#[derive(Clone, PartialEq, Eq)]
#[cfg(any(test, feature = "test-support"))]
pub enum ThreadItem {
Console,
LoadedSource,
Modules,
Variables,
}

#[derive(Clone, PartialEq, Eq)]
#[cfg(not(any(test, feature = "test-support")))]
enum ThreadItem {
Console,
LoadedSource,
Expand Down Expand Up @@ -120,8 +130,7 @@ impl DebugPanelItem {
)
});

let module_list =
cx.new(|cx| ModuleList::new(dap_store.clone(), session.clone(), &client_id, cx));
let module_list = cx.new(|cx| ModuleList::new(session.clone(), &client_id, cx));

let loaded_source_list =
cx.new(|cx| LoadedSourceList::new(&this, dap_store.clone(), &client_id, cx));
Expand Down Expand Up @@ -253,11 +262,6 @@ impl DebugPanelItem {
.update(cx, |this, cx| this.set_from_proto(variable_list_state, cx));
}

if let Some(module_list_state) = state.module_list.as_ref() {
self.module_list
.update(cx, |this, cx| this.set_from_proto(module_list_state, cx));
}

cx.notify();
}

Expand Down Expand Up @@ -470,11 +474,7 @@ impl DebugPanelItem {
proto::update_debug_adapter::Variant::AddToVariableList(variables_to_add) => self
.variable_list
.update(cx, |this, _| this.add_variables(variables_to_add.clone())),
proto::update_debug_adapter::Variant::Modules(module_list) => {
self.module_list.update(cx, |this, cx| {
this.set_from_proto(module_list, cx);
})
}
proto::update_debug_adapter::Variant::Modules(_) => {}
proto::update_debug_adapter::Variant::OutputEvent(output_event) => {
self.console.update(cx, |this, cx| {
this.add_message(OutputEvent::from_proto(output_event.clone()), window, cx);
Expand All @@ -496,6 +496,12 @@ impl DebugPanelItem {
self.thread_id
}

#[cfg(any(test, feature = "test-support"))]
pub fn set_thread_item(&mut self, thread_item: ThreadItem, cx: &mut Context<Self>) {
self.active_thread_item = thread_item;
cx.notify()
}

#[cfg(any(test, feature = "test-support"))]
pub fn stack_frame_list(&self) -> &Entity<StackFrameList> {
&self.stack_frame_list
Expand Down
Loading

0 comments on commit af77b2f

Please sign in to comment.