diff --git a/swayfmt/src/items/item_configurable/mod.rs b/swayfmt/src/items/item_configurable/mod.rs index 550b8916d8d..1a40f5d3753 100644 --- a/swayfmt/src/items/item_configurable/mod.rs +++ b/swayfmt/src/items/item_configurable/mod.rs @@ -1,4 +1,5 @@ use crate::{ + comments::rewrite_with_comments, config::user_def::FieldAlignment, formatter::{ shape::{ExprKind, LineStyle}, @@ -27,6 +28,8 @@ impl Format for ItemConfigurable { .shape .with_code_line_from(LineStyle::Multiline, ExprKind::default()), |formatter| -> Result<(), FormatterError> { + // Required for comment formatting + let start_len = formatted_code.len(); // Add configurable token write!( formatted_code, @@ -119,6 +122,14 @@ impl Format for ItemConfigurable { // Handle closing brace Self::close_curly_brace(formatted_code, formatter)?; + rewrite_with_comments::( + formatter, + self.span(), + self.leaf_spans(), + formatted_code, + start_len, + )?; + Ok(()) }, )?; diff --git a/swayfmt/tests/mod.rs b/swayfmt/tests/mod.rs index 1039e977251..de0109e895c 100644 --- a/swayfmt/tests/mod.rs +++ b/swayfmt/tests/mod.rs @@ -1608,6 +1608,44 @@ impl MyContract for Contract { ); } +#[test] +fn configurable_comments() { + check( + r#" +script; + +use std::{constants::ZERO_B256, vm::evm::evm_address::EvmAddress}; + +configurable { /* multiline */ + // double slash + /// triple slash + SIGNER: EvmAddress = EvmAddress { + // double slash + // double slash + value: ZERO_B256, // end of line + }, +} + +fn main() {}"#, + r#"script; + +use std::{constants::ZERO_B256, vm::evm::evm_address::EvmAddress}; + +configurable { /* multiline */ + // double slash + /// triple slash + SIGNER: EvmAddress = EvmAddress { + // double slash + // double slash + value: ZERO_B256, // end of line + }, +} + +fn main() {} +"#, + ); +} + #[test] fn empty_fn() { check(