Skip to content

Commit

Permalink
retain_in_keyword test passes now
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty committed Aug 24, 2024
1 parent 5f92cb2 commit 1d5b9c2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion swayfmt/src/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ impl Formatter {
self.with_comments_context(src)?;

let annotated_module = parse_file(&self.source_engine, Arc::from(src), path.clone())?;
eprintln!("{:#?}", annotated_module);
annotated_module.format(&mut raw_formatted_code, self)?;

let mut formatted_code = String::from(&raw_formatted_code);
Expand Down
7 changes: 6 additions & 1 deletion swayfmt/src/items/item_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ impl Format for ItemStorage {
formatted_code: &mut FormattedCode,
formatter: &mut Formatter,
) -> Result<(), FormatterError> {
eprintln!("ITEM STORAGE");
formatter.with_shape(
formatter
.shape
Expand Down Expand Up @@ -276,6 +275,12 @@ impl LeafSpans for StorageEntry {
impl LeafSpans for StorageField {
fn leaf_spans(&self) -> Vec<ByteSpan> {
let mut collected_spans = vec![ByteSpan::from(self.name.span())];
if let Some(in_token) = &self.in_token {
collected_spans.push(ByteSpan::from(in_token.span()));
}
if let Some(key_expr) = &self.key_expr {
collected_spans.push(ByteSpan::from(key_expr.span()));
}
collected_spans.push(ByteSpan::from(self.colon_token.span()));
collected_spans.append(&mut self.ty.leaf_spans());
collected_spans.push(ByteSpan::from(self.eq_token.span()));
Expand Down
16 changes: 9 additions & 7 deletions swayfmt/src/utils/language/punctuated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,15 @@ impl Format for StorageField {
formatter.with_shape(
formatter.shape.with_default_code_line(),
|formatter| -> Result<(), FormatterError> {
write!(
formatted_code,
"{}{} ",
self.name.span().as_str(),
self.colon_token.span().as_str(),
)?;
write!(formatted_code, "{}", self.name.span().as_str())?;
if let Some(in_token) = &self.in_token {
write!(formatted_code, " {}", in_token.span().as_str())?;
}
if let Some(key_expr) = &self.key_expr {
write!(formatted_code, " {}", key_expr.span().as_str())?;
}
write!(formatted_code, "{} ", self.colon_token.span().as_str())?;

self.ty.format(formatted_code, formatter)?;
write!(formatted_code, " {} ", self.eq_token.span().as_str())?;

Expand All @@ -272,7 +275,6 @@ impl Format for StorageField {
)?;

self.initializer.format(formatted_code, formatter)?;

Ok(())
}
}
Expand Down
5 changes: 2 additions & 3 deletions swayfmt/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use test_macros::assert_eq_pretty;
/// expected output. There are two format passes to ensure that the received output does not change on a second pass.
fn check_with_formatter(unformatted: &str, expected: &str, formatter: &mut Formatter) {
let first_formatted = Formatter::format(formatter, Arc::from(unformatted), None).unwrap();
eprintln!("{:#?}", first_formatted);
assert_eq_pretty!(first_formatted, expected);

let second_formatted =
Expand Down Expand Up @@ -3141,7 +3140,7 @@ fn retain_in_keyword() {
storage {
SRC14 {
target in 0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55: ContractId = ContractId::zero(),
}
},
}
"#},
indoc! {r#"
Expand All @@ -3151,7 +3150,7 @@ fn retain_in_keyword() {
storage {
SRC14 {
target in 0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55: ContractId = ContractId::zero(),
}
},
}
"#},
);
Expand Down

0 comments on commit 1d5b9c2

Please sign in to comment.