Implement modules' extra, to get function & module comments in docs.
This commit is contained in:
@@ -356,6 +356,12 @@ pub struct RecordConstructor<T> {
|
||||
pub sugar: bool,
|
||||
}
|
||||
|
||||
impl<A> RecordConstructor<A> {
|
||||
pub fn put_doc(&mut self, new_doc: String) {
|
||||
self.doc = Some(new_doc);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct RecordConstructorArg<T> {
|
||||
pub label: Option<String>,
|
||||
@@ -366,6 +372,12 @@ pub struct RecordConstructorArg<T> {
|
||||
pub doc: Option<String>,
|
||||
}
|
||||
|
||||
impl<T: PartialEq> RecordConstructorArg<T> {
|
||||
pub fn put_doc(&mut self, new_doc: String) {
|
||||
self.doc = Some(new_doc);
|
||||
}
|
||||
}
|
||||
|
||||
pub type TypedArg = Arg<Arc<Type>>;
|
||||
pub type UntypedArg = Arg<()>;
|
||||
|
||||
|
||||
@@ -33,22 +33,18 @@ pub fn module(
|
||||
let tokens = tokens.into_iter().filter(|(token, span)| match token {
|
||||
Token::ModuleComment => {
|
||||
extra.module_comments.push(*span);
|
||||
|
||||
false
|
||||
}
|
||||
Token::DocComment => {
|
||||
extra.doc_comments.push(*span);
|
||||
|
||||
false
|
||||
}
|
||||
Token::Comment => {
|
||||
extra.comments.push(*span);
|
||||
|
||||
false
|
||||
}
|
||||
Token::EmptyLine => {
|
||||
extra.empty_lines.push(span.start);
|
||||
|
||||
false
|
||||
}
|
||||
Token::NewLine => false,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::ast::Span;
|
||||
use std::iter::Peekable;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Default, Clone)]
|
||||
pub struct ModuleExtra {
|
||||
@@ -33,3 +34,22 @@ impl<'a> From<(&Span, &'a str)> for Comment<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn comments_before<'a>(
|
||||
comment_spans: &mut Peekable<impl Iterator<Item = &'a Span>>,
|
||||
byte: usize,
|
||||
src: &'a str,
|
||||
) -> Vec<&'a str> {
|
||||
let mut comments = vec![];
|
||||
while let Some(Span { start, .. }) = comment_spans.peek() {
|
||||
if start <= &byte {
|
||||
let comment = comment_spans
|
||||
.next()
|
||||
.expect("Comment before accessing next span");
|
||||
comments.push(Comment::from((comment, src)).content)
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
comments
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user