auto merge of #14068 : alexcrichton/rust/rustdoc-xcrate-links, r=brson
This should improve the libcore experience quite a bit when looking at the libstd documentation.
This commit is contained in:
commit
e850316408
11 changed files with 155 additions and 140 deletions
|
@ -146,41 +146,28 @@ impl fmt::Show for clean::Path {
|
|||
|
||||
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
|
||||
/// rendering function with the necessary arguments for linking to a local path.
|
||||
fn resolved_path(w: &mut io::Writer, id: ast::NodeId, p: &clean::Path,
|
||||
fn resolved_path(w: &mut io::Writer, did: ast::DefId, p: &clean::Path,
|
||||
print_all: bool) -> fmt::Result {
|
||||
path(w, p, print_all,
|
||||
|_cache, loc| { Some("../".repeat(loc.len())) },
|
||||
|cache, loc| {
|
||||
if ast_util::is_local(did) {
|
||||
Some("../".repeat(loc.len()))
|
||||
} else {
|
||||
match *cache.extern_locations.get(&did.krate) {
|
||||
render::Remote(ref s) => Some(s.clone()),
|
||||
render::Local => Some("../".repeat(loc.len())),
|
||||
render::Unknown => None,
|
||||
}
|
||||
}
|
||||
},
|
||||
|cache| {
|
||||
match cache.paths.find(&id) {
|
||||
match cache.paths.find(&did) {
|
||||
None => None,
|
||||
Some(&(ref fqp, shortty)) => Some((fqp.clone(), shortty))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Used when rendering an `ExternalPath` structure. Like `resolved_path` this
|
||||
/// will invoke `path` with proper linking-style arguments.
|
||||
fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool,
|
||||
fqn: &[~str], kind: clean::TypeKind,
|
||||
krate: ast::CrateNum) -> fmt::Result {
|
||||
path(w, p, print_all,
|
||||
|cache, loc| {
|
||||
match *cache.extern_locations.get(&krate) {
|
||||
render::Remote(ref s) => Some(s.clone()),
|
||||
render::Local => Some("../".repeat(loc.len())),
|
||||
render::Unknown => None,
|
||||
}
|
||||
},
|
||||
|_cache| {
|
||||
Some((Vec::from_slice(fqn), match kind {
|
||||
clean::TypeStruct => item_type::Struct,
|
||||
clean::TypeEnum => item_type::Enum,
|
||||
clean::TypeFunction => item_type::Function,
|
||||
clean::TypeTrait => item_type::Trait,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
||||
root: |&render::Cache, &[~str]| -> Option<~str>,
|
||||
info: |&render::Cache| -> Option<(Vec<~str> , ItemType)>)
|
||||
|
@ -298,15 +285,9 @@ impl fmt::Show for clean::Type {
|
|||
let m = cache_key.get().unwrap();
|
||||
f.buf.write(m.typarams.get(&id).as_bytes())
|
||||
}
|
||||
clean::ResolvedPath{id, typarams: ref tp, path: ref path} => {
|
||||
try!(resolved_path(f.buf, id, path, false));
|
||||
tybounds(f.buf, tp)
|
||||
}
|
||||
clean::ExternalPath{path: ref path, typarams: ref tp,
|
||||
fqn: ref fqn, kind, krate} => {
|
||||
try!(external_path(f.buf, path, false, fqn.as_slice(), kind,
|
||||
krate))
|
||||
tybounds(f.buf, tp)
|
||||
clean::ResolvedPath{ did, ref typarams, ref path} => {
|
||||
try!(resolved_path(f.buf, did, path, false));
|
||||
tybounds(f.buf, typarams)
|
||||
}
|
||||
clean::Self(..) => f.buf.write("Self".as_bytes()),
|
||||
clean::Primitive(prim) => {
|
||||
|
@ -543,10 +524,7 @@ impl fmt::Show for clean::ViewPath {
|
|||
impl fmt::Show for clean::ImportSource {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.did {
|
||||
// FIXME: shouldn't be restricted to just local imports
|
||||
Some(did) if ast_util::is_local(did) => {
|
||||
resolved_path(f.buf, did.node, &self.path, true)
|
||||
}
|
||||
Some(did) => resolved_path(f.buf, did, &self.path, true),
|
||||
_ => {
|
||||
for (i, seg) in self.path.segments.iter().enumerate() {
|
||||
if i > 0 {
|
||||
|
@ -563,8 +541,7 @@ impl fmt::Show for clean::ImportSource {
|
|||
impl fmt::Show for clean::ViewListIdent {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.source {
|
||||
// FIXME: shouldn't be limited to just local imports
|
||||
Some(did) if ast_util::is_local(did) => {
|
||||
Some(did) => {
|
||||
let path = clean::Path {
|
||||
global: false,
|
||||
segments: vec!(clean::PathSegment {
|
||||
|
@ -573,7 +550,7 @@ impl fmt::Show for clean::ViewListIdent {
|
|||
types: Vec::new(),
|
||||
})
|
||||
};
|
||||
resolved_path(f.buf, did.node, &path, false)
|
||||
resolved_path(f.buf, did, &path, false)
|
||||
}
|
||||
_ => write!(f.buf, "{}", self.name),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue