Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #90200

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4b3f82a
Add updated support for example-analyzer
willcrichton May 9, 2021
7831fee
Fix check issue
willcrichton May 30, 2021
2855bf0
Factor scraping and rendering into separate calls to rustdoc
willcrichton Jun 1, 2021
b6338e7
Generate example source files with corresponding links
willcrichton Jun 3, 2021
eea8f0a
Sort examples by size
willcrichton Aug 26, 2021
55bb517
Move highlighting logic from JS to Rust
willcrichton Aug 26, 2021
18edcf8
Reduce blur size, fix example width bug, add better error handling fo…
willcrichton Sep 14, 2021
a1cb194
Add styles for non-white themes
willcrichton Sep 14, 2021
829b1a9
Incorporate jyn's feedback
willcrichton Sep 17, 2021
5c05b3c
Add target crates as inputs to reduce size of intermediates
willcrichton Sep 20, 2021
df5e3a6
Change serialized format to use DefPathHash instead of custom String
willcrichton Sep 21, 2021
25323ec
Move JS into a standalone file
willcrichton Oct 1, 2021
55731bb
Fix lint error, change scrape-examples.js minify call
willcrichton Oct 1, 2021
ed8e12f
Unversioned -> InvocationSpecific
willcrichton Oct 1, 2021
5584c79
Update to latest rustc and rustdoc styles
willcrichton Oct 7, 2021
bb383ed
Move some expansion logic into generation-time, fix section header li…
willcrichton Oct 7, 2021
8b141a2
Add variance constraints for const params
voidc Oct 7, 2021
e22e858
Move more scrape-examples logic from JS to rust
willcrichton Oct 7, 2021
f10dcee
Change handling of spans in scrape examples, add test for highlight d…
willcrichton Oct 8, 2021
9e4958a
Add test for prev/back arrows + examples across multiple files
willcrichton Oct 9, 2021
b1616f3
Add test for ordering of examples, simplify with single scrape.mk file
willcrichton Oct 9, 2021
59b36bc
Add UI test for the variance of types appearing in consts
voidc Oct 12, 2021
a400f10
Bless tests
voidc Oct 12, 2021
24a71cb
Fix local crate not being scraped
willcrichton Oct 13, 2021
02e4d0b
Make all proc-macro back-compat lints deny-by-default
Aaron1011 Aug 15, 2021
a836676
Update the minimum external LLVM to 11
cuviper Oct 19, 2021
5a87d1a
llvm-dwp-11 fails on absolute paths
cuviper Oct 19, 2021
8f80d86
Small scrape-example fixes
willcrichton Oct 20, 2021
d1c29c6
Revert def_id addition from clean::Function, add test for
willcrichton Oct 22, 2021
fd5d614
Move def_id logic into render_call_locations
willcrichton Oct 22, 2021
e4aeeca
Reset qualifs when a storage of a local ends
tmiasko Oct 22, 2021
fd25491
Add caveat about changing parallelism and function call overhead
the8472 Oct 23, 2021
a7f2bc1
Rollup merge of #85833 - willcrichton:example-analyzer, r=jyn514
matthiaskrgr Oct 23, 2021
0c85cd4
Rollup merge of #88041 - Aaron1011:deny-proc-macro-hack, r=wesleywiser
matthiaskrgr Oct 23, 2021
809e5c8
Rollup merge of #89829 - voidc:assoc-const-variance, r=lcnr
matthiaskrgr Oct 23, 2021
684402e
Rollup merge of #90062 - cuviper:min-llvm-11, r=nikic
matthiaskrgr Oct 23, 2021
6584391
Rollup merge of #90168 - tmiasko:const-qualif-storage, r=matthewjasper
matthiaskrgr Oct 23, 2021
f99f296
Rollup merge of #90198 - the8472:available-parallelism-runtime, r=jos…
matthiaskrgr Oct 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move JS into a standalone file
  • Loading branch information
willcrichton committed Oct 7, 2021
commit 25323ec306b99adf6b5751c6f0a96eb373857336
2 changes: 2 additions & 0 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ crate struct Layout {
/// If false, the `select` element to have search filtering by crates on rendered docs
/// won't be generated.
crate generate_search_filter: bool,
/// If true, then scrape-examples.js will be included in the output HTML file
crate scrape_examples_extension: bool,
}

#[derive(Serialize)]
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
krate: krate.name.to_string(),
css_file_extension: extension_css,
generate_search_filter,
scrape_examples_extension: call_locations.len() > 0,
};
let mut issue_tracker_base_url = None;
let mut include_sources = true;
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ pub(super) fn write_shared(
)?;
}

if cx.shared.layout.scrape_examples_extension {
write_minify("scrape-examples.js", static_files::SCRAPE_EXAMPLES_JS, cx, options)?;
}

if let Some(ref css) = cx.shared.layout.css_file_extension {
let buffer = try_err!(fs::read_to_string(css), css);
// This varies based on the invocation, so it can't go through the write_minify wrapper.
Expand Down
115 changes: 0 additions & 115 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,121 +979,6 @@ function hideThemeButtonState() {
onHashChange(null);
window.addEventListener("hashchange", onHashChange);
searchState.setup();

/////// --scrape-examples interactions

// Scroll code block to put the given code location in the middle of the viewer
function scrollToLoc(elt, loc) {
var wrapper = elt.querySelector(".code-wrapper");
var halfHeight = wrapper.offsetHeight / 2;
var lines = elt.querySelector('.line-numbers');
var offsetMid = (lines.children[loc[0]].offsetTop
+ lines.children[loc[1]].offsetTop) / 2;
var scrollOffset = offsetMid - halfHeight;
lines.scrollTo(0, scrollOffset);
elt.querySelector(".rust").scrollTo(0, scrollOffset);
}

function updateScrapedExample(example) {
var locs = JSON.parse(example.attributes.getNamedItem("data-locs").textContent);
var offset = parseInt(example.attributes.getNamedItem("data-offset").textContent);

var locIndex = 0;
var highlights = example.querySelectorAll('.highlight');
var link = example.querySelector('.scraped-example-title a');
addClass(highlights[0], 'focus');
if (locs.length > 1) {
// Toggle through list of examples in a given file
var onChangeLoc = function(f) {
removeClass(highlights[locIndex], 'focus');
f();
scrollToLoc(example, locs[locIndex]);
addClass(highlights[locIndex], 'focus');

var curLoc = locs[locIndex];
var minLine = curLoc[0] + offset + 1;
var maxLine = curLoc[1] + offset + 1;

var text;
var anchor;
if (minLine == maxLine) {
text = 'line ' + minLine.toString();
anchor = minLine.toString();
} else {
var range = minLine.toString() + '-' + maxLine.toString();
text = 'lines ' + range;
anchor = range;
}

var url = new URL(link.href);
url.hash = anchor;

link.href = url.toString();
link.innerHTML = text;
};

example.querySelector('.prev')
.addEventListener('click', function() {
onChangeLoc(function() {
locIndex = (locIndex - 1 + locs.length) % locs.length;
});
});

example.querySelector('.next')
.addEventListener('click', function() {
onChangeLoc(function() { locIndex = (locIndex + 1) % locs.length; });
});
} else {
// Remove buttons if there's only one example in the file
example.querySelector('.prev').remove();
example.querySelector('.next').remove();
}

var codeEl = example.querySelector('.rust');
var codeOverflows = codeEl.scrollHeight > codeEl.clientHeight;
var expandButton = example.querySelector('.expand');
if (codeOverflows) {
// If file is larger than default height, give option to expand the viewer
expandButton.addEventListener('click', function () {
if (hasClass(example, "expanded")) {
removeClass(example, "expanded");
scrollToLoc(example, locs[0]);
} else {
addClass(example, "expanded");
}
});
} else {
// Otherwise remove expansion buttons
addClass(example, 'expanded');
expandButton.remove();
}

// Start with the first example in view
scrollToLoc(example, locs[0]);
}

function updateScrapedExamples() {
var firstExamples = document.querySelectorAll('.scraped-example-list > .scraped-example');
onEach(firstExamples, updateScrapedExample);
onEach(document.querySelectorAll('.more-examples-toggle'), function(toggle) {
// Allow users to click the left border of the <details> section to close it,
// since the section can be large and finding the [+] button is annoying.
toggle.querySelector('.toggle-line').addEventListener('click', function() {
toggle.open = false;
});

var moreExamples = toggle.querySelectorAll('.scraped-example');
toggle.querySelector('summary').addEventListener('click', function() {
// Wrapping in setTimeout ensures the update happens after the elements are actually
// visible. This is necessary since updateScrapedExample calls scrollToLoc which
// depends on offsetHeight, a property that requires an element to be visible to
// compute correctly.
setTimeout(function() { onEach(moreExamples, updateScrapedExample); });
}, {once: true});
});
}

updateScrapedExamples();
}());

(function () {
Expand Down
110 changes: 110 additions & 0 deletions src/librustdoc/html/static/js/scrape-examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
(function () {
// Scroll code block to put the given code location in the middle of the viewer
function scrollToLoc(elt, loc) {
var wrapper = elt.querySelector(".code-wrapper");
var halfHeight = wrapper.offsetHeight / 2;
var lines = elt.querySelector('.line-numbers');
var offsetMid = (lines.children[loc[0]].offsetTop
+ lines.children[loc[1]].offsetTop) / 2;
var scrollOffset = offsetMid - halfHeight;
lines.scrollTo(0, scrollOffset);
elt.querySelector(".rust").scrollTo(0, scrollOffset);
}

function updateScrapedExample(example) {
var locs = JSON.parse(example.attributes.getNamedItem("data-locs").textContent);
var offset = parseInt(example.attributes.getNamedItem("data-offset").textContent);

var locIndex = 0;
var highlights = example.querySelectorAll('.highlight');
var link = example.querySelector('.scraped-example-title a');
addClass(highlights[0], 'focus');
if (locs.length > 1) {
// Toggle through list of examples in a given file
var onChangeLoc = function(f) {
removeClass(highlights[locIndex], 'focus');
f();
scrollToLoc(example, locs[locIndex]);
addClass(highlights[locIndex], 'focus');

var curLoc = locs[locIndex];
var minLine = curLoc[0] + offset + 1;
var maxLine = curLoc[1] + offset + 1;

var text;
var anchor;
if (minLine == maxLine) {
text = 'line ' + minLine.toString();
anchor = minLine.toString();
} else {
var range = minLine.toString() + '-' + maxLine.toString();
text = 'lines ' + range;
anchor = range;
}

var url = new URL(link.href);
url.hash = anchor;

link.href = url.toString();
link.innerHTML = text;
};

example.querySelector('.prev')
.addEventListener('click', function() {
onChangeLoc(function() {
locIndex = (locIndex - 1 + locs.length) % locs.length;
});
});

example.querySelector('.next')
.addEventListener('click', function() {
onChangeLoc(function() { locIndex = (locIndex + 1) % locs.length; });
});
} else {
// Remove buttons if there's only one example in the file
example.querySelector('.prev').remove();
example.querySelector('.next').remove();
}

var codeEl = example.querySelector('.rust');
var codeOverflows = codeEl.scrollHeight > codeEl.clientHeight;
var expandButton = example.querySelector('.expand');
if (codeOverflows) {
// If file is larger than default height, give option to expand the viewer
expandButton.addEventListener('click', function () {
if (hasClass(example, "expanded")) {
removeClass(example, "expanded");
scrollToLoc(example, locs[0]);
} else {
addClass(example, "expanded");
}
});
} else {
// Otherwise remove expansion buttons
addClass(example, 'expanded');
expandButton.remove();
}

// Start with the first example in view
scrollToLoc(example, locs[0]);
}

var firstExamples = document.querySelectorAll('.scraped-example-list > .scraped-example');
onEach(firstExamples, updateScrapedExample);
onEach(document.querySelectorAll('.more-examples-toggle'), function(toggle) {
// Allow users to click the left border of the <details> section to close it,
// since the section can be large and finding the [+] button is annoying.
toggle.querySelector('.toggle-line').addEventListener('click', function() {
toggle.open = false;
});

var moreExamples = toggle.querySelectorAll('.scraped-example');
toggle.querySelector('summary').addEventListener('click', function() {
// Wrapping in setTimeout ensures the update happens after the elements are actually
// visible. This is necessary since updateScrapedExample calls scrollToLoc which
// depends on offsetHeight, a property that requires an element to be visible to
// compute correctly.
setTimeout(function() { onEach(moreExamples, updateScrapedExample); });
}, {once: true});
});
})();
4 changes: 4 additions & 0 deletions src/librustdoc/html/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ crate static SETTINGS_JS: &str = include_str!("static/js/settings.js");
/// Storage, used to store documentation settings.
crate static STORAGE_JS: &str = include_str!("static/js/storage.js");

/// The file contents of `scraped-examples.js`, which contains functionality related to the
/// --scrape-examples flag that inserts automatically-found examples of usages of items.
crate static SCRAPE_EXAMPLES_JS: &str = include_str!("static/js/scrape-examples.js");

/// The file contents of `brush.svg`, the icon used for the theme-switch button.
crate static BRUSH_SVG: &[u8] = include_bytes!("static/images/brush.svg");

Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
data-search-js="{{static_root_path | safe}}search{{page.resource_suffix}}.js"> {#- -#}
</div>
<script src="{{static_root_path | safe}}main{{page.resource_suffix}}.js"></script> {#- -#}
{%- if layout.scrape_examples_extension -%}
<script src="{{static_root_path | safe}}scrape-examples{{page.resource_suffix}}.js"></script> {#- -#}
{%- endif -%}
{%- for script in page.static_extra_scripts -%}
<script src="{{static_root_path | safe}}{{script}}.js"></script> {#- -#}
{% endfor %}
Expand Down