From 20b790117ec40a9a1783ebb174002582f1e744ae Mon Sep 17 00:00:00 2001 From: Ori Ziv Date: Wed, 26 Jun 2024 20:07:24 +0300 Subject: [PATCH] Fixing formatting of long unsplittable words. Closes #5905 --- crates/cairo-lang-formatter/src/formatter_impl.rs | 4 +++- .../test_data/cairo_files/linebreaking.cairo | 6 ++---- .../test_data/expected_results/linebreaking.cairo | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/cairo-lang-formatter/src/formatter_impl.rs b/crates/cairo-lang-formatter/src/formatter_impl.rs index d12398bd552..b0a8a231f06 100644 --- a/crates/cairo-lang-formatter/src/formatter_impl.rs +++ b/crates/cairo-lang-formatter/src/formatter_impl.rs @@ -660,7 +660,9 @@ fn format_leading_comment(content: &str, cur_indent: usize, max_line_width: usiz }; last_line_broken = false; for word in orig_comment_line.content.split(' ') { - if current_line.content.len() + word.len() <= max_comment_width { + if current_line.content.is_empty() + || current_line.content.len() + word.len() <= max_comment_width + { current_line.content.push_str(word); current_line.content.push(' '); } else { diff --git a/crates/cairo-lang-formatter/test_data/cairo_files/linebreaking.cairo b/crates/cairo-lang-formatter/test_data/cairo_files/linebreaking.cairo index f7fc09f047f..c05fb16bcf0 100644 --- a/crates/cairo-lang-formatter/test_data/cairo_files/linebreaking.cairo +++ b/crates/cairo-lang-formatter/test_data/cairo_files/linebreaking.cairo @@ -44,7 +44,5 @@ fn function_for_a_comment() { let x = 1; } - - - - +// leading words long_single_word_that_should_not_be_broken_not_creating_addional_empty_lines_padding_padding_padding_padding +fn function_for_a_comment() {} diff --git a/crates/cairo-lang-formatter/test_data/expected_results/linebreaking.cairo b/crates/cairo-lang-formatter/test_data/expected_results/linebreaking.cairo index 693efc42805..046d0ec0af0 100644 --- a/crates/cairo-lang-formatter/test_data/expected_results/linebreaking.cairo +++ b/crates/cairo-lang-formatter/test_data/expected_results/linebreaking.cairo @@ -202,3 +202,6 @@ fn function_for_a_comment() { let x = 1; } +// leading words +// long_single_word_that_should_not_be_broken_not_creating_addional_empty_lines_padding_padding_padding_padding +fn function_for_a_comment() {}