field signatures
This commit is contained in:
parent
c53fa9a898
commit
eb27b5166e
6 changed files with 38 additions and 7 deletions
|
|
@ -387,6 +387,7 @@ pub struct VariableData {
|
|||
pub type_value: String,
|
||||
pub visibility: Visibility,
|
||||
pub docs: String,
|
||||
pub sig: Option<Signature>,
|
||||
}
|
||||
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
|
|
|
|||
|
|
@ -372,6 +372,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
|||
parent: None,
|
||||
visibility: Visibility::Inherited,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
}.lower(self.tcx));
|
||||
}
|
||||
}
|
||||
|
|
@ -587,6 +588,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
|||
parent: Some(parent_id),
|
||||
visibility: vis,
|
||||
docs: docs_for_attrs(attrs),
|
||||
sig: None,
|
||||
}.lower(self.tcx));
|
||||
}
|
||||
|
||||
|
|
@ -1072,6 +1074,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
|
|||
parent: None,
|
||||
visibility: Visibility::Inherited,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
}.lower(self.tcx));
|
||||
}
|
||||
}
|
||||
|
|
@ -1521,6 +1524,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
|
|||
parent: None,
|
||||
visibility: Visibility::Inherited,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
}.lower(self.tcx));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -658,6 +658,7 @@ pub struct VariableData {
|
|||
pub parent: Option<DefId>,
|
||||
pub visibility: Visibility,
|
||||
pub docs: String,
|
||||
pub sig: Option<Signature>,
|
||||
}
|
||||
|
||||
impl Lower for data::VariableData {
|
||||
|
|
@ -676,6 +677,7 @@ impl Lower for data::VariableData {
|
|||
parent: self.parent,
|
||||
visibility: self.visibility,
|
||||
docs: self.docs,
|
||||
sig: self.sig.map(|s| s.lower(tcx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -419,7 +419,7 @@ impl From<VariableData> for Option<Def> {
|
|||
parent: data.parent.map(|id| From::from(id)),
|
||||
decl_id: None,
|
||||
docs: data.docs,
|
||||
sig: None,
|
||||
sig: data.sig,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ impl From<MacroData> for Def {
|
|||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: data.docs,
|
||||
sig: None,
|
||||
sig: data.sig,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
type_value: ty_to_string(&typ),
|
||||
visibility: From::from(&item.vis),
|
||||
docs: docs_for_attrs(&item.attrs),
|
||||
sig: None,
|
||||
}))
|
||||
}
|
||||
ast::ItemKind::Const(ref typ, ref expr) => {
|
||||
|
|
@ -197,6 +198,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
type_value: ty_to_string(&typ),
|
||||
visibility: From::from(&item.vis),
|
||||
docs: docs_for_attrs(&item.attrs),
|
||||
sig: None,
|
||||
}))
|
||||
}
|
||||
ast::ItemKind::Mod(ref m) => {
|
||||
|
|
@ -287,18 +289,39 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_field_data(&self, field: &ast::StructField,
|
||||
scope: NodeId) -> Option<VariableData> {
|
||||
pub fn get_field_data(&self,
|
||||
field: &ast::StructField,
|
||||
scope: NodeId)
|
||||
-> Option<VariableData> {
|
||||
if let Some(ident) = field.ident {
|
||||
let name = ident.to_string();
|
||||
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
|
||||
let def_id = self.tcx.map.local_def_id(field.id);
|
||||
let typ = self.tcx.item_type(def_id).to_string();
|
||||
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
|
||||
filter!(self.span_utils, sub_span, field.span, None);
|
||||
let def_id = self.tcx.map.local_def_id(field.id);
|
||||
let typ = self.tcx.item_type(def_id).to_string();
|
||||
|
||||
let span = field.span;
|
||||
let text = self.span_utils.snippet(field.span);
|
||||
let ident_start = text.find(&name).unwrap();
|
||||
let ident_end = ident_start + name.len();
|
||||
// TODO refs
|
||||
let sig = Signature {
|
||||
span: span,
|
||||
text: text,
|
||||
ident_start: ident_start,
|
||||
ident_end: ident_end,
|
||||
defs: vec![SigElement {
|
||||
id: def_id,
|
||||
start: ident_start,
|
||||
end: ident_end,
|
||||
}],
|
||||
refs: vec![],
|
||||
};
|
||||
Some(VariableData {
|
||||
id: field.id,
|
||||
kind: VariableKind::Field,
|
||||
name: ident.to_string(),
|
||||
name: name,
|
||||
qualname: qualname,
|
||||
span: sub_span.unwrap(),
|
||||
scope: scope,
|
||||
|
|
@ -307,6 +330,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
type_value: typ,
|
||||
visibility: From::from(&field.vis),
|
||||
docs: docs_for_attrs(&field.attrs),
|
||||
sig: Some(sig),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue