mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
feat: natural apply
This commit is contained in:
parent
863976c10f
commit
14ed5b9fc8
4 changed files with 93 additions and 95 deletions
|
@ -2,9 +2,7 @@ let
|
||||||
lockData = builtins.readFile ./flake.lock;
|
lockData = builtins.readFile ./flake.lock;
|
||||||
lock = builtins.fromJSON lockData;
|
lock = builtins.fromJSON lockData;
|
||||||
flakeCompat = lock.nodes.flakeCompat.locked;
|
flakeCompat = lock.nodes.flakeCompat.locked;
|
||||||
flakeCompatSrc =
|
flakeCompatSrc = builtins.fetchTarball {
|
||||||
builtins.fetchTarball
|
|
||||||
{
|
|
||||||
url = "https://github.com/edolstra/flake-compat/archive/${flakeCompat.rev}.tar.gz";
|
url = "https://github.com/edolstra/flake-compat/archive/${flakeCompat.rev}.tar.gz";
|
||||||
sha256 = flakeCompat.narHash;
|
sha256 = flakeCompat.narHash;
|
||||||
};
|
};
|
||||||
|
|
15
flake.nix
15
flake.nix
|
@ -15,9 +15,7 @@
|
||||||
};
|
};
|
||||||
outputs =
|
outputs =
|
||||||
inputs:
|
inputs:
|
||||||
inputs.flakeUtils.lib.eachSystem
|
inputs.flakeUtils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] (
|
||||||
[ "x86_64-darwin" "x86_64-linux" ]
|
|
||||||
(
|
|
||||||
system:
|
system:
|
||||||
let
|
let
|
||||||
nixpkgs = import inputs.nixpkgs { inherit system; };
|
nixpkgs = import inputs.nixpkgs { inherit system; };
|
||||||
|
@ -32,14 +30,13 @@
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${inputs.self.defaultPackage.${system}}/bin/alejandra";
|
program = "${inputs.self.defaultPackage.${system}}/bin/alejandra";
|
||||||
};
|
};
|
||||||
defaultPackage =
|
defaultPackage = fenixPlatform.buildRustPackage {
|
||||||
fenixPlatform.buildRustPackage
|
|
||||||
{
|
|
||||||
pname = cargoToml.package.name;
|
pname = cargoToml.package.name;
|
||||||
version =
|
version =
|
||||||
let
|
let
|
||||||
commit = inputs.self.shortRev or "dirty";
|
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
|
in
|
||||||
"${builtins.substring 0 8 date}_${commit}";
|
"${builtins.substring 0 8 date}_${commit}";
|
||||||
src = inputs.self.sourceInfo;
|
src = inputs.self.sourceInfo;
|
||||||
|
@ -51,9 +48,7 @@
|
||||||
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
|
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
devShell =
|
devShell = nixpkgs.mkShell {
|
||||||
nixpkgs.mkShell
|
|
||||||
{
|
|
||||||
name = "Alejandra";
|
name = "Alejandra";
|
||||||
packages = [
|
packages = [
|
||||||
fenix.rust-analyzer
|
fenix.rust-analyzer
|
||||||
|
|
|
@ -12,46 +12,50 @@ pub fn rule(
|
||||||
build_ctx.config.layout()
|
build_ctx.config.layout()
|
||||||
};
|
};
|
||||||
|
|
||||||
let child = children.get_next().unwrap();
|
// left
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
let child = children.get_next().unwrap();
|
let child = children.get_next().unwrap();
|
||||||
match layout {
|
match layout {
|
||||||
crate::config::Layout::Tall => {
|
crate::config::Layout::Tall => {
|
||||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||||
steps.push_back(crate::builder::Step::Dedent);
|
|
||||||
}
|
}
|
||||||
crate::config::Layout::Wide => {
|
crate::config::Layout::Wide => {
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
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
|
steps
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,8 @@ pub fn rule(
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
steps.push_back(crate::builder::Step::Format(child.element));
|
||||||
match layout {
|
match layout {
|
||||||
crate::config::Layout::Tall => {
|
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_LIST
|
||||||
| rnix::SyntaxKind::NODE_PAREN
|
| rnix::SyntaxKind::NODE_PAREN
|
||||||
| rnix::SyntaxKind::NODE_STRING =
|
| rnix::SyntaxKind::NODE_STRING =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue