diff options
author | notoria | 2021-06-06 15:55:05 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-10 13:00:08 +0000 |
commit | 1a3a92463405fdd4738fbdbfda212aef58a2919d (patch) | |
tree | bc47fdc4957a6890cbad286c52a445ba5d96da9a /helix-view | |
parent | aebdef8257173b31df77ae02bb23ec2abfd07e5c (diff) |
Implement Debug for data structure as a feature
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/Cargo.toml | 1 | ||||
-rw-r--r-- | helix-view/src/document.rs | 26 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 2 | ||||
-rw-r--r-- | helix-view/src/tree.rs | 6 | ||||
-rw-r--r-- | helix-view/src/view.rs | 2 |
5 files changed, 37 insertions, 0 deletions
diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 9bac60e4..2efa53f0 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -10,6 +10,7 @@ license = "MPL-2.0" [features] term = ["tui", "crossterm"] default = ["term"] +debug = ["helix-core/debug", "helix-lsp/debug"] [dependencies] anyhow = "1" diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 87eb34ba..dd40421f 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -13,6 +13,7 @@ use crate::{DocumentId, ViewId}; use std::collections::HashMap; +#[cfg_attr(feature = "debug", derive(Debug))] #[derive(Copy, Clone, PartialEq, Eq, Hash)] pub enum Mode { Normal, @@ -52,6 +53,31 @@ pub struct Document { language_server: Option<Arc<helix_lsp::Client>>, } +#[cfg(feature = "debug")] +use std::fmt; +#[cfg(feature = "debug")] +impl fmt::Debug for Document { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Document") + .field("id", &self.id) + .field("text", &self.text) + .field("selections", &self.selections) + .field("path", &self.path) + .field("mode", &self.mode) + .field("restore_cursor", &self.restore_cursor) + .field("syntax", &self.syntax) + .field("language", &self.language) + .field("changes", &self.changes) + .field("old_state", &self.old_state) + // .field("history", &self.history) + .field("last_saved_revision", &self.last_saved_revision) + .field("version", &self.version) + .field("diagnostics", &self.diagnostics) + // .field("language_server", &self.language_server) + .finish_non_exhaustive() + } +} + /// Like std::mem::replace() except it allows the replacement value to be mapped from the /// original value. fn take_with<T, F>(mut_ref: &mut T, closure: F) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 3e91921b..deb7795c 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -9,6 +9,7 @@ use anyhow::Error; pub use helix_core::diagnostic::Severity; +#[cfg_attr(feature = "debug", derive(Debug))] pub struct Editor { pub tree: Tree, pub documents: SlotMap<DocumentId, Document>, @@ -20,6 +21,7 @@ pub struct Editor { pub status_msg: Option<(String, Severity)>, } +#[cfg_attr(feature = "debug", derive(Debug))] #[derive(Copy, Clone)] pub enum Action { Replace, diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index 5b56156f..b5eb5d87 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -4,6 +4,7 @@ use tui::layout::Rect; // the dimensions are recomputed on windo resize/tree change. // +#[cfg_attr(feature = "debug", derive(Debug))] pub struct Tree { root: ViewId, // (container, index inside the container) @@ -17,11 +18,13 @@ pub struct Tree { stack: Vec<(ViewId, Rect)>, } +#[cfg_attr(feature = "debug", derive(Debug))] pub struct Node { parent: ViewId, content: Content, } +#[cfg_attr(feature = "debug", derive(Debug))] pub enum Content { View(Box<View>), Container(Box<Container>), @@ -45,6 +48,7 @@ impl Node { // TODO: screen coord to container + container coordinate helpers +#[cfg_attr(feature = "debug", derive(Debug))] #[derive(PartialEq, Eq)] pub enum Layout { Horizontal, @@ -52,6 +56,7 @@ pub enum Layout { // could explore stacked/tabbed } +#[cfg_attr(feature = "debug", derive(Debug))] pub struct Container { layout: Layout, children: Vec<ViewId>, @@ -432,6 +437,7 @@ impl Tree { } } +#[cfg_attr(feature = "debug", derive(Debug))] pub struct Traverse<'a> { tree: &'a Tree, stack: Vec<ViewId>, // TODO: reuse the one we use on update diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 7bd31305..e222c11c 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -12,6 +12,7 @@ pub const PADDING: usize = 5; type Jump = (DocumentId, Selection); +#[cfg_attr(feature = "debug", derive(Debug))] pub struct JumpList { jumps: Vec<Jump>, current: usize, @@ -58,6 +59,7 @@ impl JumpList { } } +#[cfg_attr(feature = "debug", derive(Debug))] pub struct View { pub id: ViewId, pub doc: DocumentId, |