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

perf: split children rewrittes

This commit is contained in:
Kevin Amado 2022-03-01 23:17:26 -05:00
parent f04306e80e
commit 99c80e9e51
3 changed files with 125 additions and 116 deletions

View file

@ -16,8 +16,7 @@
nixpkgsForHost = host:
import inputs.nixpkgs {
overlays = [
(
self: super: {
(self: super: {
alejandra = self.rustPlatform.buildRustPackage {
pname = "alejandra";
inherit version;
@ -49,8 +48,7 @@
platforms = self.lib.systems.doubles.all;
};
};
}
)
})
];
system = host;
};
@ -62,12 +60,10 @@
buildBinariesForHost = host: pkgs: let
binaries = builtins.listToAttrs (
builtins.map (
pkg: {
builtins.map (pkg: {
name = "alejandra-${pkg.stdenv.targetPlatform.config}";
value = pkg;
}
)
})
pkgs
);
in
@ -75,12 +71,10 @@
// {
"alejandra-binaries" = nixpkgs.${host}.linkFarm "alejandra-binaries" (
nixpkgs.${host}.lib.mapAttrsToList
(
name: binary: {
(name: binary: {
inherit name;
path = "${binary}/bin/alejandra";
}
)
})
binaries
);
};
@ -130,8 +124,7 @@
alejandra
];
packages."x86_64-linux" = with nixpkgs."x86_64-linux";
(
buildBinariesForHost "x86_64-linux" [
(buildBinariesForHost "x86_64-linux" [
alejandra
pkgsStatic.alejandra
@ -142,8 +135,7 @@
pkgsCross.gnu32.pkgsStatic.alejandra
pkgsCross.raspberryPi.pkgsStatic.alejandra
]
)
])
// {
"alejandra-vscode-vsix" = mkYarnPackage {
name = "alejandra";

View file

@ -15,13 +15,11 @@
devShell.${system} = nixpkgs.mkShell {
name = "alejandra";
packages = [
(
fenix.combine [
(fenix.combine [
fenix.latest.rustc
fenix.latest.toolchain
fenix.targets."wasm32-unknown-unknown".latest.rust-std
]
)
])
nixpkgs.binaryen
nixpkgs.pkg-config
nixpkgs.openssl

View file

@ -26,18 +26,20 @@ impl Children {
};
for child in node.children_with_tokens() {
let text: String = child.to_string();
match child.kind() {
match child {
rnix::SyntaxElement::Node(node) => {
match node.kind() {
rnix::SyntaxKind::NODE_PAREN => {
let mut simplified = child.into_node().unwrap();
let mut simplified = node.clone();
while matches!(
simplified.kind(),
rnix::SyntaxKind::NODE_PAREN
) {
let mut children =
crate::children2::new(build_ctx, &simplified);
let mut children = crate::children2::new(
build_ctx,
&simplified,
);
let opener = children.next().unwrap();
let expression = children.next().unwrap();
@ -69,27 +71,44 @@ impl Children {
children.push(simplified.into());
}
_ => {
children.push(node.clone().into());
}
}
if pos.is_some() {
pos.as_mut().unwrap().update(&node.text().to_string());
}
}
rnix::SyntaxElement::Token(token) => {
match token.kind() {
rnix::SyntaxKind::TOKEN_COMMENT => {
children.push(
crate::builder::make_isolated_token(
rnix::SyntaxKind::TOKEN_COMMENT,
&dedent_comment(pos.as_ref().unwrap(), &text),
&dedent_comment(
pos.as_ref().unwrap(),
token.text(),
),
)
.into(),
);
}
rnix::SyntaxKind::TOKEN_WHITESPACE => {
if crate::utils::count_newlines(&text) > 0 {
children.push(child);
if crate::utils::count_newlines(token.text()) > 0 {
children.push(token.clone().into());
}
}
_ => {
children.push(child);
children.push(token.clone().into());
}
}
if pos.is_some() {
pos.as_mut().unwrap().update(&text);
pos.as_mut().unwrap().update(token.text());
}
}
}
}