From 7cc13fefe9bd09ea778a0eb8c26bf133e6ad2476 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Mon, 7 Jun 2021 22:34:19 +0800 Subject: [PATCH] Derive debug without feature Note that this also removed those `finish_non_exhaustive()`. --- helix-core/Cargo.toml | 1 - helix-core/src/diagnostic.rs | 7 +++---- helix-core/src/graphemes.rs | 3 +-- helix-core/src/history.rs | 2 +- helix-core/src/movement.rs | 3 +-- helix-core/src/state.rs | 3 +-- helix-core/src/syntax.rs | 34 +++++++++++++--------------------- helix-core/src/transaction.rs | 3 +-- helix-lsp/Cargo.toml | 3 --- helix-lsp/src/client.rs | 2 +- helix-lsp/src/lib.rs | 2 +- helix-lsp/src/transport.rs | 2 +- helix-term/Cargo.toml | 1 - helix-tui/Cargo.toml | 1 - helix-view/Cargo.toml | 1 - helix-view/src/document.rs | 7 ++----- helix-view/src/editor.rs | 5 ++--- helix-view/src/tree.rs | 13 ++++++------- helix-view/src/view.rs | 4 ++-- 19 files changed, 36 insertions(+), 61 deletions(-) diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 08d107263..e205af083 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -10,7 +10,6 @@ license = "MPL-2.0" [features] embed_runtime = ["rust-embed"] -debug = [] [dependencies] helix-syntax = { path = "../helix-syntax" } diff --git a/helix-core/src/diagnostic.rs b/helix-core/src/diagnostic.rs index 0ab7b6458..e08a71e7b 100644 --- a/helix-core/src/diagnostic.rs +++ b/helix-core/src/diagnostic.rs @@ -1,5 +1,4 @@ -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub enum Severity { Error, Warning, @@ -7,13 +6,13 @@ pub enum Severity { Hint, } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Range { pub start: usize, pub end: usize, } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Diagnostic { pub range: Range, pub line: usize, diff --git a/helix-core/src/graphemes.rs b/helix-core/src/graphemes.rs index c68b0ee5d..9844a3431 100644 --- a/helix-core/src/graphemes.rs +++ b/helix-core/src/graphemes.rs @@ -147,8 +147,7 @@ pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool { } /// An iterator over the graphemes of a `RopeSlice`. -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct RopeGraphemes<'a> { text: RopeSlice<'a>, chunks: Chunks<'a>, diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 6eb72cea2..aa3bf1933 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -2,7 +2,7 @@ use crate::{ChangeSet, Rope, State, Transaction}; use smallvec::{smallvec, SmallVec}; /// Undo-tree style history store. -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct History { revisions: Vec, cursor: usize, diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index 8a30e4c60..32dfcae34 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -1,8 +1,7 @@ use crate::graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary, RopeGraphemes}; use crate::{coords_at_pos, pos_at_coords, ChangeSet, Position, Range, Rope, RopeSlice, Selection}; -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Direction { Forward, Backward, diff --git a/helix-core/src/state.rs b/helix-core/src/state.rs index c8a0cf8b1..7e4a7f701 100644 --- a/helix-core/src/state.rs +++ b/helix-core/src/state.rs @@ -1,8 +1,7 @@ use crate::{Rope, Selection}; /// A state represents the current editor state of a single buffer. -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct State { pub doc: Rope, pub selection: Selection, diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index ca20ff1a6..ec21719b9 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -1,12 +1,11 @@ use crate::{regex::Regex, Change, Rope, RopeSlice, Transaction}; pub use helix_syntax::{get_language, get_language_name, Lang}; -#[cfg(feature = "debug")] -use std::fmt; use std::{ borrow::Cow, cell::RefCell, collections::{HashMap, HashSet}, + fmt, path::{Path, PathBuf}, sync::Arc, }; @@ -14,15 +13,13 @@ use std::{ use once_cell::sync::{Lazy, OnceCell}; use serde::{Deserialize, Serialize}; -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct Configuration { pub language: Vec, } // largely based on tree-sitter/cli/src/loader.rs -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct LanguageConfiguration { #[serde(rename = "name")] @@ -50,8 +47,7 @@ pub struct LanguageConfiguration { pub(crate) indent_query: OnceCell>, } -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct LanguageServerConfiguration { pub command: String, @@ -60,16 +56,14 @@ pub struct LanguageServerConfiguration { pub args: Vec, } -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct IndentationConfiguration { pub tab_width: usize, pub unit: String, } -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct IndentQuery { #[serde(default)] @@ -196,7 +190,7 @@ impl LanguageConfiguration { pub static LOADER: OnceCell = OnceCell::new(); -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Loader { // highlight_names ? language_configs: Vec>, @@ -264,10 +258,9 @@ pub struct TsParser { cursors: Vec, } -#[cfg(feature = "debug")] impl fmt::Debug for TsParser { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("TsParser").finish_non_exhaustive() + f.debug_struct("TsParser").finish() } } @@ -279,7 +272,7 @@ thread_local! { }) } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Syntax { config: Arc, @@ -460,7 +453,7 @@ impl Syntax { // buffer_range_for_scope_at_pos } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct LanguageLayer { // mode // grammar @@ -769,7 +762,7 @@ pub enum HighlightEvent { /// Contains the data neeeded to higlight code written in a particular language. /// /// This struct is immutable and can be shared between threads. -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct HighlightConfiguration { pub language: Grammar, pub query: Query, @@ -800,7 +793,7 @@ struct LocalScope<'a> { local_defs: Vec>, } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] struct HighlightIter<'a, 'tree: 'a, F> where F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a, @@ -826,10 +819,9 @@ struct HighlightIterLayer<'a, 'tree: 'a> { depth: usize, } -#[cfg(feature = "debug")] impl<'a, 'tree: 'a> fmt::Debug for HighlightIterLayer<'a, 'tree> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("HighlightIterLayer").finish_non_exhaustive() + f.debug_struct("HighlightIterLayer").finish() } } diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index 24abe0abc..49ac396dd 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -15,8 +15,7 @@ pub enum Operation { Insert(Tendril), } -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Assoc { Before, After, diff --git a/helix-lsp/Cargo.toml b/helix-lsp/Cargo.toml index 7fd05492b..1384ce677 100644 --- a/helix-lsp/Cargo.toml +++ b/helix-lsp/Cargo.toml @@ -7,9 +7,6 @@ license = "MPL-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[features] -debug = ["helix-core/debug"] - [dependencies] helix-core = { path = "../helix-core" } diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 739ff9c2d..c2ea11b86 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -16,7 +16,7 @@ use tokio::{ sync::mpsc::{channel, UnboundedReceiver, UnboundedSender}, }; -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Client { _process: Child, server_tx: UnboundedSender, diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 197ca27d1..6d40cf0ab 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -172,7 +172,7 @@ impl Notification { } } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Registry { inner: HashMap>, diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 876de9290..e80683236 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -31,7 +31,7 @@ enum ServerMessage { Call(jsonrpc::Call), } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Transport { client_tx: UnboundedSender, client_rx: UnboundedReceiver, diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index d42db1888..75edd7231 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -10,7 +10,6 @@ license = "MPL-2.0" [features] embed_runtime = ["helix-core/embed_runtime"] -debug = ["helix-core/debug", "helix-view/debug"] [[bin]] name = "hx" diff --git a/helix-tui/Cargo.toml b/helix-tui/Cargo.toml index 4ead21078..d819fea15 100644 --- a/helix-tui/Cargo.toml +++ b/helix-tui/Cargo.toml @@ -10,7 +10,6 @@ license = "MPL-2.0" [features] default = ["crossterm"] -debug = [] [dependencies] bitflags = "1.0" diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 2efa53f09..9bac60e49 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -10,7 +10,6 @@ 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 dd40421f7..6a687955f 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -13,8 +13,7 @@ use crate::{DocumentId, ViewId}; use std::collections::HashMap; -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Mode { Normal, Select, @@ -53,9 +52,7 @@ pub struct Document { language_server: Option>, } -#[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") @@ -74,7 +71,7 @@ impl fmt::Debug for Document { .field("version", &self.version) .field("diagnostics", &self.diagnostics) // .field("language_server", &self.language_server) - .finish_non_exhaustive() + .finish() } } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index deb7795cc..df71e2d61 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -9,7 +9,7 @@ use anyhow::Error; pub use helix_core::diagnostic::Severity; -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Editor { pub tree: Tree, pub documents: SlotMap, @@ -21,8 +21,7 @@ pub struct Editor { pub status_msg: Option<(String, Severity)>, } -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub enum Action { Replace, HorizontalSplit, diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index b5eb5d879..a0c466d90 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -4,7 +4,7 @@ use tui::layout::Rect; // the dimensions are recomputed on windo resize/tree change. // -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Tree { root: ViewId, // (container, index inside the container) @@ -18,13 +18,13 @@ pub struct Tree { stack: Vec<(ViewId, Rect)>, } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Node { parent: ViewId, content: Content, } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub enum Content { View(Box), Container(Box), @@ -48,15 +48,14 @@ impl Node { // TODO: screen coord to container + container coordinate helpers -#[cfg_attr(feature = "debug", derive(Debug))] -#[derive(PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq)] pub enum Layout { Horizontal, Vertical, // could explore stacked/tabbed } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Container { layout: Layout, children: Vec, @@ -437,7 +436,7 @@ impl Tree { } } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct Traverse<'a> { tree: &'a Tree, stack: Vec, // TODO: reuse the one we use on update diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index e222c11c8..5d2d27fdb 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -12,7 +12,7 @@ pub const PADDING: usize = 5; type Jump = (DocumentId, Selection); -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct JumpList { jumps: Vec, current: usize, @@ -59,7 +59,7 @@ impl JumpList { } } -#[cfg_attr(feature = "debug", derive(Debug))] +#[derive(Debug)] pub struct View { pub id: ViewId, pub doc: DocumentId,