mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +00:00
refactor: drop --debug flag
This commit is contained in:
parent
aa3d4ccfd8
commit
9d23d257c6
8 changed files with 9 additions and 83 deletions
35
Cargo.lock
generated
35
Cargo.lock
generated
|
@ -12,7 +12,7 @@ dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
"rayon",
|
"rayon",
|
||||||
"rnix",
|
"rnix",
|
||||||
"rowan 0.15.3",
|
"rowan",
|
||||||
"termion",
|
"termion",
|
||||||
"tui",
|
"tui",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
|
@ -64,9 +64,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "3.1.0"
|
version = "3.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e5f1fea81f183005ced9e59cdb01737ef2423956dac5a6d731b06b2ecfaa3467"
|
checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
"atty",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
@ -84,12 +84,6 @@ version = "2.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "328b822bdcba4d4e402be8d9adb6eebf269f969f8eadef977a553ff3c4fbcb58"
|
checksum = "328b822bdcba4d4e402be8d9adb6eebf269f969f8eadef977a553ff3c4fbcb58"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "countme"
|
|
||||||
version = "3.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "03746e0c6dd9b5d2d9132ffe0bede35fb5f815604fd371bb42599fd37bc8e483"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-channel"
|
name = "crossbeam-channel"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
|
@ -163,12 +157,6 @@ version = "0.11.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashbrown"
|
|
||||||
version = "0.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.19"
|
version = "0.1.19"
|
||||||
|
@ -344,7 +332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "065c5eac8e8f7e7b0e7227bdc46e2d8dd7d69fff7a9a2734e21f686bbcb9b2c9"
|
checksum = "065c5eac8e8f7e7b0e7227bdc46e2d8dd7d69fff7a9a2734e21f686bbcb9b2c9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cbitset",
|
"cbitset",
|
||||||
"rowan 0.12.6",
|
"rowan",
|
||||||
"smol_str",
|
"smol_str",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -354,26 +342,13 @@ version = "0.12.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a1b36e449f3702f3b0c821411db1cbdf30fb451726a9456dce5dabcd44420043"
|
checksum = "a1b36e449f3702f3b0c821411db1cbdf30fb451726a9456dce5dabcd44420043"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"countme 2.0.4",
|
"countme",
|
||||||
"hashbrown 0.9.1",
|
"hashbrown 0.9.1",
|
||||||
"memoffset",
|
"memoffset",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"text-size",
|
"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]]
|
[[package]]
|
||||||
name = "rustc-hash"
|
name = "rustc-hash"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|
|
@ -7,7 +7,7 @@ rayon = "*"
|
||||||
rnix = "*"
|
rnix = "*"
|
||||||
termion = "*"
|
termion = "*"
|
||||||
tui = { version = "*", default-features = false, features = ["termion"] }
|
tui = { version = "*", default-features = false, features = ["termion"] }
|
||||||
rowan = "*"
|
rowan = "0.12.6" # follows rnix
|
||||||
walkdir = "*"
|
walkdir = "*"
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
|
|
|
@ -2,13 +2,6 @@ pub fn parse(args: Vec<String>) -> clap::ArgMatches {
|
||||||
clap::Command::new("Alejandra")
|
clap::Command::new("Alejandra")
|
||||||
.about("The Uncompromising Nix Code Formatter.")
|
.about("The Uncompromising Nix Code Formatter.")
|
||||||
.version(crate::version::VERSION)
|
.version(crate::version::VERSION)
|
||||||
.arg(
|
|
||||||
clap::Arg::new("debug")
|
|
||||||
.help("Enable debug mode.")
|
|
||||||
.long("debug")
|
|
||||||
.short('d')
|
|
||||||
.takes_value(false),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
clap::Arg::new("paths")
|
clap::Arg::new("paths")
|
||||||
.help("Files or directories, or none to format stdin.")
|
.help("Files or directories, or none to format stdin.")
|
||||||
|
|
|
@ -6,28 +6,19 @@ pub enum Layout {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
debug: bool,
|
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn new() -> Config {
|
pub fn new() -> Config {
|
||||||
Config { debug: false, layout: Layout::Tall }
|
Config { layout: Layout::Tall }
|
||||||
}
|
|
||||||
|
|
||||||
pub fn debug(&self) -> bool {
|
|
||||||
self.debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layout(&self) -> &Layout {
|
pub fn layout(&self) -> &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 {
|
pub fn with_layout(&self, layout: Layout) -> Config {
|
||||||
Config { debug: self.debug, layout }
|
Config { layout }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
27
src/debug.rs
27
src/debug.rs
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -14,10 +14,6 @@ pub fn string(
|
||||||
let green_node =
|
let green_node =
|
||||||
crate::builder::build(config, ast.node().into(), false, path).unwrap();
|
crate::builder::build(config, ast.node().into(), false, path).unwrap();
|
||||||
|
|
||||||
if config.debug() {
|
|
||||||
crate::debug::display(&(&green_node).into());
|
|
||||||
}
|
|
||||||
|
|
||||||
green_node.to_string()
|
green_node.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ pub mod builder;
|
||||||
pub mod children;
|
pub mod children;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod debug;
|
|
||||||
pub mod find;
|
pub mod find;
|
||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod position;
|
pub mod position;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let matches = alejandra::cli::parse(std::env::args().collect());
|
let matches = alejandra::cli::parse(std::env::args().collect());
|
||||||
|
|
||||||
let debug: bool = matches.is_present("debug");
|
let config = alejandra::config::Config::new();
|
||||||
let config = alejandra::config::Config::new().with_debug(debug);
|
|
||||||
|
|
||||||
match matches.values_of("paths") {
|
match matches.values_of("paths") {
|
||||||
Some(paths) => {
|
Some(paths) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue