Change handling of spans in scrape examples, add test for highlight decorations
This commit is contained in:
parent
e22e858687
commit
f10dceeae2
2
src/librustdoc/html/highlight/fixtures/decorations.html
Normal file
2
src/librustdoc/html/highlight/fixtures/decorations.html
Normal file
@ -0,0 +1,2 @@
|
||||
<span class="example"><span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1</span>;</span>
|
||||
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="number">2</span>;
|
@ -1,6 +1,7 @@
|
||||
use super::write_code;
|
||||
use super::{write_code, DecorationInfo};
|
||||
use crate::html::format::Buffer;
|
||||
use expect_test::expect_file;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_span::create_default_session_globals_then;
|
||||
use rustc_span::edition::Edition;
|
||||
|
||||
@ -64,3 +65,17 @@ fn test_union_highlighting() {
|
||||
expect_file!["fixtures/union.html"].assert_eq(&html.into_inner());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decorations() {
|
||||
create_default_session_globals_then(|| {
|
||||
let src = "let x = 1;
|
||||
let y = 2;";
|
||||
let mut decorations = FxHashMap::default();
|
||||
decorations.insert("example", vec![(0, 10)]);
|
||||
|
||||
let mut html = Buffer::new();
|
||||
write_code(&mut html, src, Edition::Edition2018, None, Some(DecorationInfo(decorations)));
|
||||
expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner());
|
||||
});
|
||||
}
|
||||
|
@ -149,9 +149,11 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
// We need to get the file the example originates in. If the call is contained
|
||||
// in a macro, then trace the span back to the macro source (rather than macro definition).
|
||||
let span = span.source_callsite();
|
||||
// If this span comes from a macro expansion, then the source code may not actually show
|
||||
// a use of the given item, so it would be a poor example. Hence, we skip all uses in macros.
|
||||
if span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Save call site if the function resolves to a concrete definition
|
||||
if let ty::FnDef(def_id, _) = ty.kind() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user