From 9dfd2f5bdd81c42e97f193e29bd936778025bd22 Mon Sep 17 00:00:00 2001 From: Anthony Eid Date: Thu, 1 Aug 2024 18:29:46 -0400 Subject: [PATCH] Get load workspace to get breakpoint data --- crates/editor/src/items.rs | 1 - crates/workspace/src/persistence.rs | 95 +++++++++++++++++++++++++---- crates/workspace/src/workspace.rs | 2 +- 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index b9785f6872..4d1f2dd2a5 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -7,7 +7,6 @@ use crate::{ }; use anyhow::{anyhow, Context as _, Result}; use collections::HashSet; -use dap::client::Breakpoint; use file_icons::FileIcons; use futures::future::try_join_all; use git::repository::GitFileStatus; diff --git a/crates/workspace/src/persistence.rs b/crates/workspace/src/persistence.rs index d8daa7fc53..55e8ae29bf 100644 --- a/crates/workspace/src/persistence.rs +++ b/crates/workspace/src/persistence.rs @@ -1,15 +1,16 @@ pub mod model; -use std::path::Path; +use std::path::{Path, PathBuf}; use anyhow::{anyhow, bail, Context, Result}; use client::DevServerProjectId; +use collections::HashMap; use db::{define_connection, query, sqlez::connection::Connection, sqlez_macros::sql}; use gpui::{point, size, Axis, Bounds, WindowBounds}; use sqlez::{ bindable::{Bind, Column, StaticColumnCount}, - statement::Statement, + statement::{SqlType, Statement}, }; use ui::px; @@ -140,6 +141,9 @@ pub struct Breakpoint { pub position: u64, } +#[derive(Debug)] +struct Breakpoints(Vec); + impl sqlez::bindable::StaticColumnCount for Breakpoint {} impl sqlez::bindable::Bind for Breakpoint { fn bind( @@ -161,6 +165,28 @@ impl Column for Breakpoint { } } +impl Column for Breakpoints { + fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> { + let mut breakpoints = Vec::new(); + let mut index = start_index; + + loop { + match statement.column_type(index) { + Ok(SqlType::Null) => break, + _ => { + let position = statement + .column_int64(index) + .with_context(|| format!("Failed to read BreakPoint at index {index}"))? + as u64; + breakpoints.push(Breakpoint { position }); + index += 1; + } + } + } + Ok((Breakpoints(breakpoints), index)) + } +} + #[derive(Clone, Debug, PartialEq)] struct SerializedPixels(gpui::Pixels); impl sqlez::bindable::StaticColumnCount for SerializedPixels {} @@ -454,6 +480,49 @@ impl WorkspaceDb { .warn_on_err() .flatten()?; + dbg!("About to query breakpoints"); + + // Figure out why the below query didn't work + // let breakpoints: Result> = self + // .select_bound(sql! { + // SELECT file_path, GROUP_CONCAT(breakpoint_location) as breakpoint_locations + // FROM breakpoints + // WHERE workspace_id = ? + // GROUP BY file_path}) + // .and_then(|mut prepared_statement| (prepared_statement)(workspace_id)); + + let breakpoints: Result> = self + .select_bound(sql! { + SELECT file_path, breakpoint_location + FROM breakpoints + WHERE workspace_id = ? + }) + .and_then(|mut prepared_statement| (prepared_statement)(workspace_id)); + + let breakpoints: Option)>> = match breakpoints { + Ok(bp) => { + if bp.is_empty() { + log::error!("Breakpoints are empty"); + } + + let mut map: HashMap> = HashMap::new(); + + for (file_path, breakpoint) in bp { + map.entry(file_path).or_default().push(breakpoint.position); + } + + Some( + map.into_iter() + .map(|(file_path, breakpoints)| (file_path, breakpoints)) + .collect(), + ) + } + Err(msg) => { + log::error!("{msg}"); + None + } + }; + let location = if let Some(dev_server_project_id) = dev_server_project_id { let dev_server_project: SerializedDevServerProject = self .select_row_bound(sql! { @@ -490,7 +559,7 @@ impl WorkspaceDb { display, docks, session_id: None, - breakpoints: None, + breakpoints, }) } @@ -631,8 +700,6 @@ impl WorkspaceDb { } } } - - // dbg!(persistence::DB.all_breakpoints(database_id)); } match workspace.location { @@ -771,16 +838,18 @@ impl WorkspaceDb { } } - query! { - pub fn all_breakpoints(id: WorkspaceId) -> Result> { - SELECT breakpoint_location - FROM breakpoints - WHERE workspace_id = ? - } - } + // TODO: Fix this query + // query! { + // pub fn all_breakpoints(id: WorkspaceId) -> Result)>> { + // SELECT local_path, GROUP_CONCAT(breakpoint_location) as breakpoint_locations + // FROM breakpoints + // WHERE workspace_id = ? + // GROUP BY local_path; + // } + // } query! { - pub fn breakpoints(id: WorkspaceId, file_path: &Path) -> Result> { + pub fn breakpoints_for_file(id: WorkspaceId, file_path: &Path) -> Result> { SELECT breakpoint_location FROM breakpoints WHERE workspace_id = ?1 AND file_path = ?2 diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 8fb318a9f8..e0e15af72e 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -43,7 +43,7 @@ use item::{ ProjectItem, SerializableItem, SerializableItemHandle, }; use itertools::Itertools; -use language::{LanguageRegistry, Rope}; +use language::{proto::deserialize_selection, LanguageRegistry, Rope}; use lazy_static::lazy_static; pub use modal_layer::*; use node_runtime::NodeRuntime;