Skip to content

Commit c8892e5

Browse files
committed
proper format docs, remove extra indent & append ; at enf of fn
1 parent 0255088 commit c8892e5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

crates/doc/src/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rayon::prelude::*;
1212
use solar::interface::source_map::FileName;
1313
use std::{
1414
cmp::Ordering,
15-
fmt::Debug,
1615
fs,
1716
path::{Path, PathBuf},
1817
};

crates/doc/src/parser/item.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,25 @@ impl ParseItem {
8181
///
8282
/// The parameter should be the full source file where this parse item originated from.
8383
pub fn with_code(mut self, source: &str) -> Self {
84-
self.code = source[self.source.range()].to_string();
84+
let mut code = source[self.source.range()].to_string();
85+
86+
// Special function case, add `;` at the end of definition.
87+
if let ParseSource::Function(_) = self.source {
88+
code.push(';');
89+
}
90+
91+
// Remove extra indent from source lines.
92+
self.code = code
93+
.lines()
94+
.map(|line| {
95+
if line.chars().take_while(|c| c.is_whitespace()).count() > 4 {
96+
line.strip_prefix(" ").unwrap_or(line)
97+
} else {
98+
line
99+
}
100+
})
101+
.collect::<Vec<_>>()
102+
.join("\n");
85103
self
86104
}
87105

0 commit comments

Comments
 (0)