-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Rustdoc improvements #50259
Rustdoc improvements #50259
Conversation
It looks like this includes the commit from #50229. Does this require it to be merged first? |
Oh sorry, forgot to precise: this PR depends on #50229. |
26380d3
to
7b6f80f
Compare
Rebased. |
This is a bit above my abstraction threshold for knowing what these are doing offhand. Can you give a quick description of your commits to say what they're supposed to be doing? Since there's no "Fixes (issue link)" i can't tell what you're trying to do here. |
Sure:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just have a couple clarifying questions.
src/librustdoc/html/static/main.js
Outdated
} | ||
|
||
function pathSplitter(path) { | ||
return '<span>' + path.replace(/::/g, '::</span><span>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a problem if this function opens a <span>
tag without closing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. It's an old bug in addition of that!
@@ -1362,19 +1381,23 @@ | |||
function mergeArrays(arrays) { | |||
var ret = []; | |||
var positions = []; | |||
var notDuplicates = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's with the split between duplicates
above and notDuplicates
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanation time! 😄
mergeArrays
is only used when we have multiple queries (for example: "str,[]"). The second one (the one using duplicates
) allows to remove more global duplicates and is called on every search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, but why the inversion? Why is one duplicates
and one notDuplicates
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no explanation for this... I didn't write the two functions at the same time so I wrote both without thinking to the other.
7b6f80f
to
ccc3562
Compare
My last commit reduces the size of |
593f9ae
to
a50b7e7
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
a50b7e7
to
27c83a1
Compare
if (tmp.endsWith("<span>")) { | ||
return tmp.slice(0, tmp.length - 6); | ||
} | ||
return tmp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about situations where the string doesn't end in <span>
? Doesn't that still have an unclosed span?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it always ends with ::
. This is on this string that we make the replacement.
function addTab(array, query, display) { | ||
var extraStyle = ''; | ||
if (display === false) { | ||
extraStyle = ' style="display: none;"'; | ||
} | ||
|
||
var output = ''; | ||
var duplicates = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When can duplicates occur? Do you have some examples of when this is needed? The shown
variable below is also trying to remove duplicates and I've tried to remove it in #50482 but if there are duplicates then we'll need to find a better way of dealing with them. addTab
definitely isn't the correct place to be removing duplicates because it means the search result count will be incorrect: https://doc.rust-lang.org/nightly/std/?search=is_nan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can occurs in case you have aliases. I need to fix the count then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this de-duplication happen inside execSearch
so it can be tested by rustdoc-js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I did this, it'd force the js to go through the array one more time. I'm not sure we'd want this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see tests for queries that could create duplicate results.
Do you plan to backport this PR to 1.27?
function addTab(array, query, display) { | ||
var extraStyle = ''; | ||
if (display === false) { | ||
extraStyle = ' style="display: none;"'; | ||
} | ||
|
||
var output = ''; | ||
var duplicates = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this de-duplication happen inside execSearch
so it can be tested by rustdoc-js
?
src/librustdoc/html/static/main.js
Outdated
var href = res[1]; | ||
var displayPath = res[0]; | ||
if (item.is_alias !== true) { | ||
var fullPath = item.displayPath + name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this use item.fullPath
?
format!("{{'crate':'{}','ty':{},'name':'{}','path':'{}'{}}}", | ||
krate, item.ty as usize, item.name, item.path, | ||
format!("{{'crate':'{}','ty':{},'name':'{}','desc':'{}','p':'{}'{}}}", | ||
krate, item.ty as usize, item.name, item.desc.replace("'", "\\'"), item.path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.replace("'", "\\'")
isn't how you escape strings for javascript. You need to use something like as_json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad surprise, quotes aren't escaped when using Json
object or json conversion functions so for now, it's the best solution.
7d7399f
to
f0db2cf
Compare
@bors delegate=ollie27 There’s enough going on here that i’m not too sure what each part is doing, especially since new things have been added into the PR since it’s been opened. On its face, it all seems fine, but i’m way less comfortable with Javascript than Rust, so i could be missing something. |
✌️ @ollie27 can now approve this pull request |
Let's get this in. @bors r+ |
📌 Commit f0db2cf has been approved by |
Rustdoc improvements Fixes #50658. (last commit) A lot of small improvements. r? @QuietMisdreavus
☀️ Test successful - status-appveyor, status-travis |
Fixes #50658. (last commit)
A lot of small improvements.
r? @QuietMisdreavus