save-analysis: add docs data

This commit is contained in:
Nick Cameron 2016-09-07 11:23:49 +12:00
parent 987b47549e
commit 68d29cba95
6 changed files with 116 additions and 13 deletions

View File

@ -134,6 +134,7 @@ pub struct EnumData {
pub scope: NodeId, pub scope: NodeId,
pub variants: Vec<NodeId>, pub variants: Vec<NodeId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
/// Data for extern crates. /// Data for extern crates.
@ -167,6 +168,7 @@ pub struct FunctionData {
pub value: String, pub value: String,
pub visibility: Visibility, pub visibility: Visibility,
pub parent: Option<NodeId>, pub parent: Option<NodeId>,
pub docs: String,
} }
/// Data about a function call. /// Data about a function call.
@ -213,6 +215,7 @@ pub struct MacroData {
pub span: Span, pub span: Span,
pub name: String, pub name: String,
pub qualname: String, pub qualname: String,
pub docs: String,
} }
/// Data about a macro use. /// Data about a macro use.
@ -248,6 +251,7 @@ pub struct MethodData {
pub value: String, pub value: String,
pub decl_id: Option<DefId>, pub decl_id: Option<DefId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
/// Data for modules. /// Data for modules.
@ -261,6 +265,7 @@ pub struct ModData {
pub filename: String, pub filename: String,
pub items: Vec<NodeId>, pub items: Vec<NodeId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
/// Data for a reference to a module. /// Data for a reference to a module.
@ -283,6 +288,7 @@ pub struct StructData {
pub value: String, pub value: String,
pub fields: Vec<NodeId>, pub fields: Vec<NodeId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]
@ -295,6 +301,7 @@ pub struct StructVariantData {
pub value: String, pub value: String,
pub scope: NodeId, pub scope: NodeId,
pub parent: Option<NodeId>, pub parent: Option<NodeId>,
pub docs: String,
} }
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]
@ -307,6 +314,7 @@ pub struct TraitData {
pub value: String, pub value: String,
pub items: Vec<NodeId>, pub items: Vec<NodeId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]
@ -319,6 +327,7 @@ pub struct TupleVariantData {
pub value: String, pub value: String,
pub scope: NodeId, pub scope: NodeId,
pub parent: Option<NodeId>, pub parent: Option<NodeId>,
pub docs: String,
} }
/// Data for a typedef. /// Data for a typedef.
@ -331,6 +340,7 @@ pub struct TypeDefData {
pub value: String, pub value: String,
pub visibility: Visibility, pub visibility: Visibility,
pub parent: Option<NodeId>, pub parent: Option<NodeId>,
pub docs: String,
} }
/// Data for a reference to a type or trait. /// Data for a reference to a type or trait.
@ -374,6 +384,7 @@ pub struct VariableData {
pub value: String, pub value: String,
pub type_value: String, pub type_value: String,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]

View File

@ -36,7 +36,7 @@
use std::collections::HashSet; use std::collections::HashSet;
use std::hash::*; use std::hash::*;
use syntax::ast::{self, NodeId, PatKind}; use syntax::ast::{self, NodeId, PatKind, Attribute};
use syntax::parse::token::{self, keywords}; use syntax::parse::token::{self, keywords};
use syntax::visit::{self, Visitor}; use syntax::visit::{self, Visitor};
use syntax::print::pprust::{path_to_string, ty_to_string, bounds_to_string, generics_to_string}; use syntax::print::pprust::{path_to_string, ty_to_string, bounds_to_string, generics_to_string};
@ -44,7 +44,7 @@
use syntax::codemap::Spanned; use syntax::codemap::Spanned;
use syntax_pos::*; use syntax_pos::*;
use super::{escape, generated_code, SaveContext, PathCollector}; use super::{escape, generated_code, SaveContext, PathCollector, docs_for_attrs};
use super::data::*; use super::data::*;
use super::dump::Dump; use super::dump::Dump;
use super::external_data::Lower; use super::external_data::Lower;
@ -368,6 +368,7 @@ fn process_formals(&mut self, formals: &Vec<ast::Arg>, qualname: &str) {
scope: 0, scope: 0,
parent: None, parent: None,
visibility: Visibility::Inherited, visibility: Visibility::Inherited,
docs: String::new(),
}.lower(self.tcx)); }.lower(self.tcx));
} }
} }
@ -380,6 +381,7 @@ fn process_method(&mut self,
id: ast::NodeId, id: ast::NodeId,
name: ast::Name, name: ast::Name,
vis: Visibility, vis: Visibility,
attrs: &[Attribute],
span: Span) { span: Span) {
debug!("process_method: {}:{}", id, name); debug!("process_method: {}:{}", id, name);
@ -421,6 +423,7 @@ fn process_method(&mut self,
value: sig_str, value: sig_str,
decl_id: decl_id, decl_id: decl_id,
visibility: vis, visibility: vis,
docs: docs_for_attrs(attrs),
}.lower(self.tcx)); }.lower(self.tcx));
} }
@ -491,6 +494,7 @@ fn process_generic_params(&mut self,
value: String::new(), value: String::new(),
visibility: Visibility::Inherited, visibility: Visibility::Inherited,
parent: None, parent: None,
docs: String::new(),
}.lower(self.tcx)); }.lower(self.tcx));
} }
} }
@ -541,7 +545,8 @@ fn process_assoc_const(&mut self,
typ: &ast::Ty, typ: &ast::Ty,
expr: &ast::Expr, expr: &ast::Expr,
parent_id: NodeId, parent_id: NodeId,
vis: Visibility) { vis: Visibility,
attrs: &[Attribute]) {
let qualname = format!("::{}", self.tcx.node_path_str(id)); let qualname = format!("::{}", self.tcx.node_path_str(id));
let sub_span = self.span.sub_span_after_keyword(span, keywords::Const); let sub_span = self.span.sub_span_after_keyword(span, keywords::Const);
@ -558,6 +563,7 @@ fn process_assoc_const(&mut self,
scope: self.cur_scope, scope: self.cur_scope,
parent: Some(parent_id), parent: Some(parent_id),
visibility: vis, visibility: vis,
docs: docs_for_attrs(attrs),
}.lower(self.tcx)); }.lower(self.tcx));
} }
@ -600,6 +606,7 @@ fn process_struct(&mut self,
value: val, value: val,
fields: fields, fields: fields,
visibility: From::from(&item.vis), visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx)); }.lower(self.tcx));
} }
@ -653,6 +660,7 @@ fn process_enum(&mut self,
value: val, value: val,
scope: enum_data.scope, scope: enum_data.scope,
parent: Some(item.id), parent: Some(item.id),
docs: docs_for_attrs(&variant.node.attrs),
}.lower(self.tcx)); }.lower(self.tcx));
} }
} }
@ -677,6 +685,7 @@ fn process_enum(&mut self,
value: val, value: val,
scope: enum_data.scope, scope: enum_data.scope,
parent: Some(item.id), parent: Some(item.id),
docs: docs_for_attrs(&variant.node.attrs),
}.lower(self.tcx)); }.lower(self.tcx));
} }
} }
@ -759,6 +768,7 @@ fn process_trait(&mut self,
value: val, value: val,
items: methods.iter().map(|i| i.id).collect(), items: methods.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis), visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx)); }.lower(self.tcx));
} }
@ -1007,6 +1017,7 @@ fn process_var_decl(&mut self, p: &ast::Pat, value: String) {
scope: 0, scope: 0,
parent: None, parent: None,
visibility: Visibility::Inherited, visibility: Visibility::Inherited,
docs: String::new(),
}.lower(self.tcx)); }.lower(self.tcx));
} }
} }
@ -1036,7 +1047,9 @@ fn process_macro_use(&mut self, span: Span, id: NodeId) {
self.dumper.macro_data(MacroData { self.dumper.macro_data(MacroData {
span: sub_span, span: sub_span,
name: data.name.clone(), name: data.name.clone(),
qualname: qualname.clone() qualname: qualname.clone(),
// FIXME where do macro docs come from?
docs: String::new(),
}.lower(self.tcx)); }.lower(self.tcx));
} }
} }
@ -1049,7 +1062,7 @@ fn process_macro_use(&mut self, span: Span, id: NodeId) {
qualname: qualname, qualname: qualname,
scope: data.scope, scope: data.scope,
callee_span: data.callee_span, callee_span: data.callee_span,
imported: data.imported imported: data.imported,
}.lower(self.tcx)); }.lower(self.tcx));
} }
} }
@ -1065,7 +1078,8 @@ fn process_trait_item(&mut self, trait_item: &ast::TraitItem, trait_id: NodeId)
&ty, &ty,
&expr, &expr,
trait_id, trait_id,
Visibility::Public); Visibility::Public,
&trait_item.attrs);
} }
ast::TraitItemKind::Method(ref sig, ref body) => { ast::TraitItemKind::Method(ref sig, ref body) => {
self.process_method(sig, self.process_method(sig,
@ -1073,6 +1087,7 @@ fn process_trait_item(&mut self, trait_item: &ast::TraitItem, trait_id: NodeId)
trait_item.id, trait_item.id,
trait_item.ident.name, trait_item.ident.name,
Visibility::Public, Visibility::Public,
&trait_item.attrs,
trait_item.span); trait_item.span);
} }
ast::TraitItemKind::Const(_, None) | ast::TraitItemKind::Const(_, None) |
@ -1091,7 +1106,8 @@ fn process_impl_item(&mut self, impl_item: &ast::ImplItem, impl_id: NodeId) {
&ty, &ty,
&expr, &expr,
impl_id, impl_id,
From::from(&impl_item.vis)); From::from(&impl_item.vis),
&impl_item.attrs);
} }
ast::ImplItemKind::Method(ref sig, ref body) => { ast::ImplItemKind::Method(ref sig, ref body) => {
self.process_method(sig, self.process_method(sig,
@ -1099,6 +1115,7 @@ fn process_impl_item(&mut self, impl_item: &ast::ImplItem, impl_id: NodeId) {
impl_item.id, impl_item.id,
impl_item.ident.name, impl_item.ident.name,
From::from(&impl_item.vis), From::from(&impl_item.vis),
&impl_item.attrs,
impl_item.span); impl_item.span);
} }
ast::ImplItemKind::Type(_) | ast::ImplItemKind::Type(_) |
@ -1240,6 +1257,7 @@ fn visit_item(&mut self, item: &ast::Item) {
value: value, value: value,
visibility: From::from(&item.vis), visibility: From::from(&item.vis),
parent: None, parent: None,
docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx)); }.lower(self.tcx));
} }
@ -1429,6 +1447,7 @@ fn visit_arm(&mut self, arm: &ast::Arm) {
scope: 0, scope: 0,
parent: None, parent: None,
visibility: Visibility::Inherited, visibility: Visibility::Inherited,
docs: String::new(),
}.lower(self.tcx)); }.lower(self.tcx));
} }
} }

View File

@ -93,6 +93,7 @@ pub struct EnumData {
pub scope: DefId, pub scope: DefId,
pub variants: Vec<DefId>, pub variants: Vec<DefId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
impl Lower for data::EnumData { impl Lower for data::EnumData {
@ -108,6 +109,7 @@ fn lower(self, tcx: TyCtxt) -> EnumData {
scope: make_def_id(self.scope, &tcx.map), scope: make_def_id(self.scope, &tcx.map),
variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(), variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility, visibility: self.visibility,
docs: self.docs,
} }
} }
} }
@ -170,6 +172,7 @@ pub struct FunctionData {
pub value: String, pub value: String,
pub visibility: Visibility, pub visibility: Visibility,
pub parent: Option<DefId>, pub parent: Option<DefId>,
pub docs: String,
} }
impl Lower for data::FunctionData { impl Lower for data::FunctionData {
@ -186,6 +189,7 @@ fn lower(self, tcx: TyCtxt) -> FunctionData {
value: self.value, value: self.value,
visibility: self.visibility, visibility: self.visibility,
parent: self.parent.map(|id| make_def_id(id, &tcx.map)), parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
docs: self.docs,
} }
} }
} }
@ -257,6 +261,7 @@ pub struct MacroData {
pub span: SpanData, pub span: SpanData,
pub name: String, pub name: String,
pub qualname: String, pub qualname: String,
pub docs: String,
} }
impl Lower for data::MacroData { impl Lower for data::MacroData {
@ -267,6 +272,7 @@ fn lower(self, tcx: TyCtxt) -> MacroData {
span: SpanData::from_span(self.span, tcx.sess.codemap()), span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name, name: self.name,
qualname: self.qualname, qualname: self.qualname,
docs: self.docs,
} }
} }
} }
@ -330,7 +336,8 @@ pub struct MethodData {
pub value: String, pub value: String,
pub decl_id: Option<DefId>, pub decl_id: Option<DefId>,
pub visibility: Visibility, pub visibility: Visibility,
pub parent: Option<DefId> pub parent: Option<DefId>,
pub docs: String,
} }
impl Lower for data::MethodData { impl Lower for data::MethodData {
@ -347,6 +354,7 @@ fn lower(self, tcx: TyCtxt) -> MethodData {
decl_id: self.decl_id, decl_id: self.decl_id,
visibility: self.visibility, visibility: self.visibility,
parent: Some(make_def_id(self.scope, &tcx.map)), parent: Some(make_def_id(self.scope, &tcx.map)),
docs: self.docs,
} }
} }
} }
@ -362,6 +370,7 @@ pub struct ModData {
pub filename: String, pub filename: String,
pub items: Vec<DefId>, pub items: Vec<DefId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
impl Lower for data::ModData { impl Lower for data::ModData {
@ -377,6 +386,7 @@ fn lower(self, tcx: TyCtxt) -> ModData {
filename: self.filename, filename: self.filename,
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(), items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility, visibility: self.visibility,
docs: self.docs,
} }
} }
} }
@ -414,6 +424,7 @@ pub struct StructData {
pub value: String, pub value: String,
pub fields: Vec<DefId>, pub fields: Vec<DefId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
impl Lower for data::StructData { impl Lower for data::StructData {
@ -430,6 +441,7 @@ fn lower(self, tcx: TyCtxt) -> StructData {
value: self.value, value: self.value,
fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(), fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility, visibility: self.visibility,
docs: self.docs,
} }
} }
} }
@ -444,6 +456,7 @@ pub struct StructVariantData {
pub value: String, pub value: String,
pub scope: DefId, pub scope: DefId,
pub parent: Option<DefId>, pub parent: Option<DefId>,
pub docs: String,
} }
impl Lower for data::StructVariantData { impl Lower for data::StructVariantData {
@ -459,6 +472,7 @@ fn lower(self, tcx: TyCtxt) -> StructVariantData {
value: self.value, value: self.value,
scope: make_def_id(self.scope, &tcx.map), scope: make_def_id(self.scope, &tcx.map),
parent: self.parent.map(|id| make_def_id(id, &tcx.map)), parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
docs: self.docs,
} }
} }
} }
@ -473,6 +487,7 @@ pub struct TraitData {
pub value: String, pub value: String,
pub items: Vec<DefId>, pub items: Vec<DefId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
impl Lower for data::TraitData { impl Lower for data::TraitData {
@ -488,6 +503,7 @@ fn lower(self, tcx: TyCtxt) -> TraitData {
value: self.value, value: self.value,
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(), items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility, visibility: self.visibility,
docs: self.docs,
} }
} }
} }
@ -502,6 +518,7 @@ pub struct TupleVariantData {
pub value: String, pub value: String,
pub scope: DefId, pub scope: DefId,
pub parent: Option<DefId>, pub parent: Option<DefId>,
pub docs: String,
} }
impl Lower for data::TupleVariantData { impl Lower for data::TupleVariantData {
@ -517,6 +534,7 @@ fn lower(self, tcx: TyCtxt) -> TupleVariantData {
value: self.value, value: self.value,
scope: make_def_id(self.scope, &tcx.map), scope: make_def_id(self.scope, &tcx.map),
parent: self.parent.map(|id| make_def_id(id, &tcx.map)), parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
docs: self.docs,
} }
} }
} }
@ -531,6 +549,7 @@ pub struct TypeDefData {
pub value: String, pub value: String,
pub visibility: Visibility, pub visibility: Visibility,
pub parent: Option<DefId>, pub parent: Option<DefId>,
pub docs: String,
} }
impl Lower for data::TypeDefData { impl Lower for data::TypeDefData {
@ -545,6 +564,7 @@ fn lower(self, tcx: TyCtxt) -> TypeDefData {
value: self.value, value: self.value,
visibility: self.visibility, visibility: self.visibility,
parent: self.parent.map(|id| make_def_id(id, &tcx.map)), parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
docs: self.docs,
} }
} }
} }
@ -632,6 +652,7 @@ pub struct VariableData {
pub type_value: String, pub type_value: String,
pub parent: Option<DefId>, pub parent: Option<DefId>,
pub visibility: Visibility, pub visibility: Visibility,
pub docs: String,
} }
impl Lower for data::VariableData { impl Lower for data::VariableData {
@ -649,6 +670,7 @@ fn lower(self, tcx: TyCtxt) -> VariableData {
type_value: self.type_value, type_value: self.type_value,
parent: self.parent.map(|id| make_def_id(id, &tcx.map)), parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
visibility: self.visibility, visibility: self.visibility,
docs: self.docs,
} }
} }
} }

View File

@ -168,6 +168,7 @@ struct Def {
parent: Option<Id>, parent: Option<Id>,
children: Vec<Id>, children: Vec<Id>,
decl_id: Option<Id>, decl_id: Option<Id>,
docs: String,
} }
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]
@ -209,6 +210,7 @@ fn from(data: EnumData) -> Option<Def> {
parent: None, parent: None,
children: data.variants.into_iter().map(|id| From::from(id)).collect(), children: data.variants.into_iter().map(|id| From::from(id)).collect(),
decl_id: None, decl_id: None,
docs: data.docs,
}), }),
_ => None, _ => None,
} }
@ -227,6 +229,7 @@ fn from(data: TupleVariantData) -> Option<Def> {
parent: data.parent.map(|id| From::from(id)), parent: data.parent.map(|id| From::from(id)),
children: vec![], children: vec![],
decl_id: None, decl_id: None,
docs: data.docs,
}) })
} }
} }
@ -242,6 +245,7 @@ fn from(data: StructVariantData) -> Option<Def> {
parent: data.parent.map(|id| From::from(id)), parent: data.parent.map(|id| From::from(id)),
children: vec![], children: vec![],
decl_id: None, decl_id: None,
docs: data.docs,
}) })
} }
} }
@ -258,6 +262,7 @@ fn from(data: StructData) -> Option<Def> {
parent: None, parent: None,
children: data.fields.into_iter().map(|id| From::from(id)).collect(), children: data.fields.into_iter().map(|id| From::from(id)).collect(),
decl_id: None, decl_id: None,
docs: data.docs,
}), }),
_ => None, _ => None,
} }
@ -276,6 +281,7 @@ fn from(data: TraitData) -> Option<Def> {
children: data.items.into_iter().map(|id| From::from(id)).collect(), children: data.items.into_iter().map(|id| From::from(id)).collect(),
parent: None, parent: None,
decl_id: None, decl_id: None,
docs: data.docs,
}), }),
_ => None, _ => None,
} }
@ -294,6 +300,7 @@ fn from(data: FunctionData) -> Option<Def> {
children: vec![], children: vec![],
parent: data.parent.map(|id| From::from(id)), parent: data.parent.map(|id| From::from(id)),
decl_id: None, decl_id: None,
docs: data.docs,
}), }),
_ => None, _ => None,
} }
@ -312,6 +319,7 @@ fn from(data: MethodData) -> Option<Def> {
children: vec![], children: vec![],
parent: data.parent.map(|id| From::from(id)), parent: data.parent.map(|id| From::from(id)),
decl_id: data.decl_id.map(|id| From::from(id)), decl_id: data.decl_id.map(|id| From::from(id)),
docs: data.docs,
}), }),
_ => None, _ => None,
} }
@ -329,6 +337,7 @@ fn from(data: MacroData) -> Option<Def> {
children: vec![], children: vec![],
parent: None, parent: None,
decl_id: None, decl_id: None,
docs: data.docs,
}) })
} }
} }
@ -345,6 +354,7 @@ fn from(data:ModData) -> Option<Def> {
children: data.items.into_iter().map(|id| From::from(id)).collect(), children: data.items.into_iter().map(|id| From::from(id)).collect(),
parent: None, parent: None,
decl_id: None, decl_id: None,
docs: data.docs,
}), }),
_ => None, _ => None,
} }
@ -363,6 +373,7 @@ fn from(data: TypeDefData) -> Option<Def> {
children: vec![], children: vec![],
parent: data.parent.map(|id| From::from(id)), parent: data.parent.map(|id| From::from(id)),
decl_id: None, decl_id: None,
docs: String::new(),
}), }),
_ => None, _ => None,
} }
@ -386,6 +397,7 @@ fn from(data: VariableData) -> Option<Def> {
children: vec![], children: vec![],
parent: data.parent.map(|id| From::from(id)), parent: data.parent.map(|id| From::from(id)),
decl_id: None, decl_id: None,
docs: data.docs,
}), }),
_ => None, _ => None,
} }

View File

@ -183,6 +183,7 @@ struct Def {
value: String, value: String,
children: Vec<Id>, children: Vec<Id>,
decl_id: Option<Id>, decl_id: Option<Id>,
docs: String,
} }
#[derive(Debug, RustcEncodable)] #[derive(Debug, RustcEncodable)]
@ -223,6 +224,7 @@ fn from(data: EnumData) -> Def {
value: data.value, value: data.value,
children: data.variants.into_iter().map(|id| From::from(id)).collect(), children: data.variants.into_iter().map(|id| From::from(id)).collect(),
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }
@ -238,6 +240,7 @@ fn from(data: TupleVariantData) -> Def {
value: data.value, value: data.value,
children: vec![], children: vec![],
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }
@ -252,6 +255,7 @@ fn from(data: StructVariantData) -> Def {
value: data.value, value: data.value,
children: vec![], children: vec![],
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }
@ -266,6 +270,7 @@ fn from(data: StructData) -> Def {
value: data.value, value: data.value,
children: data.fields.into_iter().map(|id| From::from(id)).collect(), children: data.fields.into_iter().map(|id| From::from(id)).collect(),
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }
@ -280,6 +285,7 @@ fn from(data: TraitData) -> Def {
value: data.value, value: data.value,
children: data.items.into_iter().map(|id| From::from(id)).collect(), children: data.items.into_iter().map(|id| From::from(id)).collect(),
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }
@ -294,6 +300,7 @@ fn from(data: FunctionData) -> Def {
value: data.value, value: data.value,
children: vec![], children: vec![],
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }
@ -308,6 +315,7 @@ fn from(data: MethodData) -> Def {
value: data.value, value: data.value,
children: vec![], children: vec![],
decl_id: data.decl_id.map(|id| From::from(id)), decl_id: data.decl_id.map(|id| From::from(id)),
docs: data.docs,
} }
} }
} }
@ -322,6 +330,7 @@ fn from(data: MacroData) -> Def {
value: String::new(), value: String::new(),
children: vec![], children: vec![],
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }
@ -336,6 +345,7 @@ fn from(data:ModData) -> Def {
value: data.filename, value: data.filename,
children: data.items.into_iter().map(|id| From::from(id)).collect(), children: data.items.into_iter().map(|id| From::from(id)).collect(),
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }
@ -350,6 +360,7 @@ fn from(data: TypeDefData) -> Def {
value: data.value, value: data.value,
children: vec![], children: vec![],
decl_id: None, decl_id: None,
docs: String::new(),
} }
} }
} }
@ -369,6 +380,7 @@ fn from(data: VariableData) -> Def {
value: data.value, value: data.value,
children: vec![], children: vec![],
decl_id: None, decl_id: None,
docs: data.docs,
} }
} }
} }

View File

@ -29,6 +29,7 @@
extern crate serialize as rustc_serialize; extern crate serialize as rustc_serialize;
extern crate syntax_pos; extern crate syntax_pos;
mod csv_dumper; mod csv_dumper;
mod json_api_dumper; mod json_api_dumper;
mod json_dumper; mod json_dumper;
@ -50,8 +51,8 @@
use std::fs::{self, File}; use std::fs::{self, File};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use syntax::ast::{self, NodeId, PatKind}; use syntax::ast::{self, NodeId, PatKind, Attribute};
use syntax::parse::token::{self, keywords}; use syntax::parse::token::{self, keywords, InternedString};
use syntax::visit::{self, Visitor}; use syntax::visit::{self, Visitor};
use syntax::print::pprust::{ty_to_string, arg_to_string}; use syntax::print::pprust::{ty_to_string, arg_to_string};
use syntax::codemap::MacroAttribute; use syntax::codemap::MacroAttribute;
@ -142,6 +143,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
value: make_signature(decl, generics), value: make_signature(decl, generics),
visibility: From::from(&item.vis), visibility: From::from(&item.vis),
parent: None, parent: None,
docs: docs_for_attrs(&item.attrs),
})) }))
} }
ast::ItemKind::Static(ref typ, mt, ref expr) => { ast::ItemKind::Static(ref typ, mt, ref expr) => {
@ -168,6 +170,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
value: value, value: value,
type_value: ty_to_string(&typ), type_value: ty_to_string(&typ),
visibility: From::from(&item.vis), visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
})) }))
} }
ast::ItemKind::Const(ref typ, ref expr) => { ast::ItemKind::Const(ref typ, ref expr) => {
@ -185,6 +188,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
value: self.span_utils.snippet(expr.span), value: self.span_utils.snippet(expr.span),
type_value: ty_to_string(&typ), type_value: ty_to_string(&typ),
visibility: From::from(&item.vis), visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
})) }))
} }
ast::ItemKind::Mod(ref m) => { ast::ItemKind::Mod(ref m) => {
@ -204,6 +208,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
filename: filename, filename: filename,
items: m.items.iter().map(|i| i.id).collect(), items: m.items.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis), visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
})) }))
} }
ast::ItemKind::Enum(ref def, _) => { ast::ItemKind::Enum(ref def, _) => {
@ -225,6 +230,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
scope: self.enclosing_scope(item.id), scope: self.enclosing_scope(item.id),
variants: def.variants.iter().map(|v| v.node.data.id()).collect(), variants: def.variants.iter().map(|v| v.node.data.id()).collect(),
visibility: From::from(&item.vis), visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
})) }))
} }
ast::ItemKind::Impl(_, _, _, ref trait_ref, ref typ, _) => { ast::ItemKind::Impl(_, _, _, ref trait_ref, ref typ, _) => {
@ -291,6 +297,7 @@ pub fn get_field_data(&self, field: &ast::StructField,
value: "".to_owned(), value: "".to_owned(),
type_value: typ, type_value: typ,
visibility: From::from(&field.vis), visibility: From::from(&field.vis),
docs: docs_for_attrs(&field.attrs),
}) })
} else { } else {
None None
@ -303,7 +310,7 @@ pub fn get_method_data(&self, id: ast::NodeId,
name: ast::Name, span: Span) -> Option<FunctionData> { name: ast::Name, span: Span) -> Option<FunctionData> {
// The qualname for a method is the trait name or name of the struct in an impl in // The qualname for a method is the trait name or name of the struct in an impl in
// which the method is declared in, followed by the method's name. // which the method is declared in, followed by the method's name.
let (qualname, vis) = match self.tcx.impl_of_method(self.tcx.map.local_def_id(id)) { let (qualname, vis, docs) = match self.tcx.impl_of_method(self.tcx.map.local_def_id(id)) {
Some(impl_id) => match self.tcx.map.get_if_local(impl_id) { Some(impl_id) => match self.tcx.map.get_if_local(impl_id) {
Some(NodeItem(item)) => { Some(NodeItem(item)) => {
match item.node { match item.node {
@ -316,7 +323,7 @@ pub fn get_method_data(&self, id: ast::NodeId,
result.push_str(&self.tcx.item_path_str(def_id)); result.push_str(&self.tcx.item_path_str(def_id));
} }
result.push_str(">"); result.push_str(">");
(result, From::from(&item.vis)) (result, From::from(&item.vis), docs_for_attrs(&item.attrs))
} }
_ => { _ => {
span_bug!(span, span_bug!(span,
@ -338,7 +345,9 @@ pub fn get_method_data(&self, id: ast::NodeId,
Some(def_id) => { Some(def_id) => {
match self.tcx.map.get_if_local(def_id) { match self.tcx.map.get_if_local(def_id) {
Some(NodeItem(item)) => { Some(NodeItem(item)) => {
(format!("::{}", self.tcx.item_path_str(def_id)), From::from(&item.vis)) (format!("::{}", self.tcx.item_path_str(def_id)),
From::from(&item.vis),
docs_for_attrs(&item.attrs))
} }
r => { r => {
span_bug!(span, span_bug!(span,
@ -382,6 +391,7 @@ pub fn get_method_data(&self, id: ast::NodeId,
value: String::new(), value: String::new(),
visibility: vis, visibility: vis,
parent: Some(parent_scope), parent: Some(parent_scope),
docs: docs,
}) })
} }
@ -739,6 +749,23 @@ fn visit_pat(&mut self, p: &ast::Pat) {
} }
} }
fn docs_for_attrs(attrs: &[Attribute]) -> String {
let doc = InternedString::new("doc");
let mut result = String::new();
for attr in attrs {
if attr.name() == doc {
if let Some(ref val) = attr.value_str() {
result.push_str(val);
result.push('\n');
}
}
}
result
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum Format { pub enum Format {
Csv, Csv,