Skip to content

Commit df064eb

Browse files
committed
---
yaml --- r: 152024 b: refs/heads/try2 c: 8dad7f5 h: refs/heads/master v: v3
1 parent 82d1b91 commit df064eb

File tree

4 files changed

+97
-33
lines changed

4 files changed

+97
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 9f13db2cb2edfd626006bd86e01351a8b1c23401
8+
refs/heads/try2: 8dad7f579e029fd883d64848f4abb12630dcc3e6
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustdoc/clean.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,28 +1575,40 @@ fn try_inline(id: ast::NodeId) -> Option<Vec<Item>> {
15751575
};
15761576
let did = ast_util::def_id_of_def(def);
15771577
if ast_util::is_local(did) { return None }
1578-
try_inline_def(tcx, def)
1578+
try_inline_def(&**cx, tcx, def)
15791579
}
15801580

1581-
fn try_inline_def(tcx: &ty::ctxt, def: ast::Def) -> Option<Vec<Item>> {
1581+
fn try_inline_def(cx: &core::DocContext,
1582+
tcx: &ty::ctxt,
1583+
def: ast::Def) -> Option<Vec<Item>> {
15821584
let mut ret = Vec::new();
15831585
let did = ast_util::def_id_of_def(def);
15841586
let inner = match def {
1585-
ast::DefTrait(did) => TraitItem(build_external_trait(tcx, did)),
1586-
ast::DefFn(did, style) =>
1587-
FunctionItem(build_external_function(tcx, did, style)),
1587+
ast::DefTrait(did) => {
1588+
record_extern_fqn(cx, did, TypeTrait);
1589+
TraitItem(build_external_trait(tcx, did))
1590+
}
1591+
ast::DefFn(did, style) => {
1592+
record_extern_fqn(cx, did, TypeFunction);
1593+
FunctionItem(build_external_function(tcx, did, style))
1594+
}
15881595
ast::DefStruct(did) => {
1596+
record_extern_fqn(cx, did, TypeStruct);
15891597
ret.extend(build_impls(tcx, did).move_iter());
15901598
StructItem(build_struct(tcx, did))
15911599
}
15921600
ast::DefTy(did) => {
1601+
record_extern_fqn(cx, did, TypeEnum);
15931602
ret.extend(build_impls(tcx, did).move_iter());
15941603
build_type(tcx, did)
15951604
}
15961605
// Assume that the enum type is reexported next to the variant, and
15971606
// variants don't show up in documentation specially.
15981607
ast::DefVariant(..) => return Some(Vec::new()),
1599-
ast::DefMod(did) => ModuleItem(build_module(tcx, did)),
1608+
ast::DefMod(did) => {
1609+
record_extern_fqn(cx, did, TypeModule);
1610+
ModuleItem(build_module(cx, tcx, did))
1611+
}
16001612
_ => return None,
16011613
};
16021614
let fqn = csearch::get_item_path(tcx, did);
@@ -1838,10 +1850,7 @@ fn register_def(cx: &core::DocContext, def: ast::Def) -> ast::DefId {
18381850
core::Typed(ref t) => t,
18391851
core::NotTyped(_) => return did
18401852
};
1841-
let fqn = csearch::get_item_path(tcx, did);
1842-
let fqn = fqn.move_iter().map(|i| i.to_str().to_strbuf()).collect();
1843-
debug!("recording {} => {}", did, fqn);
1844-
cx.external_paths.borrow_mut().get_mut_ref().insert(did, (fqn, kind));
1853+
record_extern_fqn(cx, did, kind);
18451854
match kind {
18461855
TypeTrait => {
18471856
let t = build_external_trait(tcx, did);
@@ -1852,6 +1861,19 @@ fn register_def(cx: &core::DocContext, def: ast::Def) -> ast::DefId {
18521861
return did;
18531862
}
18541863

1864+
fn record_extern_fqn(cx: &core::DocContext,
1865+
did: ast::DefId,
1866+
kind: TypeKind) {
1867+
match cx.maybe_typed {
1868+
core::Typed(ref tcx) => {
1869+
let fqn = csearch::get_item_path(tcx, did);
1870+
let fqn = fqn.move_iter().map(|i| i.to_str().to_strbuf()).collect();
1871+
cx.external_paths.borrow_mut().get_mut_ref().insert(did, (fqn, kind));
1872+
}
1873+
core::NotTyped(..) => {}
1874+
}
1875+
}
1876+
18551877
fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> Trait {
18561878
let def = ty::lookup_trait_def(tcx, did);
18571879
let methods = ty::trait_methods(tcx, did);
@@ -2000,13 +2022,14 @@ fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> Item {
20002022
}
20012023
}
20022024

2003-
fn build_module(tcx: &ty::ctxt, did: ast::DefId) -> Module {
2025+
fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
2026+
did: ast::DefId) -> Module {
20042027
let mut items = Vec::new();
20052028

20062029
csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, _| {
20072030
match def {
20082031
decoder::DlDef(def) => {
2009-
match try_inline_def(tcx, def) {
2032+
match try_inline_def(cx, tcx, def) {
20102033
Some(i) => items.extend(i.move_iter()),
20112034
None => {}
20122035
}

branches/try2/src/librustdoc/html/render.rs

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ pub struct Cache {
141141
/// necessary.
142142
pub paths: HashMap<ast::DefId, (Vec<String>, ItemType)>,
143143

144+
/// Similar to `paths`, but only holds external paths. This is only used for
145+
/// generating explicit hyperlinks to other crates.
146+
pub external_paths: HashMap<ast::DefId, Vec<StrBuf>>,
147+
144148
/// This map contains information about all known traits of this crate.
145149
/// Implementations of a crate should inherit the documentation of the
146150
/// parent trait if no extra documentation is specified, and default methods
@@ -249,7 +253,8 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
249253
let analysis = ::analysiskey.get();
250254
let public_items = analysis.as_ref().map(|a| a.public_items.clone());
251255
let public_items = public_items.unwrap_or(NodeSet::new());
252-
let paths = analysis.as_ref().map(|a| {
256+
let paths: HashMap<ast::DefId, (Vec<StrBuf>, ItemType)> =
257+
analysis.as_ref().map(|a| {
253258
let paths = a.external_paths.borrow_mut().take_unwrap();
254259
paths.move_iter().map(|(k, (v, t))| {
255260
(k, (v, match t {
@@ -265,6 +270,8 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
265270
}).unwrap_or(HashMap::new());
266271
let mut cache = Cache {
267272
impls: HashMap::new(),
273+
external_paths: paths.iter().map(|(&k, &(ref v, _))| (k, v.clone()))
274+
.collect(),
268275
paths: paths,
269276
implementors: HashMap::new(),
270277
stack: Vec::new(),
@@ -496,13 +503,15 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
496503
seen: HashSet::new(),
497504
cx: &mut cx,
498505
};
506+
// skip all invalid spans
507+
folder.seen.insert("".to_strbuf());
499508
krate = folder.fold_crate(krate);
500509
}
501510

502511
for &(n, ref e) in krate.externs.iter() {
503512
cache.extern_locations.insert(n, extern_location(e, &cx.dst));
504513
let did = ast::DefId { krate: n, node: ast::CRATE_NODE_ID };
505-
cache.paths.insert(did, (Vec::new(), item_type::Module));
514+
cache.paths.insert(did, (vec![e.name.to_strbuf()], item_type::Module));
506515
}
507516

508517
// And finally render the whole crate's documentation
@@ -1032,23 +1041,38 @@ impl<'a> Item<'a> {
10321041
}
10331042
}
10341043

1035-
fn link(&self) -> String {
1036-
let mut path = Vec::new();
1037-
clean_srcpath(self.item.source.filename.as_bytes(), |component| {
1038-
path.push(component.to_owned());
1039-
});
1040-
let href = if self.item.source.loline == self.item.source.hiline {
1041-
format_strbuf!("{}", self.item.source.loline)
1044+
fn link(&self) -> Option<String> {
1045+
if ast_util::is_local(self.item.def_id) {
1046+
let mut path = Vec::new();
1047+
clean_srcpath(self.item.source.filename.as_bytes(), |component| {
1048+
path.push(component.to_owned());
1049+
});
1050+
let href = if self.item.source.loline == self.item.source.hiline {
1051+
format!("{}", self.item.source.loline)
1052+
} else {
1053+
format!("{}-{}",
1054+
self.item.source.loline,
1055+
self.item.source.hiline)
1056+
};
1057+
Some(format!("{root}src/{krate}/{path}.html\\#{href}",
1058+
root = self.cx.root_path,
1059+
krate = self.cx.layout.krate,
1060+
path = path.connect("/"),
1061+
href = href))
10421062
} else {
1043-
format_strbuf!("{}-{}",
1044-
self.item.source.loline,
1045-
self.item.source.hiline)
1046-
};
1047-
format_strbuf!("{root}src/{krate}/{path}.html\\#{href}",
1048-
root = self.cx.root_path,
1049-
krate = self.cx.layout.krate,
1050-
path = path.connect("/"),
1051-
href = href)
1063+
let cache = cache_key.get().unwrap();
1064+
let path = cache.external_paths.get(&self.item.def_id);
1065+
let root = match *cache.extern_locations.get(&self.item.def_id.krate) {
1066+
Remote(ref s) => s.to_strbuf(),
1067+
Local => format!("{}/..", self.cx.root_path),
1068+
Unknown => return None,
1069+
};
1070+
Some(format!("{root}/{path}/{file}?gotosrc={goto}",
1071+
root = root,
1072+
path = path.slice_to(path.len() - 1).connect("/"),
1073+
file = item_path(self.item),
1074+
goto = self.item.def_id.node))
1075+
}
10521076
}
10531077
}
10541078

@@ -1097,8 +1121,15 @@ impl<'a> fmt::Show for Item<'a> {
10971121

10981122
// Write `src` tag
10991123
if self.cx.include_sources {
1100-
try!(write!(fmt, "<a class='source' href='{}'>[src]</a>",
1101-
self.link()));
1124+
match self.link() {
1125+
Some(l) => {
1126+
try!(write!(fmt,
1127+
"<a class='source' id='src-{}' \
1128+
href='{}'>[src]</a>",
1129+
self.item.def_id.node, l));
1130+
}
1131+
None => {}
1132+
}
11021133
}
11031134
try!(write!(fmt, "</h1>\n"));
11041135

branches/try2/src/librustdoc/html/static/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,4 +675,14 @@
675675
if (window.pending_implementors) {
676676
window.register_implementors(window.pending_implementors);
677677
}
678+
679+
680+
var query = window.location.search.substring(1);
681+
var vars = query.split('&');
682+
for (var i = 0; i < vars.length; i++) {
683+
var pair = vars[i].split('=');
684+
if (pair[0] == 'gotosrc') {
685+
window.location = $('#src-' + pair[1]).attr('href');
686+
}
687+
}
678688
}());

0 commit comments

Comments
 (0)