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:
parent
f04306e80e
commit
99c80e9e51
3 changed files with 125 additions and 116 deletions
102
flake.nix
102
flake.nix
|
@ -16,41 +16,39 @@
|
||||||
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;
|
src = self.stdenv.mkDerivation {
|
||||||
src = self.stdenv.mkDerivation {
|
name = "src";
|
||||||
name = "src";
|
builder = builtins.toFile "builder.sh" ''
|
||||||
builder = builtins.toFile "builder.sh" ''
|
source $stdenv/setup
|
||||||
source $stdenv/setup
|
|
||||||
|
|
||||||
mkdir $out
|
mkdir $out
|
||||||
cp -rT --no-preserve=mode,ownership $src $out/src/
|
cp -rT --no-preserve=mode,ownership $src $out/src/
|
||||||
cp $cargoLock $out/Cargo.lock
|
cp $cargoLock $out/Cargo.lock
|
||||||
cp $cargoToml $out/Cargo.toml
|
cp $cargoToml $out/Cargo.toml
|
||||||
'';
|
'';
|
||||||
cargoLock = ./Cargo.lock;
|
cargoLock = ./Cargo.lock;
|
||||||
cargoToml = ./Cargo.toml;
|
cargoToml = ./Cargo.toml;
|
||||||
src = ./src;
|
src = ./src;
|
||||||
};
|
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
|
||||||
|
|
||||||
passthru.tests = {
|
|
||||||
version = self.testVersion {package = super.alejandra;};
|
|
||||||
};
|
|
||||||
|
|
||||||
meta = {
|
|
||||||
description = "The Uncompromising Nix Code Formatter.";
|
|
||||||
homepage = "https://github.com/kamadorueda/alejandra";
|
|
||||||
license = self.lib.licenses.unlicense;
|
|
||||||
maintainers = [self.lib.maintainers.kamadorueda];
|
|
||||||
platforms = self.lib.systems.doubles.all;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
)
|
|
||||||
|
passthru.tests = {
|
||||||
|
version = self.testVersion {package = super.alejandra;};
|
||||||
|
};
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "The Uncompromising Nix Code Formatter.";
|
||||||
|
homepage = "https://github.com/kamadorueda/alejandra";
|
||||||
|
license = self.lib.licenses.unlicense;
|
||||||
|
maintainers = [self.lib.maintainers.kamadorueda];
|
||||||
|
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,20 +124,18 @@
|
||||||
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
|
|
||||||
|
|
||||||
pkgsCross.aarch64-multiplatform.pkgsStatic.alejandra
|
pkgsCross.aarch64-multiplatform.pkgsStatic.alejandra
|
||||||
|
|
||||||
pkgsCross.armv7l-hf-multiplatform.pkgsStatic.alejandra
|
pkgsCross.armv7l-hf-multiplatform.pkgsStatic.alejandra
|
||||||
|
|
||||||
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,70 +26,89 @@ 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 node.kind() {
|
||||||
|
rnix::SyntaxKind::NODE_PAREN => {
|
||||||
|
let mut simplified = node.clone();
|
||||||
|
|
||||||
match child.kind() {
|
while matches!(
|
||||||
rnix::SyntaxKind::NODE_PAREN => {
|
simplified.kind(),
|
||||||
let mut simplified = child.into_node().unwrap();
|
rnix::SyntaxKind::NODE_PAREN
|
||||||
|
) {
|
||||||
|
let mut children = crate::children2::new(
|
||||||
|
build_ctx,
|
||||||
|
&simplified,
|
||||||
|
);
|
||||||
|
|
||||||
while matches!(
|
let opener = children.next().unwrap();
|
||||||
simplified.kind(),
|
let expression = children.next().unwrap();
|
||||||
rnix::SyntaxKind::NODE_PAREN
|
let closer = children.next().unwrap();
|
||||||
) {
|
|
||||||
let mut children =
|
|
||||||
crate::children2::new(build_ctx, &simplified);
|
|
||||||
|
|
||||||
let opener = children.next().unwrap();
|
if !opener.has_inline_comment
|
||||||
let expression = children.next().unwrap();
|
&& !opener.has_comments
|
||||||
let closer = children.next().unwrap();
|
&& !expression.has_inline_comment
|
||||||
|
&& !expression.has_comments
|
||||||
|
&& !closer.has_inline_comment
|
||||||
|
&& !closer.has_comments
|
||||||
|
&& matches!(
|
||||||
|
expression.element.kind(),
|
||||||
|
rnix::SyntaxKind::NODE_ATTR_SET
|
||||||
|
| rnix::SyntaxKind::NODE_IDENT
|
||||||
|
| rnix::SyntaxKind::NODE_LIST
|
||||||
|
| rnix::SyntaxKind::NODE_LITERAL
|
||||||
|
| rnix::SyntaxKind::NODE_PAREN
|
||||||
|
| rnix::SyntaxKind::NODE_PATH_WITH_INTERPOL
|
||||||
|
| rnix::SyntaxKind::NODE_STRING
|
||||||
|
)
|
||||||
|
{
|
||||||
|
simplified =
|
||||||
|
expression.element.into_node().unwrap();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !opener.has_inline_comment
|
children.push(simplified.into());
|
||||||
&& !opener.has_comments
|
}
|
||||||
&& !expression.has_inline_comment
|
_ => {
|
||||||
&& !expression.has_comments
|
children.push(node.clone().into());
|
||||||
&& !closer.has_inline_comment
|
|
||||||
&& !closer.has_comments
|
|
||||||
&& matches!(
|
|
||||||
expression.element.kind(),
|
|
||||||
rnix::SyntaxKind::NODE_ATTR_SET
|
|
||||||
| rnix::SyntaxKind::NODE_IDENT
|
|
||||||
| rnix::SyntaxKind::NODE_LIST
|
|
||||||
| rnix::SyntaxKind::NODE_LITERAL
|
|
||||||
| rnix::SyntaxKind::NODE_PAREN
|
|
||||||
| rnix::SyntaxKind::NODE_PATH_WITH_INTERPOL
|
|
||||||
| rnix::SyntaxKind::NODE_STRING
|
|
||||||
)
|
|
||||||
{
|
|
||||||
simplified =
|
|
||||||
expression.element.into_node().unwrap();
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
children.push(simplified.into());
|
if pos.is_some() {
|
||||||
}
|
pos.as_mut().unwrap().update(&node.text().to_string());
|
||||||
rnix::SyntaxKind::TOKEN_COMMENT => {
|
|
||||||
children.push(
|
|
||||||
crate::builder::make_isolated_token(
|
|
||||||
rnix::SyntaxKind::TOKEN_COMMENT,
|
|
||||||
&dedent_comment(pos.as_ref().unwrap(), &text),
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
rnix::SyntaxKind::TOKEN_WHITESPACE => {
|
|
||||||
if crate::utils::count_newlines(&text) > 0 {
|
|
||||||
children.push(child);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
children.push(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos.is_some() {
|
rnix::SyntaxElement::Token(token) => {
|
||||||
pos.as_mut().unwrap().update(&text);
|
match token.kind() {
|
||||||
|
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||||
|
children.push(
|
||||||
|
crate::builder::make_isolated_token(
|
||||||
|
rnix::SyntaxKind::TOKEN_COMMENT,
|
||||||
|
&dedent_comment(
|
||||||
|
pos.as_ref().unwrap(),
|
||||||
|
token.text(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
rnix::SyntaxKind::TOKEN_WHITESPACE => {
|
||||||
|
if crate::utils::count_newlines(token.text()) > 0 {
|
||||||
|
children.push(token.clone().into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
children.push(token.clone().into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pos.is_some() {
|
||||||
|
pos.as_mut().unwrap().update(token.text());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue