1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-31 04:27:45 +00:00

feat: natural apply

This commit is contained in:
Kevin Amado 2022-02-01 19:24:54 -05:00
parent 863976c10f
commit 14ed5b9fc8
No known key found for this signature in database
GPG key ID: FFF341057F503148
4 changed files with 93 additions and 95 deletions

View file

@ -2,9 +2,7 @@ let
lockData = builtins.readFile ./flake.lock;
lock = builtins.fromJSON lockData;
flakeCompat = lock.nodes.flakeCompat.locked;
flakeCompatSrc =
builtins.fetchTarball
{
flakeCompatSrc = builtins.fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${flakeCompat.rev}.tar.gz";
sha256 = flakeCompat.narHash;
};

View file

@ -15,9 +15,7 @@
};
outputs =
inputs:
inputs.flakeUtils.lib.eachSystem
[ "x86_64-darwin" "x86_64-linux" ]
(
inputs.flakeUtils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] (
system:
let
nixpkgs = import inputs.nixpkgs { inherit system; };
@ -32,14 +30,13 @@
type = "app";
program = "${inputs.self.defaultPackage.${system}}/bin/alejandra";
};
defaultPackage =
fenixPlatform.buildRustPackage
{
defaultPackage = fenixPlatform.buildRustPackage {
pname = cargoToml.package.name;
version =
let
commit = inputs.self.shortRev or "dirty";
date = inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
date =
inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
in
"${builtins.substring 0 8 date}_${commit}";
src = inputs.self.sourceInfo;
@ -51,9 +48,7 @@
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
};
};
devShell =
nixpkgs.mkShell
{
devShell = nixpkgs.mkShell {
name = "Alejandra";
packages = [
fenix.rust-analyzer

View file

@ -12,46 +12,50 @@ pub fn rule(
build_ctx.config.layout()
};
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
match child.element.kind() {
rnix::SyntaxKind::NODE_APPLY => {
steps
.push_back(crate::builder::Step::Format(child.element));
}
_ => {
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
}
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
steps.push_back(crate::builder::Step::Whitespace);
}
}
children.drain_comments(|text| {
steps.push_back(crate::builder::Step::Comment(text));
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
});
// left
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
steps.push_back(crate::builder::Step::Dedent);
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
}
// /**/
children.drain_comments(|text| {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text));
});
let child_prev = children.peek_prev().unwrap();
// right
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if let rnix::SyntaxKind::TOKEN_COMMENT = child_prev.element.kind() {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if let rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_STRING = child.element.kind()
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
};
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
}
}
steps
}

View file

@ -45,7 +45,8 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
if let rnix::SyntaxKind::NODE_ATTR_SET
if let rnix::SyntaxKind::NODE_APPLY
| rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_STRING =