Skip to content
Merged
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 13, 2025
commit 548e1f2e620b403bdc7e7e9d180eb7b902402fd0
25 changes: 24 additions & 1 deletion compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,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