Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed docstring trimming
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
  • Loading branch information
arihant2math committed Feb 3, 2025
commit a130b6cca6ef6a428eff1157df80b9d7cdf81c22
25 changes: 24 additions & 1 deletion compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3357,7 +3357,30 @@ fn split_doc<'a>(
if let Some(doc) = try_get_constant_string(std::slice::from_ref(&expr.value)) {
if opts.optimize < 2 {
return (
Some(doc.split("\n").map(|x| x.trim_start()).join("\n")),
Some({
let split: Vec<&str> = doc.split('\n').collect();
// Find the amount of whitespace in the first line
let first_text = split.iter().find(|line| !line.trim().is_empty());
if let Some(first_text) = first_text {
let whitespace = first_text
.chars()
.take_while(|c| c.is_whitespace())
.collect::<String>();
split
.iter()
.map(|line| {
if line.starts_with(&whitespace) {
line[whitespace.len()..].to_owned()
} else {
line.to_string()
}
})
.collect::<Vec<String>>()
.join("\n")
} else {
doc
}
}),
body_rest,
);
} else {
Expand Down