mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 21:17:45 +00:00
perf: split children rewrittes
This commit is contained in:
parent
f04306e80e
commit
99c80e9e51
3 changed files with 125 additions and 116 deletions
24
flake.nix
24
flake.nix
|
@ -16,8 +16,7 @@
|
||||||
nixpkgsForHost = host:
|
nixpkgsForHost = host:
|
||||||
import inputs.nixpkgs {
|
import inputs.nixpkgs {
|
||||||
overlays = [
|
overlays = [
|
||||||
(
|
(self: super: {
|
||||||
self: super: {
|
|
||||||
alejandra = self.rustPlatform.buildRustPackage {
|
alejandra = self.rustPlatform.buildRustPackage {
|
||||||
pname = "alejandra";
|
pname = "alejandra";
|
||||||
inherit version;
|
inherit version;
|
||||||
|
@ -49,8 +48,7 @@
|
||||||
platforms = self.lib.systems.doubles.all;
|
platforms = self.lib.systems.doubles.all;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
})
|
||||||
)
|
|
||||||
];
|
];
|
||||||
system = host;
|
system = host;
|
||||||
};
|
};
|
||||||
|
@ -62,12 +60,10 @@
|
||||||
|
|
||||||
buildBinariesForHost = host: pkgs: let
|
buildBinariesForHost = host: pkgs: let
|
||||||
binaries = builtins.listToAttrs (
|
binaries = builtins.listToAttrs (
|
||||||
builtins.map (
|
builtins.map (pkg: {
|
||||||
pkg: {
|
|
||||||
name = "alejandra-${pkg.stdenv.targetPlatform.config}";
|
name = "alejandra-${pkg.stdenv.targetPlatform.config}";
|
||||||
value = pkg;
|
value = pkg;
|
||||||
}
|
})
|
||||||
)
|
|
||||||
pkgs
|
pkgs
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
|
@ -75,12 +71,10 @@
|
||||||
// {
|
// {
|
||||||
"alejandra-binaries" = nixpkgs.${host}.linkFarm "alejandra-binaries" (
|
"alejandra-binaries" = nixpkgs.${host}.linkFarm "alejandra-binaries" (
|
||||||
nixpkgs.${host}.lib.mapAttrsToList
|
nixpkgs.${host}.lib.mapAttrsToList
|
||||||
(
|
(name: binary: {
|
||||||
name: binary: {
|
|
||||||
inherit name;
|
inherit name;
|
||||||
path = "${binary}/bin/alejandra";
|
path = "${binary}/bin/alejandra";
|
||||||
}
|
})
|
||||||
)
|
|
||||||
binaries
|
binaries
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -130,8 +124,7 @@
|
||||||
alejandra
|
alejandra
|
||||||
];
|
];
|
||||||
packages."x86_64-linux" = with nixpkgs."x86_64-linux";
|
packages."x86_64-linux" = with nixpkgs."x86_64-linux";
|
||||||
(
|
(buildBinariesForHost "x86_64-linux" [
|
||||||
buildBinariesForHost "x86_64-linux" [
|
|
||||||
alejandra
|
alejandra
|
||||||
pkgsStatic.alejandra
|
pkgsStatic.alejandra
|
||||||
|
|
||||||
|
@ -142,8 +135,7 @@
|
||||||
pkgsCross.gnu32.pkgsStatic.alejandra
|
pkgsCross.gnu32.pkgsStatic.alejandra
|
||||||
|
|
||||||
pkgsCross.raspberryPi.pkgsStatic.alejandra
|
pkgsCross.raspberryPi.pkgsStatic.alejandra
|
||||||
]
|
])
|
||||||
)
|
|
||||||
// {
|
// {
|
||||||
"alejandra-vscode-vsix" = mkYarnPackage {
|
"alejandra-vscode-vsix" = mkYarnPackage {
|
||||||
name = "alejandra";
|
name = "alejandra";
|
||||||
|
|
|
@ -15,13 +15,11 @@
|
||||||
devShell.${system} = nixpkgs.mkShell {
|
devShell.${system} = nixpkgs.mkShell {
|
||||||
name = "alejandra";
|
name = "alejandra";
|
||||||
packages = [
|
packages = [
|
||||||
(
|
(fenix.combine [
|
||||||
fenix.combine [
|
|
||||||
fenix.latest.rustc
|
fenix.latest.rustc
|
||||||
fenix.latest.toolchain
|
fenix.latest.toolchain
|
||||||
fenix.targets."wasm32-unknown-unknown".latest.rust-std
|
fenix.targets."wasm32-unknown-unknown".latest.rust-std
|
||||||
]
|
])
|
||||||
)
|
|
||||||
nixpkgs.binaryen
|
nixpkgs.binaryen
|
||||||
nixpkgs.pkg-config
|
nixpkgs.pkg-config
|
||||||
nixpkgs.openssl
|
nixpkgs.openssl
|
||||||
|
|
|
@ -26,18 +26,20 @@ impl Children {
|
||||||
};
|
};
|
||||||
|
|
||||||
for child in node.children_with_tokens() {
|
for child in node.children_with_tokens() {
|
||||||
let text: String = child.to_string();
|
match child {
|
||||||
|
rnix::SyntaxElement::Node(node) => {
|
||||||
match child.kind() {
|
match node.kind() {
|
||||||
rnix::SyntaxKind::NODE_PAREN => {
|
rnix::SyntaxKind::NODE_PAREN => {
|
||||||
let mut simplified = child.into_node().unwrap();
|
let mut simplified = node.clone();
|
||||||
|
|
||||||
while matches!(
|
while matches!(
|
||||||
simplified.kind(),
|
simplified.kind(),
|
||||||
rnix::SyntaxKind::NODE_PAREN
|
rnix::SyntaxKind::NODE_PAREN
|
||||||
) {
|
) {
|
||||||
let mut children =
|
let mut children = crate::children2::new(
|
||||||
crate::children2::new(build_ctx, &simplified);
|
build_ctx,
|
||||||
|
&simplified,
|
||||||
|
);
|
||||||
|
|
||||||
let opener = children.next().unwrap();
|
let opener = children.next().unwrap();
|
||||||
let expression = children.next().unwrap();
|
let expression = children.next().unwrap();
|
||||||
|
@ -69,27 +71,44 @@ impl Children {
|
||||||
|
|
||||||
children.push(simplified.into());
|
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 => {
|
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||||
children.push(
|
children.push(
|
||||||
crate::builder::make_isolated_token(
|
crate::builder::make_isolated_token(
|
||||||
rnix::SyntaxKind::TOKEN_COMMENT,
|
rnix::SyntaxKind::TOKEN_COMMENT,
|
||||||
&dedent_comment(pos.as_ref().unwrap(), &text),
|
&dedent_comment(
|
||||||
|
pos.as_ref().unwrap(),
|
||||||
|
token.text(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
rnix::SyntaxKind::TOKEN_WHITESPACE => {
|
rnix::SyntaxKind::TOKEN_WHITESPACE => {
|
||||||
if crate::utils::count_newlines(&text) > 0 {
|
if crate::utils::count_newlines(token.text()) > 0 {
|
||||||
children.push(child);
|
children.push(token.clone().into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
children.push(child);
|
children.push(token.clone().into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pos.is_some() {
|
if pos.is_some() {
|
||||||
pos.as_mut().unwrap().update(&text);
|
pos.as_mut().unwrap().update(token.text());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue