Skip to content

Conversation

@zhfr7
Copy link

@zhfr7 zhfr7 commented Dec 19, 2025

  • Avoids trimming indentation from doc code block lines by keeping track of whether the current line is between two code fences or not.
    • Assumes that "```ab" and "```" are the start and end fences respectively.
    • Also assumes that the start of the indentation is one space after "///".
  • Additionally remove the use of format as it just a combination of two push_strs, but also creates a new String.

I'm not that sure about the second point but let me know if format is still preferred here, I just feel like it creating a new String is unnecessary, when you can just refer to the original &strs.

Closes #956.

@Mte90 Mte90 requested a review from Ph0enixKM December 19, 2025 17:00
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/modules/statement/comment_doc.rs 95.65% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @zhfr7 for your help! This PR gave me a smile on my face as I had no time to do it yet I've been constantly thinking about fixing this. There is just so much to do. Thank you for your contribution, I really appreciate it.

Your PR is very good. There is just one tought that I had in my mind when reading the diff. The solution could cover not only ab codeblocks but also any block that starts with three backticks... Unless you see some limitations with this approach.

Comment on lines +61 to +63
_ if inside_code_block => {
self.value.push_str(line[1..].trim_end());
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably assumes that each codeblock is one space away. This example:

///```ab
///let a = 12
///```

Generates:

```ab
et a = 12
```

I think that we should probably left_trim by the same amount we left_trim the starting block (```ab).

@Ph0enixKM
Copy link
Member

I'm not that sure about the second point but let me know if format is still preferred here, I just feel like it creating a new String is unnecessary, when you can just refer to the original &strs.

Absolutely on point. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Handle proper indentation in code blocks generated by doc comments

2 participants