on master help sign in
Implement Debug for data structure as a feature
commit1a3a92463405fdd4738fbdbfda212aef58a2919d authornotoria <notoria@users.noreply.github.com> dateSun 6 Jun 2021, 17:55 (5 years ago) parentaebdef8
20 files changed+83−2
helix-core/Cargo.toml+2−1 helix-core/src/diagnostic.rs+4 helix-core/src/graphemes.rs+1 helix-core/src/history.rs+1 helix-core/src/movement.rs+1 helix-core/src/state.rs+1 helix-core/src/syntax.rs+26 helix-core/src/transaction.rs+1 helix-lsp/Cargo.toml+3 helix-lsp/src/client.rs+1 helix-lsp/src/lib.rs+1 helix-lsp/src/transport.rs+1 helix-syntax/languages/tree-sitter-haskell+1−1 helix-term/Cargo.toml+1 helix-tui/Cargo.toml+1 helix-view/Cargo.toml+1 helix-view/src/document.rs+26 helix-view/src/editor.rs+2 helix-view/src/tree.rs+6 helix-view/src/view.rs+2
helix-core/Cargo.toml+2−1
@@ -10,6 +10,7 @@ license = "MPL-2.0"
1010
1111[features]
1212embed_runtime = ["rust-embed"]
13+debug = []
1314
1415[dependencies]
1516helix-syntax = { path = "../helix-syntax" }
@@ -17,7 +18,7 @@ helix-syntax = { path = "../helix-syntax" }
1718ropey = "1.2"
1819smallvec = "1.4"
1920tendril = "0.4.2"
20−unicode-segmentation = "1.6"
21+unicode-segmentation = { git = "https://github.com/unicode-rs/unicode-segmentation.git" }
2122unicode-width = "0.1"
2223unicode-general-category = "0.4.0"
2324# slab = "0.4.2"
helix-core/src/diagnostic.rs+4
@@ -1,3 +1,4 @@
1+#[cfg_attr(feature = "debug", derive(Debug))]
12#[derive(Eq, PartialEq)]
23pub enum Severity {
34 Error,
@@ -6,10 +7,13 @@ pub enum Severity {
67 Hint,
78}
89
10+#[cfg_attr(feature = "debug", derive(Debug))]
911pub struct Range {
1012 pub start: usize,
1113 pub end: usize,
1214}
15+
16+#[cfg_attr(feature = "debug", derive(Debug))]
1317pub struct Diagnostic {
1418 pub range: Range,
1519 pub line: usize,
helix-core/src/graphemes.rs+1
@@ -147,6 +147,7 @@ pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool {
147147}
148148
149149/// An iterator over the graphemes of a `RopeSlice`.
150+#[cfg_attr(feature = "debug", derive(Debug))]
150151#[derive(Clone)]
151152pub struct RopeGraphemes<'a> {
152153 text: RopeSlice<'a>,
helix-core/src/history.rs+1
@@ -2,6 +2,7 @@ use crate::{ChangeSet, Rope, State, Transaction};
22use smallvec::{smallvec, SmallVec};
33
44/// Undo-tree style history store.
5+#[cfg_attr(feature = "debug", derive(Debug))]
56pub struct History {
67 revisions: Vec<Revision>,
78 cursor: usize,
helix-core/src/movement.rs+1
@@ -1,6 +1,7 @@
11use crate::graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary, RopeGraphemes};
22use crate::{coords_at_pos, pos_at_coords, ChangeSet, Position, Range, Rope, RopeSlice, Selection};
33
4+#[cfg_attr(feature = "debug", derive(Debug))]
45#[derive(Copy, Clone, PartialEq, Eq)]
56pub enum Direction {
67 Forward,
helix-core/src/state.rs+1
@@ -1,6 +1,7 @@
11use crate::{Rope, Selection};
22
33/// A state represents the current editor state of a single buffer.
4+#[cfg_attr(feature = "debug", derive(Debug))]
45#[derive(Clone)]
56pub struct State {
67 pub doc: Rope,
helix-core/src/syntax.rs+26
@@ -1,6 +1,8 @@
11use crate::{regex::Regex, Change, Rope, RopeSlice, Transaction};
22pub use helix_syntax::{get_language, get_language_name, Lang};
33
4+#[cfg(feature = "debug")]
5+use std::fmt;
46use std::{
57 borrow::Cow,
68 cell::RefCell,
@@ -12,12 +14,14 @@ use std::{
1214use once_cell::sync::{Lazy, OnceCell};
1315use serde::{Deserialize, Serialize};
1416
17+#[cfg_attr(feature = "debug", derive(Debug))]
1518#[derive(Serialize, Deserialize)]
1619pub struct Configuration {
1720 pub language: Vec<LanguageConfiguration>,
1821}
1922
2023// largely based on tree-sitter/cli/src/loader.rs
24+#[cfg_attr(feature = "debug", derive(Debug))]
2125#[derive(Serialize, Deserialize)]
2226#[serde(rename_all = "kebab-case")]
2327pub struct LanguageConfiguration {
@@ -46,6 +50,7 @@ pub struct LanguageConfiguration {
4650 pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
4751}
4852
53+#[cfg_attr(feature = "debug", derive(Debug))]
4954#[derive(Serialize, Deserialize)]
5055#[serde(rename_all = "kebab-case")]
5156pub struct LanguageServerConfiguration {
@@ -55,6 +60,7 @@ pub struct LanguageServerConfiguration {
5560 pub args: Vec<String>,
5661}
5762
63+#[cfg_attr(feature = "debug", derive(Debug))]
5864#[derive(Serialize, Deserialize)]
5965#[serde(rename_all = "kebab-case")]
6066pub struct IndentationConfiguration {
@@ -62,6 +68,7 @@ pub struct IndentationConfiguration {
6268 pub unit: String,
6369}
6470
71+#[cfg_attr(feature = "debug", derive(Debug))]
6572#[derive(Serialize, Deserialize)]
6673#[serde(rename_all = "kebab-case")]
6774pub struct IndentQuery {
@@ -189,6 +196,7 @@ impl LanguageConfiguration {
189196
190197pub static LOADER: OnceCell<Loader> = OnceCell::new();
191198
199+#[cfg_attr(feature = "debug", derive(Debug))]
192200pub struct Loader {
193201 // highlight_names ?
194202 language_configs: Vec<Arc<LanguageConfiguration>>,
@@ -256,6 +264,13 @@ pub struct TsParser {
256264 cursors: Vec<QueryCursor>,
257265}
258266
267+#[cfg(feature = "debug")]
268+impl fmt::Debug for TsParser {
269+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
270+ f.debug_struct("TsParser").finish_non_exhaustive()
271+ }
272+}
273+
259274// could also just use a pool, or a single instance?
260275thread_local! {
261276 pub static PARSER: RefCell<TsParser> = RefCell::new(TsParser {
@@ -264,6 +279,7 @@ thread_local! {
264279 })
265280}
266281
282+#[cfg_attr(feature = "debug", derive(Debug))]
267283pub struct Syntax {
268284 config: Arc<HighlightConfiguration>,
269285
@@ -444,6 +460,7 @@ impl Syntax {
444460 // buffer_range_for_scope_at_pos
445461}
446462
463+#[cfg_attr(feature = "debug", derive(Debug))]
447464pub struct LanguageLayer {
448465 // mode
449466 // grammar
@@ -752,6 +769,7 @@ pub enum HighlightEvent {
752769/// Contains the data neeeded to higlight code written in a particular language.
753770///
754771/// This struct is immutable and can be shared between threads.
772+#[cfg_attr(feature = "debug", derive(Debug))]
755773pub struct HighlightConfiguration {
756774 pub language: Grammar,
757775 pub query: Query,
@@ -782,6 +800,7 @@ struct LocalScope<'a> {
782800 local_defs: Vec<LocalDef<'a>>,
783801}
784802
803+#[cfg_attr(feature = "debug", derive(Debug))]
785804struct HighlightIter<'a, 'tree: 'a, F>
786805where
787806 F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
@@ -807,6 +826,13 @@ struct HighlightIterLayer<'a, 'tree: 'a> {
807826 depth: usize,
808827}
809828
829+#[cfg(feature = "debug")]
830+impl<'a, 'tree: 'a> fmt::Debug for HighlightIterLayer<'a, 'tree> {
831+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
832+ f.debug_struct("HighlightIterLayer").finish_non_exhaustive()
833+ }
834+}
835+
810836impl HighlightConfiguration {
811837 /// Creates a `HighlightConfiguration` for a given `Grammar` and set of highlighting
812838 /// queries.
helix-core/src/transaction.rs+1
@@ -15,6 +15,7 @@ pub enum Operation {
1515 Insert(Tendril),
1616}
1717
18+#[cfg_attr(feature = "debug", derive(Debug))]
1819#[derive(Copy, Clone, PartialEq, Eq)]
1920pub enum Assoc {
2021 Before,
helix-lsp/Cargo.toml+3
@@ -7,6 +7,9 @@ license = "MPL-2.0"
77
88# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99
10+[features]
11+debug = ["helix-core/debug"]
12+
1013[dependencies]
1114helix-core = { path = "../helix-core" }
1215
helix-lsp/src/client.rs+1
@@ -16,6 +16,7 @@ use tokio::{
1616 sync::mpsc::{channel, UnboundedReceiver, UnboundedSender},
1717};
1818
19+#[cfg_attr(feature = "debug", derive(Debug))]
1920pub struct Client {
2021 _process: Child,
2122 server_tx: UnboundedSender<Payload>,
helix-lsp/src/lib.rs+1
@@ -172,6 +172,7 @@ impl Notification {
172172 }
173173}
174174
175+#[cfg_attr(feature = "debug", derive(Debug))]
175176pub struct Registry {
176177 inner: HashMap<LanguageId, Arc<Client>>,
177178
helix-lsp/src/transport.rs+1
@@ -31,6 +31,7 @@ enum ServerMessage {
3131 Call(jsonrpc::Call),
3232}
3333
34+#[cfg_attr(feature = "debug", derive(Debug))]
3435pub struct Transport {
3536 client_tx: UnboundedSender<jsonrpc::Call>,
3637 client_rx: UnboundedReceiver<Payload>,
helix-syntax/languages/tree-sitter-haskell+1−1

Submodule changed.

helix-term/Cargo.toml+1
@@ -10,6 +10,7 @@ license = "MPL-2.0"
1010
1111[features]
1212embed_runtime = ["helix-core/embed_runtime"]
13+debug = ["helix-core/debug", "helix-view/debug"]
1314
1415[[bin]]
1516name = "hx"
helix-tui/Cargo.toml+1
@@ -10,6 +10,7 @@ license = "MPL-2.0"
1010
1111[features]
1212default = ["crossterm"]
13+debug = []
1314
1415[dependencies]
1516bitflags = "1.0"
helix-view/Cargo.toml+1
@@ -10,6 +10,7 @@ license = "MPL-2.0"
1010[features]
1111term = ["tui", "crossterm"]
1212default = ["term"]
13+debug = ["helix-core/debug", "helix-lsp/debug"]
1314
1415[dependencies]
1516anyhow = "1"
helix-view/src/document.rs+26
@@ -13,6 +13,7 @@ use crate::{DocumentId, ViewId};
1313
1414use std::collections::HashMap;
1515
16+#[cfg_attr(feature = "debug", derive(Debug))]
1617#[derive(Copy, Clone, PartialEq, Eq, Hash)]
1718pub enum Mode {
1819 Normal,
@@ -52,6 +53,31 @@ pub struct Document {
5253 language_server: Option<Arc<helix_lsp::Client>>,
5354}
5455
56+#[cfg(feature = "debug")]
57+use std::fmt;
58+#[cfg(feature = "debug")]
59+impl fmt::Debug for Document {
60+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61+ f.debug_struct("Document")
62+ .field("id", &self.id)
63+ .field("text", &self.text)
64+ .field("selections", &self.selections)
65+ .field("path", &self.path)
66+ .field("mode", &self.mode)
67+ .field("restore_cursor", &self.restore_cursor)
68+ .field("syntax", &self.syntax)
69+ .field("language", &self.language)
70+ .field("changes", &self.changes)
71+ .field("old_state", &self.old_state)
72+ // .field("history", &self.history)
73+ .field("last_saved_revision", &self.last_saved_revision)
74+ .field("version", &self.version)
75+ .field("diagnostics", &self.diagnostics)
76+ // .field("language_server", &self.language_server)
77+ .finish_non_exhaustive()
78+ }
79+}
80+
5581/// Like std::mem::replace() except it allows the replacement value to be mapped from the
5682/// original value.
5783fn take_with<T, F>(mut_ref: &mut T, closure: F)
helix-view/src/editor.rs+2
@@ -9,6 +9,7 @@ use anyhow::Error;
99
1010pub use helix_core::diagnostic::Severity;
1111
12+#[cfg_attr(feature = "debug", derive(Debug))]
1213pub struct Editor {
1314 pub tree: Tree,
1415 pub documents: SlotMap<DocumentId, Document>,
@@ -20,6 +21,7 @@ pub struct Editor {
2021 pub status_msg: Option<(String, Severity)>,
2122}
2223
24+#[cfg_attr(feature = "debug", derive(Debug))]
2325#[derive(Copy, Clone)]
2426pub enum Action {
2527 Replace,
helix-view/src/tree.rs+6
@@ -4,6 +4,7 @@ use tui::layout::Rect;
44
55// the dimensions are recomputed on windo resize/tree change.
66//
7+#[cfg_attr(feature = "debug", derive(Debug))]
78pub struct Tree {
89 root: ViewId,
910 // (container, index inside the container)
@@ -17,11 +18,13 @@ pub struct Tree {
1718 stack: Vec<(ViewId, Rect)>,
1819}
1920
21+#[cfg_attr(feature = "debug", derive(Debug))]
2022pub struct Node {
2123 parent: ViewId,
2224 content: Content,
2325}
2426
27+#[cfg_attr(feature = "debug", derive(Debug))]
2528pub enum Content {
2629 View(Box<View>),
2730 Container(Box<Container>),
@@ -45,6 +48,7 @@ impl Node {
4548
4649// TODO: screen coord to container + container coordinate helpers
4750
51+#[cfg_attr(feature = "debug", derive(Debug))]
4852#[derive(PartialEq, Eq)]
4953pub enum Layout {
5054 Horizontal,
@@ -52,6 +56,7 @@ pub enum Layout {
5256 // could explore stacked/tabbed
5357}
5458
59+#[cfg_attr(feature = "debug", derive(Debug))]
5560pub struct Container {
5661 layout: Layout,
5762 children: Vec<ViewId>,
@@ -432,6 +437,7 @@ impl Tree {
432437 }
433438}
434439
440+#[cfg_attr(feature = "debug", derive(Debug))]
435441pub struct Traverse<'a> {
436442 tree: &'a Tree,
437443 stack: Vec<ViewId>, // TODO: reuse the one we use on update
helix-view/src/view.rs+2
@@ -12,6 +12,7 @@ pub const PADDING: usize = 5;
1212
1313type Jump = (DocumentId, Selection);
1414
15+#[cfg_attr(feature = "debug", derive(Debug))]
1516pub struct JumpList {
1617 jumps: Vec<Jump>,
1718 current: usize,
@@ -58,6 +59,7 @@ impl JumpList {
5859 }
5960}
6061
62+#[cfg_attr(feature = "debug", derive(Debug))]
6163pub struct View {
6264 pub id: ViewId,
6365 pub doc: DocumentId,