-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Doc alias improvements #71724
Doc alias improvements #71724
Conversation
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 |
61be7ed
to
70fcb74
Compare
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.
There are a few things we can do to simplify this. How about adding an aliases
field to IndexItem
to store the list of aliases for each item. Then the actual aliases map can be built inside build_index
after the paths and parents for each item have been fully calculated. Additionally we can add the aliases map to CrateData
so it will be included in search-index.js
allowing us to remove the aliases
field on Cache
and the seperate aliases.js
file.
82d2bb7
to
a293680
Compare
@ollie27 I don't know why I didn't think about putting aliases in the search index before, this is a brilliant idea! However, I don't like the idea to put the aliases into Anyway, I integrated your suggestions. Thanks a lot! |
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.
This is looking a lot better but there's still some issues to deal with. The main visible one is that the results should list items from the current crate before others.
4081845
to
b0c5e2c
Compare
Updated! |
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 |
b0c5e2c
to
2fded7c
Compare
Fixed tidy issue... |
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 |
2fded7c
to
1b84e80
Compare
And with this one I added the missing comma in the JS test (long day). |
src/librustdoc/html/render/cache.rs
Outdated
@@ -582,6 +553,12 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { | |||
parent_idx: None, | |||
search_type: get_index_search_type(&item), | |||
}); | |||
for alias in item.attrs.get_doc_aliases().into_iter() { |
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.
for alias in item.attrs.get_doc_aliases().into_iter() { | |
for alias in item.attrs.get_doc_aliases() { |
When I make a suggestion like this it applies to all instances not just the one I comment on. This is why we should be trying to avoid code duplication.
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.
Sorry...
|
||
for alias in item.attrs.get_doc_aliases().into_iter() { | ||
self.aliases | ||
.entry(alias.to_lowercase()) |
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 guess it's not a big issue for now. It does seem weird that aliases are treated differently to the other search results though.
Updated, the code is indeed much better! |
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.
The #[doc(alias)]
implementation is looking a lot better now, nice work.
Just one nit and with the commits squashed r=me.
9050eed
to
e553226
Compare
…terministic results * Update Javascript to take this change into account * Update CrateData::aliases field to take a reference instead (it allowed to remove a conversion loop)
e553226
to
e17ac66
Compare
I squashed a few commits but kept the big changes into their own commits if this is ok with you. |
cc @ollie27 |
There are still commits that makes changes that subsequent commits just revert. Feel free to r=me if you think it's too much work to clean up the commits or you don't want to squash into one commit. It's the end result that matters most after all. |
Well, for me it's important to keep one change per commit. It makes the git history easier to follow. Even more considering how much the tests impact here. I squashed commits in order to keep it clean so I'll r+ it like this. Thanks a lot for your great reviews! Once this PR is merged, I'll need to check what remains to be done so this feature can finally be stabilized. @bors: r+ |
📌 Commit e17ac66 has been approved by |
Erf... @bors: r- |
@bors: r=ollie27 |
📌 Commit e17ac66 has been approved by |
…ts, r=ollie27 Doc alias improvements After [this message](rust-lang#50146 (comment)), I realized that the **doc alias**. So this PR does the followings: * Align the alias discovery on items added into the search-index. It brings a few nice advantages: * Instead of cloning the data between the two (in rustdoc source code), we now have the search-index one and aliases which reference to the first one. So we go from one big map containing a lot of duplicated data to just integers... * In the front-end (main.js), I improved the code around aliases to allow them to go through the same transformation as other items when we show the search results. * Improve the search tester in order to perform multiple requests into one file (I think it's better in this case than having a file for each case considering how many there are...) * I also had to add the new function inside the tester (`handleAliases`) Once this PR is merged, I intend to finally stabilize this feature. r? @ollie27 cc @rust-lang/rustdoc
…ts, r=ollie27 Doc alias improvements After [this message](rust-lang#50146 (comment)), I realized that the **doc alias**. So this PR does the followings: * Align the alias discovery on items added into the search-index. It brings a few nice advantages: * Instead of cloning the data between the two (in rustdoc source code), we now have the search-index one and aliases which reference to the first one. So we go from one big map containing a lot of duplicated data to just integers... * In the front-end (main.js), I improved the code around aliases to allow them to go through the same transformation as other items when we show the search results. * Improve the search tester in order to perform multiple requests into one file (I think it's better in this case than having a file for each case considering how many there are...) * I also had to add the new function inside the tester (`handleAliases`) Once this PR is merged, I intend to finally stabilize this feature. r? @ollie27 cc @rust-lang/rustdoc
…ts, r=ollie27 Doc alias improvements After [this message](rust-lang#50146 (comment)), I realized that the **doc alias**. So this PR does the followings: * Align the alias discovery on items added into the search-index. It brings a few nice advantages: * Instead of cloning the data between the two (in rustdoc source code), we now have the search-index one and aliases which reference to the first one. So we go from one big map containing a lot of duplicated data to just integers... * In the front-end (main.js), I improved the code around aliases to allow them to go through the same transformation as other items when we show the search results. * Improve the search tester in order to perform multiple requests into one file (I think it's better in this case than having a file for each case considering how many there are...) * I also had to add the new function inside the tester (`handleAliases`) Once this PR is merged, I intend to finally stabilize this feature. r? @ollie27 cc @rust-lang/rustdoc
Rollup of 9 pull requests Successful merges: - rust-lang#71662 (Implement FromStr for OsString) - rust-lang#71677 (Add explicit references to the BuildHasher trait) - rust-lang#71724 (Doc alias improvements) - rust-lang#71948 (Suggest to await future before ? operator) - rust-lang#72090 (rustc_driver: factor out computing the exit code) - rust-lang#72206 (Cleanup stale 'FIXME(rust-lang#64197)') - rust-lang#72218 (make sure even unleashed miri does not do pointer stuff) - rust-lang#72220 ([const-prop] Don't replace Rvalues that are already constants) - rust-lang#72224 (doc: add links to rotate_(left|right)) Failed merges: r? @ghost
I agree but that's not what we have. Take for example cf41b1d which adds |
Oh, I completely overlooked it, sorry about this too... |
After this message, I realized that the doc alias. So this PR does the followings:
handleAliases
)Once this PR is merged, I intend to finally stabilize this feature.
r? @ollie27
cc @rust-lang/rustdoc