on master help sign in
Implement Debug for data structure as a feature
1a3a924notoria
helix-core/Cargo.toml+2−1
@@ -10,6 +10,7 @@ license = "MPL-2.0"
10
10
11[features]
11[features]
12embed_runtime = ["rust-embed"]
12embed_runtime = ["rust-embed"]
13+debug = []
13
14
14[dependencies]
15[dependencies]
15helix-syntax = { path = "../helix-syntax" }
16helix-syntax = { path = "../helix-syntax" }
@@ -17,7 +18,7 @@ helix-syntax = { path = "../helix-syntax" }
17ropey = "1.2"
18ropey = "1.2"
18smallvec = "1.4"
19smallvec = "1.4"
19tendril = "0.4.2"
20tendril = "0.4.2"
20−unicode-segmentation = "1.6"
21+unicode-segmentation = { git = "https://github.com/unicode-rs/unicode-segmentation.git" }
21unicode-width = "0.1"
22unicode-width = "0.1"
22unicode-general-category = "0.4.0"
23unicode-general-category = "0.4.0"
23# slab = "0.4.2"
24# slab = "0.4.2"
helix-core/src/diagnostic.rs+4
@@ -1,3 +1,4 @@
1+#[cfg_attr(feature = "debug", derive(Debug))]
1#[derive(Eq, PartialEq)]
2#[derive(Eq, PartialEq)]
2pub enum Severity {
3pub enum Severity {
3 Error,
4 Error,
@@ -6,10 +7,13 @@ pub enum Severity {
6 Hint,
7 Hint,
7}
8}
8
9
10+#[cfg_attr(feature = "debug", derive(Debug))]
9pub struct Range {
11pub struct Range {
10 pub start: usize,
12 pub start: usize,
11 pub end: usize,
13 pub end: usize,
12}
14}
15+
16+#[cfg_attr(feature = "debug", derive(Debug))]
13pub struct Diagnostic {
17pub struct Diagnostic {
14 pub range: Range,
18 pub range: Range,
15 pub line: usize,
19 pub line: usize,
helix-core/src/graphemes.rs+1
@@ -147,6 +147,7 @@ pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool {
147}
147}
148
148
149/// An iterator over the graphemes of a `RopeSlice`.
149/// An iterator over the graphemes of a `RopeSlice`.
150+#[cfg_attr(feature = "debug", derive(Debug))]
150#[derive(Clone)]
151#[derive(Clone)]
151pub struct RopeGraphemes<'a> {
152pub struct RopeGraphemes<'a> {
152 text: RopeSlice<'a>,
153 text: RopeSlice<'a>,
helix-core/src/history.rs+1
@@ -2,6 +2,7 @@ use crate::{ChangeSet, Rope, State, Transaction};
2use smallvec::{smallvec, SmallVec};
2use smallvec::{smallvec, SmallVec};
3
3
4/// Undo-tree style history store.
4/// Undo-tree style history store.
5+#[cfg_attr(feature = "debug", derive(Debug))]
5pub struct History {
6pub struct History {
6 revisions: Vec<Revision>,
7 revisions: Vec<Revision>,
7 cursor: usize,
8 cursor: usize,
helix-core/src/movement.rs+1
@@ -1,6 +1,7 @@
1use crate::graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary, RopeGraphemes};
1use crate::graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary, RopeGraphemes};
2use crate::{coords_at_pos, pos_at_coords, ChangeSet, Position, Range, Rope, RopeSlice, Selection};
2use crate::{coords_at_pos, pos_at_coords, ChangeSet, Position, Range, Rope, RopeSlice, Selection};
3
3
4+#[cfg_attr(feature = "debug", derive(Debug))]
4#[derive(Copy, Clone, PartialEq, Eq)]
5#[derive(Copy, Clone, PartialEq, Eq)]
5pub enum Direction {
6pub enum Direction {
6 Forward,
7 Forward,
helix-core/src/state.rs+1
@@ -1,6 +1,7 @@
1use crate::{Rope, Selection};
1use crate::{Rope, Selection};
2
2
3/// A state represents the current editor state of a single buffer.
3/// A state represents the current editor state of a single buffer.
4+#[cfg_attr(feature = "debug", derive(Debug))]
4#[derive(Clone)]
5#[derive(Clone)]
5pub struct State {
6pub struct State {
6 pub doc: Rope,
7 pub doc: Rope,
helix-core/src/syntax.rs+26
@@ -1,6 +1,8 @@
1use crate::{regex::Regex, Change, Rope, RopeSlice, Transaction};
1use crate::{regex::Regex, Change, Rope, RopeSlice, Transaction};
2pub use helix_syntax::{get_language, get_language_name, Lang};
2pub use helix_syntax::{get_language, get_language_name, Lang};
3
3
4+#[cfg(feature = "debug")]
5+use std::fmt;
4use std::{
6use std::{
5 borrow::Cow,
7 borrow::Cow,
6 cell::RefCell,
8 cell::RefCell,
@@ -12,12 +14,14 @@ use std::{
12use once_cell::sync::{Lazy, OnceCell};
14use once_cell::sync::{Lazy, OnceCell};
13use serde::{Deserialize, Serialize};
15use serde::{Deserialize, Serialize};
14
16
17+#[cfg_attr(feature = "debug", derive(Debug))]
15#[derive(Serialize, Deserialize)]
18#[derive(Serialize, Deserialize)]
16pub struct Configuration {
19pub struct Configuration {
17 pub language: Vec<LanguageConfiguration>,
20 pub language: Vec<LanguageConfiguration>,
18}
21}
19
22
20// largely based on tree-sitter/cli/src/loader.rs
23// largely based on tree-sitter/cli/src/loader.rs
24+#[cfg_attr(feature = "debug", derive(Debug))]
21#[derive(Serialize, Deserialize)]
25#[derive(Serialize, Deserialize)]
22#[serde(rename_all = "kebab-case")]
26#[serde(rename_all = "kebab-case")]
23pub struct LanguageConfiguration {
27pub struct LanguageConfiguration {
@@ -46,6 +50,7 @@ pub struct LanguageConfiguration {
46 pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
50 pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
47}
51}
48
52
53+#[cfg_attr(feature = "debug", derive(Debug))]
49#[derive(Serialize, Deserialize)]
54#[derive(Serialize, Deserialize)]
50#[serde(rename_all = "kebab-case")]
55#[serde(rename_all = "kebab-case")]
51pub struct LanguageServerConfiguration {
56pub struct LanguageServerConfiguration {
@@ -55,6 +60,7 @@ pub struct LanguageServerConfiguration {
55 pub args: Vec<String>,
60 pub args: Vec<String>,
56}
61}
57
62
63+#[cfg_attr(feature = "debug", derive(Debug))]
58#[derive(Serialize, Deserialize)]
64#[derive(Serialize, Deserialize)]
59#[serde(rename_all = "kebab-case")]
65#[serde(rename_all = "kebab-case")]
60pub struct IndentationConfiguration {
66pub struct IndentationConfiguration {
@@ -62,6 +68,7 @@ pub struct IndentationConfiguration {
62 pub unit: String,
68 pub unit: String,
63}
69}
64
70
71+#[cfg_attr(feature = "debug", derive(Debug))]
65#[derive(Serialize, Deserialize)]
72#[derive(Serialize, Deserialize)]
66#[serde(rename_all = "kebab-case")]
73#[serde(rename_all = "kebab-case")]
67pub struct IndentQuery {
74pub struct IndentQuery {
@@ -189,6 +196,7 @@ impl LanguageConfiguration {
189
196
190pub static LOADER: OnceCell<Loader> = OnceCell::new();
197pub static LOADER: OnceCell<Loader> = OnceCell::new();
191
198
199+#[cfg_attr(feature = "debug", derive(Debug))]
192pub struct Loader {
200pub struct Loader {
193 // highlight_names ?
201 // highlight_names ?
194 language_configs: Vec<Arc<LanguageConfiguration>>,
202 language_configs: Vec<Arc<LanguageConfiguration>>,
@@ -256,6 +264,13 @@ pub struct TsParser {
256 cursors: Vec<QueryCursor>,
264 cursors: Vec<QueryCursor>,
257}
265}
258
266
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+
259// could also just use a pool, or a single instance?
274// could also just use a pool, or a single instance?
260thread_local! {
275thread_local! {
261 pub static PARSER: RefCell<TsParser> = RefCell::new(TsParser {
276 pub static PARSER: RefCell<TsParser> = RefCell::new(TsParser {
@@ -264,6 +279,7 @@ thread_local! {
264 })
279 })
265}
280}
266
281
282+#[cfg_attr(feature = "debug", derive(Debug))]
267pub struct Syntax {
283pub struct Syntax {
268 config: Arc<HighlightConfiguration>,
284 config: Arc<HighlightConfiguration>,
269
285
@@ -444,6 +460,7 @@ impl Syntax {
444 // buffer_range_for_scope_at_pos
460 // buffer_range_for_scope_at_pos
445}
461}
446
462
463+#[cfg_attr(feature = "debug", derive(Debug))]
447pub struct LanguageLayer {
464pub struct LanguageLayer {
448 // mode
465 // mode
449 // grammar
466 // grammar
@@ -752,6 +769,7 @@ pub enum HighlightEvent {
752/// Contains the data neeeded to higlight code written in a particular language.
769/// Contains the data neeeded to higlight code written in a particular language.
753///
770///
754/// This struct is immutable and can be shared between threads.
771/// This struct is immutable and can be shared between threads.
772+#[cfg_attr(feature = "debug", derive(Debug))]
755pub struct HighlightConfiguration {
773pub struct HighlightConfiguration {
756 pub language: Grammar,
774 pub language: Grammar,
757 pub query: Query,
775 pub query: Query,
@@ -782,6 +800,7 @@ struct LocalScope<'a> {
782 local_defs: Vec<LocalDef<'a>>,
800 local_defs: Vec<LocalDef<'a>>,
783}
801}
784
802
803+#[cfg_attr(feature = "debug", derive(Debug))]
785struct HighlightIter<'a, 'tree: 'a, F>
804struct HighlightIter<'a, 'tree: 'a, F>
786where
805where
787 F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
806 F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
@@ -807,6 +826,13 @@ struct HighlightIterLayer<'a, 'tree: 'a> {
807 depth: usize,
826 depth: usize,
808}
827}
809
828
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+
810impl HighlightConfiguration {
836impl HighlightConfiguration {
811 /// Creates a `HighlightConfiguration` for a given `Grammar` and set of highlighting
837 /// Creates a `HighlightConfiguration` for a given `Grammar` and set of highlighting
812 /// queries.
838 /// queries.
helix-core/src/transaction.rs+1
@@ -15,6 +15,7 @@ pub enum Operation {
15 Insert(Tendril),
15 Insert(Tendril),
16}
16}
17
17
18+#[cfg_attr(feature = "debug", derive(Debug))]
18#[derive(Copy, Clone, PartialEq, Eq)]
19#[derive(Copy, Clone, PartialEq, Eq)]
19pub enum Assoc {
20pub enum Assoc {
20 Before,
21 Before,
helix-lsp/Cargo.toml+3
@@ -7,6 +7,9 @@ license = "MPL-2.0"
7
7
8# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9
9
10+[features]
11+debug = ["helix-core/debug"]
12+
10[dependencies]
13[dependencies]
11helix-core = { path = "../helix-core" }
14helix-core = { path = "../helix-core" }
12
15
helix-lsp/src/client.rs+1
@@ -16,6 +16,7 @@ use tokio::{
16 sync::mpsc::{channel, UnboundedReceiver, UnboundedSender},
16 sync::mpsc::{channel, UnboundedReceiver, UnboundedSender},
17};
17};
18
18
19+#[cfg_attr(feature = "debug", derive(Debug))]
19pub struct Client {
20pub struct Client {
20 _process: Child,
21 _process: Child,
21 server_tx: UnboundedSender<Payload>,
22 server_tx: UnboundedSender<Payload>,
helix-lsp/src/lib.rs+1
@@ -172,6 +172,7 @@ impl Notification {
172 }
172 }
173}
173}
174
174
175+#[cfg_attr(feature = "debug", derive(Debug))]
175pub struct Registry {
176pub struct Registry {
176 inner: HashMap<LanguageId, Arc<Client>>,
177 inner: HashMap<LanguageId, Arc<Client>>,
177
178
helix-lsp/src/transport.rs+1
@@ -31,6 +31,7 @@ enum ServerMessage {
31 Call(jsonrpc::Call),
31 Call(jsonrpc::Call),
32}
32}
33
33
34+#[cfg_attr(feature = "debug", derive(Debug))]
34pub struct Transport {
35pub struct Transport {
35 client_tx: UnboundedSender<jsonrpc::Call>,
36 client_tx: UnboundedSender<jsonrpc::Call>,
36 client_rx: UnboundedReceiver<Payload>,
37 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"
10
10
11[features]
11[features]
12embed_runtime = ["helix-core/embed_runtime"]
12embed_runtime = ["helix-core/embed_runtime"]
13+debug = ["helix-core/debug", "helix-view/debug"]
13
14
14[[bin]]
15[[bin]]
15name = "hx"
16name = "hx"
helix-tui/Cargo.toml+1
@@ -10,6 +10,7 @@ license = "MPL-2.0"
10
10
11[features]
11[features]
12default = ["crossterm"]
12default = ["crossterm"]
13+debug = []
13
14
14[dependencies]
15[dependencies]
15bitflags = "1.0"
16bitflags = "1.0"
helix-view/Cargo.toml+1
@@ -10,6 +10,7 @@ license = "MPL-2.0"
10[features]
10[features]
11term = ["tui", "crossterm"]
11term = ["tui", "crossterm"]
12default = ["term"]
12default = ["term"]
13+debug = ["helix-core/debug", "helix-lsp/debug"]
13
14
14[dependencies]
15[dependencies]
15anyhow = "1"
16anyhow = "1"
helix-view/src/document.rs+26
@@ -13,6 +13,7 @@ use crate::{DocumentId, ViewId};
13
13
14use std::collections::HashMap;
14use std::collections::HashMap;
15
15
16+#[cfg_attr(feature = "debug", derive(Debug))]
16#[derive(Copy, Clone, PartialEq, Eq, Hash)]
17#[derive(Copy, Clone, PartialEq, Eq, Hash)]
17pub enum Mode {
18pub enum Mode {
18 Normal,
19 Normal,
@@ -52,6 +53,31 @@ pub struct Document {
52 language_server: Option<Arc<helix_lsp::Client>>,
53 language_server: Option<Arc<helix_lsp::Client>>,
53}
54}
54
55
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+
55/// Like std::mem::replace() except it allows the replacement value to be mapped from the
81/// Like std::mem::replace() except it allows the replacement value to be mapped from the
56/// original value.
82/// original value.
57fn take_with<T, F>(mut_ref: &mut T, closure: F)
83fn take_with<T, F>(mut_ref: &mut T, closure: F)
helix-view/src/editor.rs+2
@@ -9,6 +9,7 @@ use anyhow::Error;
9
9
10pub use helix_core::diagnostic::Severity;
10pub use helix_core::diagnostic::Severity;
11
11
12+#[cfg_attr(feature = "debug", derive(Debug))]
12pub struct Editor {
13pub struct Editor {
13 pub tree: Tree,
14 pub tree: Tree,
14 pub documents: SlotMap<DocumentId, Document>,
15 pub documents: SlotMap<DocumentId, Document>,
@@ -20,6 +21,7 @@ pub struct Editor {
20 pub status_msg: Option<(String, Severity)>,
21 pub status_msg: Option<(String, Severity)>,
21}
22}
22
23
24+#[cfg_attr(feature = "debug", derive(Debug))]
23#[derive(Copy, Clone)]
25#[derive(Copy, Clone)]
24pub enum Action {
26pub enum Action {
25 Replace,
27 Replace,
helix-view/src/tree.rs+6
@@ -4,6 +4,7 @@ use tui::layout::Rect;
4
4
5// the dimensions are recomputed on windo resize/tree change.
5// the dimensions are recomputed on windo resize/tree change.
6//
6//
7+#[cfg_attr(feature = "debug", derive(Debug))]
7pub struct Tree {
8pub struct Tree {
8 root: ViewId,
9 root: ViewId,
9 // (container, index inside the container)
10 // (container, index inside the container)
@@ -17,11 +18,13 @@ pub struct Tree {
17 stack: Vec<(ViewId, Rect)>,
18 stack: Vec<(ViewId, Rect)>,
18}
19}
19
20
21+#[cfg_attr(feature = "debug", derive(Debug))]
20pub struct Node {
22pub struct Node {
21 parent: ViewId,
23 parent: ViewId,
22 content: Content,
24 content: Content,
23}
25}
24
26
27+#[cfg_attr(feature = "debug", derive(Debug))]
25pub enum Content {
28pub enum Content {
26 View(Box<View>),
29 View(Box<View>),
27 Container(Box<Container>),
30 Container(Box<Container>),
@@ -45,6 +48,7 @@ impl Node {
45
48
46// TODO: screen coord to container + container coordinate helpers
49// TODO: screen coord to container + container coordinate helpers
47
50
51+#[cfg_attr(feature = "debug", derive(Debug))]
48#[derive(PartialEq, Eq)]
52#[derive(PartialEq, Eq)]
49pub enum Layout {
53pub enum Layout {
50 Horizontal,
54 Horizontal,
@@ -52,6 +56,7 @@ pub enum Layout {
52 // could explore stacked/tabbed
56 // could explore stacked/tabbed
53}
57}
54
58
59+#[cfg_attr(feature = "debug", derive(Debug))]
55pub struct Container {
60pub struct Container {
56 layout: Layout,
61 layout: Layout,
57 children: Vec<ViewId>,
62 children: Vec<ViewId>,
@@ -432,6 +437,7 @@ impl Tree {
432 }
437 }
433}
438}
434
439
440+#[cfg_attr(feature = "debug", derive(Debug))]
435pub struct Traverse<'a> {
441pub struct Traverse<'a> {
436 tree: &'a Tree,
442 tree: &'a Tree,
437 stack: Vec<ViewId>, // TODO: reuse the one we use on update
443 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;
12
12
13type Jump = (DocumentId, Selection);
13type Jump = (DocumentId, Selection);
14
14
15+#[cfg_attr(feature = "debug", derive(Debug))]
15pub struct JumpList {
16pub struct JumpList {
16 jumps: Vec<Jump>,
17 jumps: Vec<Jump>,
17 current: usize,
18 current: usize,
@@ -58,6 +59,7 @@ impl JumpList {
58 }
59 }
59}
60}
60
61
62+#[cfg_attr(feature = "debug", derive(Debug))]
61pub struct View {
63pub struct View {
62 pub id: ViewId,
64 pub id: ViewId,
63 pub doc: DocumentId,
65 pub doc: DocumentId,