Skip to content

Commit 813dea1

Browse files
committed
implemented setters for comment text and spans
1 parent 6e69f10 commit 813dea1

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/comments.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ impl Comment {
140140
pub fn text(&self) -> &str {
141141
self.kind().comment()
142142
}
143+
144+
/// Set the [`CommentKind`] for the comment
145+
pub fn set_kind(&mut self, kind: CommentKind) -> &mut Self {
146+
self.kind = kind;
147+
self
148+
}
149+
150+
/// Sets new [`Span`] locations for the comment
151+
pub const fn set_span_locations(&mut self, start: Location, end: Location) -> &mut Self {
152+
self.span = Span::new(start, end);
153+
self
154+
}
155+
}
156+
157+
impl Default for Comment {
158+
fn default() -> Self {
159+
Self { kind: CommentKind::SingleLine(String::new()), span: Span::default() }
160+
}
143161
}
144162

145163
/// Enum for returning errors withe Comment parsing
@@ -363,6 +381,21 @@ impl Comments {
363381
}
364382
}
365383

384+
fn combine_leading_comments(comments: &Comments, line: u64) -> Comment {
385+
let mut comment: Comment = Comment::default();
386+
let mut content = String::new();
387+
let mut span = Span::default();
388+
for possible_comment in comments.comments() {
389+
if possible_comment.span().end().line() < line {
390+
comment.set_kind(CommentKind::SingleLine(
391+
comment.text().to_owned() + possible_comment.text(),
392+
));
393+
}
394+
}
395+
396+
comment
397+
}
398+
366399
#[cfg(test)]
367400
mod tests {
368401
use std::{env, fs};

0 commit comments

Comments
 (0)