1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

refactor: drop --debug flag

This commit is contained in:
Kevin Amado 2022-02-21 12:33:56 -05:00
parent aa3d4ccfd8
commit 9d23d257c6
8 changed files with 9 additions and 83 deletions

35
Cargo.lock generated
View file

@ -12,7 +12,7 @@ dependencies = [
"rand",
"rayon",
"rnix",
"rowan 0.15.3",
"rowan",
"termion",
"tui",
"walkdir",
@ -64,9 +64,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.1.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5f1fea81f183005ced9e59cdb01737ef2423956dac5a6d731b06b2ecfaa3467"
checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7"
dependencies = [
"atty",
"bitflags",
@ -84,12 +84,6 @@ version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "328b822bdcba4d4e402be8d9adb6eebf269f969f8eadef977a553ff3c4fbcb58"
[[package]]
name = "countme"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03746e0c6dd9b5d2d9132ffe0bede35fb5f815604fd371bb42599fd37bc8e483"
[[package]]
name = "crossbeam-channel"
version = "0.5.2"
@ -163,12 +157,6 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "hashbrown"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -344,7 +332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065c5eac8e8f7e7b0e7227bdc46e2d8dd7d69fff7a9a2734e21f686bbcb9b2c9"
dependencies = [
"cbitset",
"rowan 0.12.6",
"rowan",
"smol_str",
]
@ -354,26 +342,13 @@ version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1b36e449f3702f3b0c821411db1cbdf30fb451726a9456dce5dabcd44420043"
dependencies = [
"countme 2.0.4",
"countme",
"hashbrown 0.9.1",
"memoffset",
"rustc-hash",
"text-size",
]
[[package]]
name = "rowan"
version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c72a0c863fef62cfd9ca7b72a35b422d7672dbffac4ac8003dcc3be7837d871d"
dependencies = [
"countme 3.0.0",
"hashbrown 0.12.0",
"memoffset",
"rustc-hash",
"text-size",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"

View file

@ -7,7 +7,7 @@ rayon = "*"
rnix = "*"
termion = "*"
tui = { version = "*", default-features = false, features = ["termion"] }
rowan = "*"
rowan = "0.12.6" # follows rnix
walkdir = "*"
[package]

View file

@ -2,13 +2,6 @@ pub fn parse(args: Vec<String>) -> clap::ArgMatches {
clap::Command::new("Alejandra")
.about("The Uncompromising Nix Code Formatter.")
.version(crate::version::VERSION)
.arg(
clap::Arg::new("debug")
.help("Enable debug mode.")
.long("debug")
.short('d')
.takes_value(false),
)
.arg(
clap::Arg::new("paths")
.help("Files or directories, or none to format stdin.")

View file

@ -6,28 +6,19 @@ pub enum Layout {
#[derive(Clone)]
pub struct Config {
debug: bool,
layout: Layout,
}
impl Config {
pub fn new() -> Config {
Config { debug: false, layout: Layout::Tall }
}
pub fn debug(&self) -> bool {
self.debug
Config { layout: Layout::Tall }
}
pub fn layout(&self) -> &Layout {
&self.layout
}
pub fn with_debug(&self, debug: bool) -> Config {
Config { debug, layout: self.layout.clone() }
}
pub fn with_layout(&self, layout: Layout) -> Config {
Config { debug: self.debug, layout }
Config { layout }
}
}

View file

@ -1,27 +0,0 @@
pub fn display(
element: &rowan::NodeOrToken<&rowan::GreenNodeData, &rowan::GreenTokenData>,
) {
eprintln!("AST:");
display_recursive(element, 2);
}
fn display_recursive(
element: &rowan::NodeOrToken<&rowan::GreenNodeData, &rowan::GreenTokenData>,
depth: usize,
) {
let kind = unsafe {
std::mem::transmute::<u16, rnix::SyntaxKind>(element.kind().0)
};
match element {
rowan::NodeOrToken::Node(node) => {
eprintln!("{0:<1$}{2:?}", "", 2 * depth, kind);
for child in node.children() {
display_recursive(&child, depth + 1);
}
}
rowan::NodeOrToken::Token(token) => {
eprintln!("{0:<1$}{2:?} {3:?}", "", 2 * depth, kind, token.text());
}
}
}

View file

@ -14,10 +14,6 @@ pub fn string(
let green_node =
crate::builder::build(config, ast.node().into(), false, path).unwrap();
if config.debug() {
crate::debug::display(&(&green_node).into());
}
green_node.to_string()
}

View file

@ -2,7 +2,6 @@ pub mod builder;
pub mod children;
pub mod cli;
pub mod config;
pub mod debug;
pub mod find;
pub mod format;
pub mod position;

View file

@ -1,8 +1,7 @@
fn main() -> std::io::Result<()> {
let matches = alejandra::cli::parse(std::env::args().collect());
let debug: bool = matches.is_present("debug");
let config = alejandra::config::Config::new().with_debug(debug);
let config = alejandra::config::Config::new();
match matches.values_of("paths") {
Some(paths) => {