Use the new signature stuff

And fix a couple of bugs
This commit is contained in:
Nick Cameron 2017-05-31 15:59:48 +12:00
parent 0058fdd110
commit a2a999f035
7 changed files with 95 additions and 211 deletions

View File

@ -18,7 +18,7 @@ use rustc::hir::def_id::{CrateNum, DefId};
use syntax::ast::{self, Attribute, NodeId};
use syntax_pos::Span;
use rls_data::ExternalCrateData;
use rls_data::{ExternalCrateData, Signature};
pub struct CrateData {
pub name: String,
@ -129,7 +129,7 @@ pub struct EnumData {
pub variants: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -165,7 +165,7 @@ pub struct FunctionData {
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -251,7 +251,7 @@ pub struct MethodData {
pub parent: Option<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -292,7 +292,7 @@ pub struct StructData {
pub fields: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -307,7 +307,7 @@ pub struct StructVariantData {
pub scope: NodeId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -322,7 +322,7 @@ pub struct TraitData {
pub items: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -337,7 +337,7 @@ pub struct TupleVariantData {
pub scope: NodeId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -419,28 +419,3 @@ pub struct VariableRefData {
pub scope: NodeId,
pub ref_id: DefId,
}
/// Encodes information about the signature of a definition. This should have
/// enough information to create a nice display about a definition without
/// access to the source code.
#[derive(Clone, Debug)]
pub struct Signature {
pub span: Span,
pub text: String,
// These identify the main identifier for the defintion as byte offsets into
// `text`. E.g., of `foo` in `pub fn foo(...)`
pub ident_start: usize,
pub ident_end: usize,
pub defs: Vec<SigElement>,
pub refs: Vec<SigElement>,
}
/// An element of a signature. `start` and `end` are byte offsets into the `text`
/// of the parent `Signature`.
#[derive(Clone, Debug)]
pub struct SigElement {
pub id: DefId,
pub start: usize,
pub end: usize,
}

View File

@ -48,12 +48,13 @@ use syntax::ptr::P;
use syntax::codemap::Spanned;
use syntax_pos::*;
use super::{escape, generated_code, SaveContext, PathCollector, docs_for_attrs};
use super::data::*;
use super::dump::Dump;
use super::external_data::{Lower, make_def_id};
use super::span_utils::SpanUtils;
use super::recorder;
use {escape, generated_code, SaveContext, PathCollector, docs_for_attrs};
use data::*;
use dump::Dump;
use external_data::{Lower, make_def_id};
use recorder;
use span_utils::SpanUtils;
use sig;
use rls_data::ExternalCrateData;
@ -646,7 +647,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
fields: fields,
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: self.save_ctxt.sig_base(item),
sig: sig::item_signature(item, &self.save_ctxt),
attributes: item.attrs.clone(),
}.lower(self.tcx));
}
@ -679,18 +680,6 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
qualname.push_str("::");
qualname.push_str(&name);
let text = self.span.signature_string_for_span(variant.span);
let ident_start = text.find(&name).unwrap();
let ident_end = ident_start + name.len();
let sig = Signature {
span: variant.span,
text: text,
ident_start: ident_start,
ident_end: ident_end,
defs: vec![],
refs: vec![],
};
match variant.node.data {
ast::VariantData::Struct(ref fields, _) => {
let sub_span = self.span.span_for_first_ident(variant.span);
@ -712,7 +701,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
scope: enum_data.scope,
parent: Some(make_def_id(item.id, &self.tcx.hir)),
docs: docs_for_attrs(&variant.node.attrs),
sig: sig,
// TODO
sig: None,
attributes: variant.node.attrs.clone(),
}.lower(self.tcx));
}
@ -739,7 +729,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
scope: enum_data.scope,
parent: Some(make_def_id(item.id, &self.tcx.hir)),
docs: docs_for_attrs(&variant.node.attrs),
sig: sig,
// TODO
sig: None,
attributes: variant.node.attrs.clone(),
}.lower(self.tcx));
}
@ -811,7 +802,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
items: methods.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: self.save_ctxt.sig_base(item),
sig: sig::item_signature(item, &self.save_ctxt),
attributes: item.attrs.clone(),
}.lower(self.tcx));
}
@ -1369,7 +1360,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
visibility: From::from(&item.vis),
parent: None,
docs: docs_for_attrs(&item.attrs),
sig: Some(self.save_ctxt.sig_base(item)),
sig: sig::item_signature(item, &self.save_ctxt),
attributes: item.attrs.clone(),
}.lower(self.tcx));
}

View File

@ -16,9 +16,9 @@ use syntax::codemap::CodeMap;
use syntax::print::pprust;
use syntax_pos::Span;
use data::{self, Visibility, SigElement};
use data::{self, Visibility};
use rls_data::{SpanData, CratePreludeData, Attribute};
use rls_data::{SpanData, CratePreludeData, Attribute, Signature};
use rls_span::{Column, Row};
// FIXME: this should be pub(crate), but the current snapshot doesn't allow it yet
@ -103,7 +103,7 @@ pub struct EnumData {
pub variants: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -121,7 +121,7 @@ impl Lower for data::EnumData {
variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -186,7 +186,7 @@ pub struct FunctionData {
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -205,7 +205,7 @@ impl Lower for data::FunctionData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -355,7 +355,7 @@ pub struct MethodData {
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -374,7 +374,7 @@ impl Lower for data::MethodData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -410,7 +410,7 @@ impl Lower for data::ModData {
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.map(|s| s.lower(tcx)),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -450,7 +450,7 @@ pub struct StructData {
pub fields: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -469,7 +469,7 @@ impl Lower for data::StructData {
fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -486,7 +486,7 @@ pub struct StructVariantData {
pub scope: DefId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -504,7 +504,7 @@ impl Lower for data::StructVariantData {
scope: make_def_id(self.scope, &tcx.hir),
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -521,7 +521,7 @@ pub struct TraitData {
pub items: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -539,7 +539,7 @@ impl Lower for data::TraitData {
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(),
visibility: self.visibility,
docs: self.docs,
sig: self.sig.lower(tcx),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -556,7 +556,7 @@ pub struct TupleVariantData {
pub scope: DefId,
pub parent: Option<DefId>,
pub docs: String,
pub sig: Signature,
pub sig: Option<Signature>,
pub attributes: Vec<Attribute>,
}
@ -574,7 +574,7 @@ impl Lower for data::TupleVariantData {
scope: make_def_id(self.scope, &tcx.hir),
parent: self.parent,
docs: self.docs,
sig: self.sig.lower(tcx),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -608,7 +608,7 @@ impl Lower for data::TypeDefData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
sig: self.sig.map(|s| s.lower(tcx)),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -718,7 +718,7 @@ impl Lower for data::VariableData {
parent: self.parent,
visibility: self.visibility,
docs: self.docs,
sig: self.sig.map(|s| s.lower(tcx)),
sig: self.sig,
attributes: self.attributes.lower(tcx),
}
}
@ -746,30 +746,3 @@ impl Lower for data::VariableRefData {
}
}
}
#[derive(Clone, Debug)]
pub struct Signature {
pub span: SpanData,
pub text: String,
// These identify the main identifier for the defintion as byte offsets into
// `text`. E.g., of `foo` in `pub fn foo(...)`
pub ident_start: usize,
pub ident_end: usize,
pub defs: Vec<SigElement>,
pub refs: Vec<SigElement>,
}
impl Lower for data::Signature {
type Target = Signature;
fn lower(self, tcx: TyCtxt) -> Signature {
Signature {
span: span_from_span(self.span, tcx.sess.codemap()),
text: self.text,
ident_start: self.ident_start,
ident_end: self.ident_end,
defs: self.defs,
refs: self.refs,
}
}
}

View File

@ -133,7 +133,7 @@ impl Into<Option<Def>> for EnumData {
children: self.variants.into_iter().map(|id| id_from_def_id(id)).collect(),
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: vec![],
}),
_ => None,
@ -154,7 +154,7 @@ impl Into<Option<Def>> for TupleVariantData {
children: vec![],
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: vec![],
})
}
@ -172,7 +172,7 @@ impl Into<Option<Def>> for StructVariantData {
children: vec![],
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: vec![],
})
}
@ -191,7 +191,7 @@ impl Into<Option<Def>> for StructData {
children: self.fields.into_iter().map(|id| id_from_def_id(id)).collect(),
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: vec![],
}),
_ => None,
@ -212,7 +212,7 @@ impl Into<Option<Def>> for TraitData {
parent: None,
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: vec![],
}),
_ => None,
@ -233,7 +233,7 @@ impl Into<Option<Def>> for FunctionData {
parent: self.parent.map(|id| id_from_def_id(id)),
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: vec![],
}),
_ => None,
@ -254,7 +254,7 @@ impl Into<Option<Def>> for MethodData {
parent: self.parent.map(|id| id_from_def_id(id)),
decl_id: self.decl_id.map(|id| id_from_def_id(id)),
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: vec![],
}),
_ => None,

View File

@ -14,12 +14,11 @@ use rustc::hir::def_id::DefId;
use rustc_serialize::json::as_json;
use rls_data::{self, Id, Analysis, Import, ImportKind, Def, DefKind, Ref, RefKind, MacroRef,
Relation, RelationKind, Signature, SigElement, CratePreludeData};
Relation, RelationKind, CratePreludeData};
use rls_span::{Column, Row};
use external_data;
use external_data::*;
use data::{self, VariableKind};
use data::VariableKind;
use dump::Dump;
pub struct JsonDumper<O: DumpOutput> {
@ -121,7 +120,7 @@ impl<'b, O: DumpOutput + 'b> Dump for JsonDumper<O> {
children: data.items.into_iter().map(|id| id_from_def_id(id)).collect(),
decl_id: None,
docs: data.docs,
sig: data.sig.map(|s| s.into()),
sig: data.sig,
attributes: data.attributes.into_iter().map(|a| a.into()).collect(),
};
if def.span.file_name.to_str().unwrap() != def.value {
@ -220,7 +219,7 @@ impl Into<Def> for EnumData {
children: self.variants.into_iter().map(|id| id_from_def_id(id)).collect(),
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: self.attributes,
}
}
@ -239,7 +238,7 @@ impl Into<Def> for TupleVariantData {
children: vec![],
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: self.attributes,
}
}
@ -257,7 +256,7 @@ impl Into<Def> for StructVariantData {
children: vec![],
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: self.attributes,
}
}
@ -275,7 +274,7 @@ impl Into<Def> for StructData {
children: self.fields.into_iter().map(|id| id_from_def_id(id)).collect(),
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: self.attributes,
}
}
@ -293,7 +292,7 @@ impl Into<Def> for TraitData {
children: self.items.into_iter().map(|id| id_from_def_id(id)).collect(),
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: self.attributes,
}
}
@ -311,7 +310,7 @@ impl Into<Def> for FunctionData {
children: vec![],
decl_id: None,
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: self.attributes,
}
}
@ -329,7 +328,7 @@ impl Into<Def> for MethodData {
children: vec![],
decl_id: self.decl_id.map(|id| id_from_def_id(id)),
docs: self.docs,
sig: Some(self.sig.into()),
sig: self.sig,
attributes: self.attributes,
}
}
@ -365,7 +364,7 @@ impl Into<Def> for TypeDefData {
children: vec![],
decl_id: None,
docs: String::new(),
sig: self.sig.map(|s| s.into()),
sig: self.sig,
attributes: self.attributes,
}
}
@ -480,23 +479,3 @@ impl Into<Relation> for InheritanceData {
}
}
}
impl Into<Signature> for external_data::Signature {
fn into(self) -> Signature {
Signature {
text: self.text,
defs: self.defs.into_iter().map(|s| s.into()).collect(),
refs: self.refs.into_iter().map(|s| s.into()).collect(),
}
}
}
impl Into<SigElement> for data::SigElement {
fn into(self) -> SigElement {
SigElement {
id: id_from_def_id(self.id),
start: self.start,
end: self.end,
}
}
}

View File

@ -141,7 +141,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
visibility: From::from(&item.vis),
parent: None,
docs: docs_for_attrs(&item.attrs),
sig: self.sig_base_extern(item),
// TODO
sig: None,
attributes: item.attrs.clone(),
}))
}
@ -161,7 +162,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
type_value: ty_to_string(ty),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: Some(self.sig_base_extern(item)),
// TODO
sig: None,
attributes: item.attrs.clone(),
}))
}
@ -187,7 +189,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
visibility: From::from(&item.vis),
parent: None,
docs: docs_for_attrs(&item.attrs),
sig: self.sig_base(item),
sig: sig::item_signature(item, self),
attributes: item.attrs.clone(),
}))
}
@ -216,7 +218,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: Some(self.sig_base(item)),
sig: sig::item_signature(item, self),
attributes: item.attrs.clone(),
}))
}
@ -236,7 +238,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: Some(self.sig_base(item)),
sig: sig::item_signature(item, self),
attributes: item.attrs.clone(),
}))
}
@ -259,7 +261,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
items: m.items.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: Some(self.sig_base(item)),
sig: sig::item_signature(item, self),
attributes: item.attrs.clone(),
}))
}
@ -283,7 +285,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
variants: def.variants.iter().map(|v| v.node.data.id()).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
sig: self.sig_base(item),
sig: sig::item_signature(item, self),
attributes: item.attrs.clone(),
}))
}
@ -347,18 +349,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let def_id = self.tcx.hir.local_def_id(field.id);
let typ = self.tcx.type_of(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();
let sig = Signature {
span: span,
text: text,
ident_start: ident_start,
ident_end: ident_end,
defs: vec![],
refs: vec![],
};
Some(VariableData {
id: field.id,
kind: VariableKind::Field,
@ -371,7 +361,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
type_value: typ,
visibility: From::from(&field.vis),
docs: docs_for_attrs(&field.attrs),
sig: Some(sig),
// TODO
sig: None,
attributes: field.attrs.clone(),
})
} else {
@ -460,22 +451,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let sub_span = self.span_utils.sub_span_after_keyword(span, keywords::Fn);
filter!(self.span_utils, sub_span, span, None);
let name = name.to_string();
let text = self.span_utils.signature_string_for_span(span);
let ident_start = text.find(&name).unwrap();
let ident_end = ident_start + name.len();
let sig = Signature {
span: span,
text: text,
ident_start: ident_start,
ident_end: ident_end,
defs: vec![],
refs: vec![],
};
Some(FunctionData {
id: id,
name: name,
name: name.to_string(),
qualname: qualname,
declaration: decl_id,
span: sub_span.unwrap(),
@ -485,7 +463,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
visibility: vis,
parent: parent_scope,
docs: docs,
sig: sig,
// TODO
sig: None,
attributes: attributes,
})
}
@ -787,36 +766,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
}
fn sig_base(&self, item: &ast::Item) -> Signature {
let text = self.span_utils.signature_string_for_span(item.span);
let name = item.ident.to_string();
let ident_start = text.find(&name).expect("Name not in signature?");
let ident_end = ident_start + name.len();
Signature {
span: Span { hi: item.span.lo + BytePos(text.len() as u32), ..item.span },
text: text,
ident_start: ident_start,
ident_end: ident_end,
defs: vec![],
refs: vec![],
}
}
fn sig_base_extern(&self, item: &ast::ForeignItem) -> Signature {
let text = self.span_utils.signature_string_for_span(item.span);
let name = item.ident.to_string();
let ident_start = text.find(&name).expect("Name not in signature?");
let ident_end = ident_start + name.len();
Signature {
span: Span { hi: item.span.lo + BytePos(text.len() as u32), ..item.span },
text: text,
ident_start: ident_start,
ident_end: ident_end,
defs: vec![],
refs: vec![],
}
}
#[inline]
pub fn enclosing_scope(&self, id: NodeId) -> NodeId {
self.tcx.hir.get_enclosing_scope(id).unwrap_or(CRATE_NODE_ID)

View File

@ -22,6 +22,10 @@ use syntax::ast::{self, NodeId};
use syntax::print::pprust;
pub fn item_signature(item: &ast::Item, scx: &SaveContext) -> Option<Signature> {
item.make(0, None, scx).ok()
}
// TODO dup from json_dumper
fn id_from_def_id(id: DefId) -> Id {
Id {
@ -246,8 +250,8 @@ impl Sig for ast::Item {
let name = self.ident.to_string();
let def = SigElement {
id: id_from_node_id(self.id, scx),
start: offset + 5,
end: offset + 5 + name.len(),
start: offset + text.len(),
end: offset + text.len() + name.len(),
};
text.push_str(&name);
let generics: Signature = generics.make(offset + text.len(), id, scx)?;
@ -336,7 +340,6 @@ impl Sig for ast::Item {
sig.text.push_str(" -> ");
let nested = t.make(offset + sig.text.len(), None, scx)?;
sig.text.push_str(&nested.text);
sig.text.push(',');
sig.defs.extend(nested.defs.into_iter());
sig.refs.extend(nested.refs.into_iter());
}
@ -473,10 +476,23 @@ impl Sig for ast::Item {
impl Sig for ast::Path {
fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext) -> Result {
// if generated_code(span) {
// return Err("Generated code");
// }
let def = scx.get_path_def(id.ok_or("Missing id for Path")?);
let id = id_from_def_id(def.def_id());
let (name, start, end) = match def {
Def::Label(..) |
Def::PrimTy(..) |
Def::SelfTy(..) |
Def::Err => {
return Ok(Signature {
text: pprust::path_to_string(self),
defs: vec![],
refs: vec![],
})
}
Def::AssociatedConst(..) |
Def::Variant(..) |
Def::VariantCtor(..) => {
@ -499,6 +515,7 @@ impl Sig for ast::Path {
}
};
let id = id_from_def_id(def.def_id());
Ok(Signature {
text: name,
defs: vec![],
@ -557,4 +574,4 @@ impl Sig for ast::Generics {
}
}
// TODO impl items, trait items
// TODO impl items, trait items, fields, extern items, enum variant