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

Rustdoc improvements #50259

Merged
merged 9 commits into from
May 15, 2018
Merged

Rustdoc improvements #50259

merged 9 commits into from
May 15, 2018

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Apr 26, 2018

Fixes #50658. (last commit)

A lot of small improvements.

r? @QuietMisdreavus

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2018
@QuietMisdreavus
Copy link
Member

It looks like this includes the commit from #50229. Does this require it to be merged first?

@GuillaumeGomez
Copy link
Member Author

Oh sorry, forgot to precise: this PR depends on #50229.

@GuillaumeGomez
Copy link
Member Author

Rebased.

@QuietMisdreavus
Copy link
Member

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.

@GuillaumeGomez
Copy link
Member Author

Sure:

  • first commit: avoid results duplicates when performing multiple queries at once
  • second commit: improve alias rendering (so users can easily see that it's not a "normal" result)
  • third commit: add description in aliases results (I noticed it wasn't there so I added it back)
  • fourth commit: now, the focus/blur on the themes switch buttons is way better (when clicking outside, the menu closes itself, etc...)

Copy link
Member

@QuietMisdreavus QuietMisdreavus left a 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.

}

function pathSplitter(path) {
return '<span>' + path.replace(/::/g, '::</span><span>');
Copy link
Member

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?

Copy link
Member Author

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 = {};
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented May 5, 2018

My last commit reduces the size of aliases.js and search-index.js (for the second we go from 3458462 to 2993110).

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:start:test_rustdoc
Check compiletest suite=rustdoc mode=rustdoc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:08:20] 
[01:08:20] running 231 tests
[01:09:37] ...F...............i.....................................................F..........................
[01:10:22] .........i...........................................................F.........................F....
[01:10:31] failures:
[01:10:31] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:489:22
[01:10:31] 
[01:10:31] ---- [rustdoc] rustdoc/assoc-consts.rs stdout ----
[01:10:31] ---- [rustdoc] rustdoc/assoc-consts.rs stdout ----
[01:10:31]  
[01:10:31] error: htmldocck failed!
[01:10:31] status: exit code: 1
[01:10:31] command: "/usr/bin/python2.7" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/assoc-consts.stage2-x86_64-unknown-linux-gnu" "/checkout/src/test/rustdoc/assoc-consts.rs"
[01:10:31] ------------------------------------------
[01:10:31] 
[01:10:31] ------------------------------------------
[01:10:31] stderr:
[01:10:31] stderr:
[01:10:31] ------------------------------------------
[01:10:31] 114: @has check failed
[01:10:31]  `XPATH PATTERN` did not match
[01:10:31]      // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT0 in trait."
[01:10:31] 123: @has check failed
[01:10:31]  `XPATH PATTERN` did not match
[01:10:31]      // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait."
[01:10:31] Encountered 2 errors
[01:10:31] 
[01:10:31] ------------------------------------------
[01:10:31] 
[01:10:31] 
[01:10:31] thread '[rustdoc] rustdoc/assoc-consts.rs' panicked at 'explicit panic', tools/co01:10:31] thread '[rustdoc] rustdoc/issue-12834.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3001:9
[01:10:31] ---- [rustdoc] rustdoc/manual_impl.rs stdout ----
[01:10:31]  
[01:10:31]  
[01:10:31] error: htmldocck failed!
[01:10:31] status: exit code: 1
[01:10:31] command: "/usr/bin/python2.7" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/manual_impl.stage2-x86_64-unknown-linux-gnu" "/checkout/src/test/rustdoc/manual_impl.rs"
[01:10:31] ------------------------------------------
[01:10:31] 
[01:10:31] ------------------------------------------
[01:10:31] stderr:
[01:10:31] stderr:
[01:10:31] ------------------------------------------
[01:10:31] 37: @has check failed
[01:10:31]  `XPATH PATTERN` did not match
[01:10:31]  // @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
[01:10:31] 38: @has check failed
[01:10:31]  `XPATH PATTERN` did not match
[01:10:31]  // @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
[01:10:31] 39: @has check failed
[01:10:31]  `XPATH PATTERN` did not match
[01:10:31]  // @has - '//*[@class="docblock"]' 'Docs associated with the trait c_method definition.'
[01:10:31] 58: @has check failed
[01:10:31]  `XPATH PATTERN` did not match
[01:10:31]  // @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
[01:10:31] 78: @has check failed
[01:10:31]  `XPATH PATTERN` did not match
[01:10:31]  // @has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
[01:10:31] Encountered 5 errors
[01:10:31] 
[01:10:31] ------------------------------------------
[01:10:31] 
[01:10:31] 
[01:10:31] thread '[rustdoc] rustdoc/manual_impl.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3001:9
[01:10:31] 
[01:10:31] ---- [rustdoc] rustdoc/search-index-summaries.rs stdout ----
[01:10:31]  
[01:10:31] error: htmldocck failed!
[01:10:31] status: exit code: 1
[01:10:31] command: "/usr/bin/python2.7" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/search-index-summaries.stage2-x86_64-unknown-linux-gnu" "/checkout/src/test/rustdoc/search-index-summaries.rs"
[01:10:31] ------------------------------------------
[01:10:31] 
[01:10:31] ------------------------------------------
[01:10:31] stderr:
[01:10:31] stderr:
[01:10:31] ------------------------------------------
[01:10:31] 13: @has check failed
[01:10:31]  `PATTERN` did not match
[01:10:31]  // @has 'search-index.js' 'Foo short link.'
[01:10:31] Encountered 1 errors
[01:10:31] 
[01:10:31] ------------------------------------------
[01:10:31] 
---
[01:10:31] test result: FAILED. 225 passed; 4 failed; 2 ignored; 0 measured; 0 filtered out
[01:10:31] 
[01:10:31] 
[01:10:31] 
[01:10:31] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--rustdoc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" "--src-base" "/checkout/src/test/rustdoc" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "rustdoc" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:10:31] 
[01:10:31] 
[01:10:31] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:10:31] Build completed unsuccessfully in 0:26:33
[01:10:31] Build completed unsuccessfully in 0:26:33
[01:10:31] make: *** [check] Error 1
[01:10:31] Makefile:58: recipe for target 'check' failed
travis_time:end:091031ca:start=15255363579409 find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
travis_time:end:0fc71328:start=1525540591226231257,finish=1525540591232662503,duration=6431246
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:09e61c96

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 @TimNN. (Feature Requests)

if (tmp.endsWith("<span>")) {
return tmp.slice(0, tmp.length - 6);
}
return tmp;
Copy link
Member

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?

Copy link
Member Author

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 = {};
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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...

Copy link
Member

@ollie27 ollie27 left a 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 = {};
Copy link
Member

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?

var href = res[1];
var displayPath = res[0];
if (item.is_alias !== true) {
var fullPath = item.displayPath + name;
Copy link
Member

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,
Copy link
Member

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.

Copy link
Member Author

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.

@QuietMisdreavus
Copy link
Member

@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.

@bors
Copy link
Contributor

bors commented May 13, 2018

✌️ @ollie27 can now approve this pull request

@ollie27
Copy link
Member

ollie27 commented May 14, 2018

Let's get this in.

@bors r+

@bors
Copy link
Contributor

bors commented May 14, 2018

📌 Commit f0db2cf has been approved by ollie27

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2018
@bors
Copy link
Contributor

bors commented May 15, 2018

⌛ Testing commit f0db2cf with merge d5ecf70...

bors added a commit that referenced this pull request May 15, 2018
Rustdoc improvements

Fixes #50658. (last commit)

A lot of small improvements.

r? @QuietMisdreavus
@bors
Copy link
Contributor

bors commented May 15, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: ollie27
Pushing d5ecf70 to master...

@bors bors merged commit f0db2cf into rust-lang:master May 15, 2018
@GuillaumeGomez GuillaumeGomez deleted the improve-results branch May 15, 2018 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants