Add an option for the source code link generation

This commit is contained in:
Guillaume Gomez 2021-04-13 15:52:41 +02:00 committed by Guillaume Gomez
parent 023231a709
commit 2104bf27d4
4 changed files with 23 additions and 3 deletions

View File

@ -276,6 +276,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
crate show_type_layout: bool,
crate unstable_features: rustc_feature::UnstableFeatures,
crate emit: Vec<EmitType>,
/// If `true`, HTML source pages will generate links for items to their definition.
crate generate_link_to_definition: bool,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -655,6 +657,7 @@ fn println_condition(condition: Condition) {
let generate_redirect_map = matches.opt_present("generate-redirect-map");
let show_type_layout = matches.opt_present("show-type-layout");
let nocapture = matches.opt_present("nocapture");
let generate_link_to_definition = matches.opt_present("generate-link-to-definition");
let (lint_opts, describe_lints, lint_cap) =
get_cmd_lint_options(matches, error_format, &debugging_opts);
@ -721,6 +724,7 @@ fn println_condition(condition: Condition) {
crate_name.as_deref(),
),
emit,
generate_link_to_definition,
},
crate_name,
output_format,

View File

@ -396,6 +396,7 @@ fn init(
unstable_features,
generate_redirect_map,
show_type_layout,
generate_link_to_definition,
..
} = options;
@ -456,8 +457,13 @@ fn init(
}
}
let (mut krate, local_sources, matches) =
collect_spans_and_sources(tcx, krate, &src_root, include_sources);
let (mut krate, local_sources, matches) = collect_spans_and_sources(
tcx,
krate,
&src_root,
include_sources,
generate_link_to_definition,
);
let (sender, receiver) = channel();
let mut scx = SharedContext {

View File

@ -20,11 +20,14 @@
krate: clean::Crate,
src_root: &std::path::Path,
include_sources: bool,
generate_link_to_definition: bool,
) -> (clean::Crate, FxHashMap<std::path::PathBuf, String>, FxHashMap<(u32, u32), LinkFromSrc>) {
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
if include_sources {
intravisit::walk_crate(&mut visitor, tcx.hir().krate());
if generate_link_to_definition {
intravisit::walk_crate(&mut visitor, tcx.hir().krate());
}
let (krate, sources) = sources::collect_local_sources(tcx, src_root, krate);
(krate, sources, visitor.matches)
} else {

View File

@ -607,6 +607,13 @@ fn opts() -> Vec<RustcOptGroup> {
unstable("nocapture", |o| {
o.optflag("", "nocapture", "Don't capture stdout and stderr of tests")
}),
unstable("generate-link-to-definition", |o| {
o.optflag(
"",
"generate-link-to-definition",
"Make the identifiers in the HTML source code pages navigable",
)
}),
]
}