mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +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:
|
||||
import inputs.nixpkgs {
|
||||
overlays = [
|
||||
(
|
||||
self: super: {
|
||||
alejandra = self.rustPlatform.buildRustPackage {
|
||||
pname = "alejandra";
|
||||
inherit version;
|
||||
src = self.stdenv.mkDerivation {
|
||||
name = "src";
|
||||
builder = builtins.toFile "builder.sh" ''
|
||||
source $stdenv/setup
|
||||
(self: super: {
|
||||
alejandra = self.rustPlatform.buildRustPackage {
|
||||
pname = "alejandra";
|
||||
inherit version;
|
||||
src = self.stdenv.mkDerivation {
|
||||
name = "src";
|
||||
builder = builtins.toFile "builder.sh" ''
|
||||
source $stdenv/setup
|
||||
|
||||
mkdir $out
|
||||
cp -rT --no-preserve=mode,ownership $src $out/src/
|
||||
cp $cargoLock $out/Cargo.lock
|
||||
cp $cargoToml $out/Cargo.toml
|
||||
'';
|
||||
cargoLock = ./Cargo.lock;
|
||||
cargoToml = ./Cargo.toml;
|
||||
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;
|
||||
};
|
||||
mkdir $out
|
||||
cp -rT --no-preserve=mode,ownership $src $out/src/
|
||||
cp $cargoLock $out/Cargo.lock
|
||||
cp $cargoToml $out/Cargo.toml
|
||||
'';
|
||||
cargoLock = ./Cargo.lock;
|
||||
cargoToml = ./Cargo.toml;
|
||||
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;
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
system = host;
|
||||
};
|
||||
|
@ -62,12 +60,10 @@
|
|||
|
||||
buildBinariesForHost = host: pkgs: let
|
||||
binaries = builtins.listToAttrs (
|
||||
builtins.map (
|
||||
pkg: {
|
||||
name = "alejandra-${pkg.stdenv.targetPlatform.config}";
|
||||
value = 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: {
|
||||
inherit name;
|
||||
path = "${binary}/bin/alejandra";
|
||||
}
|
||||
)
|
||||
(name: binary: {
|
||||
inherit name;
|
||||
path = "${binary}/bin/alejandra";
|
||||
})
|
||||
binaries
|
||||
);
|
||||
};
|
||||
|
@ -130,20 +124,18 @@
|
|||
alejandra
|
||||
];
|
||||
packages."x86_64-linux" = with nixpkgs."x86_64-linux";
|
||||
(
|
||||
buildBinariesForHost "x86_64-linux" [
|
||||
alejandra
|
||||
pkgsStatic.alejandra
|
||||
(buildBinariesForHost "x86_64-linux" [
|
||||
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 {
|
||||
name = "alejandra";
|
||||
|
|
|
@ -15,13 +15,11 @@
|
|||
devShell.${system} = nixpkgs.mkShell {
|
||||
name = "alejandra";
|
||||
packages = [
|
||||
(
|
||||
fenix.combine [
|
||||
fenix.latest.rustc
|
||||
fenix.latest.toolchain
|
||||
fenix.targets."wasm32-unknown-unknown".latest.rust-std
|
||||
]
|
||||
)
|
||||
(fenix.combine [
|
||||
fenix.latest.rustc
|
||||
fenix.latest.toolchain
|
||||
fenix.targets."wasm32-unknown-unknown".latest.rust-std
|
||||
])
|
||||
nixpkgs.binaryen
|
||||
nixpkgs.pkg-config
|
||||
nixpkgs.openssl
|
||||
|
|
|
@ -26,70 +26,89 @@ impl Children {
|
|||
};
|
||||
|
||||
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() {
|
||||
rnix::SyntaxKind::NODE_PAREN => {
|
||||
let mut simplified = child.into_node().unwrap();
|
||||
while matches!(
|
||||
simplified.kind(),
|
||||
rnix::SyntaxKind::NODE_PAREN
|
||||
) {
|
||||
let mut children = crate::children2::new(
|
||||
build_ctx,
|
||||
&simplified,
|
||||
);
|
||||
|
||||
while matches!(
|
||||
simplified.kind(),
|
||||
rnix::SyntaxKind::NODE_PAREN
|
||||
) {
|
||||
let mut children =
|
||||
crate::children2::new(build_ctx, &simplified);
|
||||
let opener = children.next().unwrap();
|
||||
let expression = children.next().unwrap();
|
||||
let closer = children.next().unwrap();
|
||||
|
||||
let opener = children.next().unwrap();
|
||||
let expression = children.next().unwrap();
|
||||
let closer = children.next().unwrap();
|
||||
if !opener.has_inline_comment
|
||||
&& !opener.has_comments
|
||||
&& !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
|
||||
&& !opener.has_comments
|
||||
&& !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;
|
||||
children.push(simplified.into());
|
||||
}
|
||||
_ => {
|
||||
children.push(node.clone().into());
|
||||
}
|
||||
}
|
||||
|
||||
children.push(simplified.into());
|
||||
}
|
||||
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);
|
||||
if pos.is_some() {
|
||||
pos.as_mut().unwrap().update(&node.text().to_string());
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
children.push(child);
|
||||
}
|
||||
}
|
||||
|
||||
if pos.is_some() {
|
||||
pos.as_mut().unwrap().update(&text);
|
||||
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(),
|
||||
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