mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
feat: multiline strings done right
This commit is contained in:
parent
a35638f586
commit
a5e92895fa
4 changed files with 48 additions and 11 deletions
|
@ -36,7 +36,8 @@
|
||||||
|
|
||||||
It's written in [Rust](https://www.rust-lang.org/)
|
It's written in [Rust](https://www.rust-lang.org/)
|
||||||
and formats [Nixpkgs](https://github.com/NixOS/nixpkgs)
|
and formats [Nixpkgs](https://github.com/NixOS/nixpkgs)
|
||||||
in just a few seconds[^benchmark-specs].
|
in just a few seconds.
|
||||||
|
[^benchmark-specs]
|
||||||
|
|
||||||
| Cores | Seconds |
|
| Cores | Seconds |
|
||||||
|:-----:|:--------:
|
|:-----:|:--------:
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub fn rule(
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|e| e.kind() != rnix::SyntaxKind::TOKEN_STRING_CONTENT);
|
.filter(|e| e.kind() != rnix::SyntaxKind::TOKEN_STRING_CONTENT);
|
||||||
|
|
||||||
let mut lines: Vec<String> = elements[0..elements.len() - 1]
|
let content: String = elements[0..elements.len() - 1]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|element| match element.kind() {
|
.map(|element| match element.kind() {
|
||||||
rnix::SyntaxKind::TOKEN_STRING_CONTENT => {
|
rnix::SyntaxKind::TOKEN_STRING_CONTENT => {
|
||||||
|
@ -47,9 +47,23 @@ pub fn rule(
|
||||||
}
|
}
|
||||||
_ => placeholder.to_string(),
|
_ => placeholder.to_string(),
|
||||||
})
|
})
|
||||||
.collect::<String>()
|
.collect();
|
||||||
.split('\n')
|
|
||||||
.map(|line| line.trim_end().to_string())
|
let lines: Vec<String> =
|
||||||
|
content.split('\n').map(|line| line.to_string()).collect();
|
||||||
|
|
||||||
|
let should_trim_end: bool =
|
||||||
|
lines.len() >= 1 && lines[lines.len() - 1].trim().len() == 0;
|
||||||
|
|
||||||
|
let mut lines: Vec<String> = lines
|
||||||
|
.iter()
|
||||||
|
.map(|line| {
|
||||||
|
if should_trim_end {
|
||||||
|
line.trim_end().to_string()
|
||||||
|
} else {
|
||||||
|
line.to_string()
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// eprintln!("0: {:?}", lines);
|
// eprintln!("0: {:?}", lines);
|
||||||
|
@ -92,14 +106,18 @@ pub fn rule(
|
||||||
|
|
||||||
if portions.len() == 1 {
|
if portions.len() == 1 {
|
||||||
if portions[0].len() > 0 || index + 1 == lines.len() {
|
if portions[0].len() > 0 || index + 1 == lines.len() {
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
if lines.len() > 1 {
|
||||||
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
|
}
|
||||||
steps.push_back(crate::builder::Step::Token(
|
steps.push_back(crate::builder::Step::Token(
|
||||||
rnix::SyntaxKind::TOKEN_STRING_CONTENT,
|
rnix::SyntaxKind::TOKEN_STRING_CONTENT,
|
||||||
portions[0].to_string(),
|
portions[0].to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
if lines.len() > 1 {
|
||||||
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
|
}
|
||||||
for (index, portion) in portions.iter().enumerate() {
|
for (index, portion) in portions.iter().enumerate() {
|
||||||
steps.push_back(crate::builder::Step::Token(
|
steps.push_back(crate::builder::Step::Token(
|
||||||
rnix::SyntaxKind::TOKEN_STRING_CONTENT,
|
rnix::SyntaxKind::TOKEN_STRING_CONTENT,
|
||||||
|
|
|
@ -59,4 +59,13 @@
|
||||||
''
|
''
|
||||||
###
|
###
|
||||||
''-couch_ini ${ cfg.package }/etc/default.ini ${ configFile } ${ pkgs.writeText "couchdb-extra.ini" cfg.extraConfig } ${ cfg.configFile }''
|
''-couch_ini ${ cfg.package }/etc/default.ini ${ configFile } ${ pkgs.writeText "couchdb-extra.ini" cfg.extraConfig } ${ cfg.configFile }''
|
||||||
|
###
|
||||||
|
''exec i3-input -F "mark %s" -l 1 -P 'Mark: ' ''
|
||||||
|
###
|
||||||
|
''exec i3-input -F '[con_mark="%s"] focus' -l 1 -P 'Go to: ' ''
|
||||||
|
###
|
||||||
|
''"${ pkgs.name or "<unknown-name>" }";''
|
||||||
|
###
|
||||||
|
''
|
||||||
|
${pkgs.replace-secret}/bin/replace-secret '${placeholder}' '${secretFile}' '${targetFile}' ''
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
b
|
b
|
||||||
"
|
"
|
||||||
###
|
###
|
||||||
'' ''
|
''''
|
||||||
###
|
###
|
||||||
'' a''
|
''a''
|
||||||
###
|
###
|
||||||
'' ${ "" }''
|
''${ "" }''
|
||||||
###
|
###
|
||||||
'' ${ "" }
|
'' ${ "" }
|
||||||
|
|
||||||
|
@ -57,7 +57,16 @@
|
||||||
[${ mkSectionName sectName }]
|
[${ mkSectionName sectName }]
|
||||||
''
|
''
|
||||||
###
|
###
|
||||||
'' -couch_ini ${ cfg.package }/etc/default.ini ${ configFile } ${
|
''-couch_ini ${ cfg.package }/etc/default.ini ${ configFile } ${
|
||||||
pkgs.writeText "couchdb-extra.ini" cfg.extraConfig
|
pkgs.writeText "couchdb-extra.ini" cfg.extraConfig
|
||||||
} ${ cfg.configFile }''
|
} ${ cfg.configFile }''
|
||||||
|
###
|
||||||
|
''exec i3-input -F "mark %s" -l 1 -P 'Mark: ' ''
|
||||||
|
###
|
||||||
|
''exec i3-input -F '[con_mark="%s"] focus' -l 1 -P 'Go to: ' ''
|
||||||
|
###
|
||||||
|
''"${ pkgs.name or "<unknown-name>" }";''
|
||||||
|
###
|
||||||
|
''
|
||||||
|
${ pkgs.replace-secret }/bin/replace-secret '${ placeholder }' '${ secretFile }' '${ targetFile }' ''
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue