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

Make html rendered by rustdoc allow searching non-English identifier / alias #126057

Merged
merged 7 commits into from
Jun 8, 2024

Conversation

Sunshine40
Copy link
Contributor

Fix alias search result showing undefined description.

Inspired by rust-lang/mdBook#2393 .

Not sure if it's worth it adding full-text search functionality to rustdoc rendered html.

…/ alias. Fix alias search result showing `undefined` description.
@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @fmease (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jun 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2024

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha

@rust-log-analyzer

This comment has been minimized.

@Sunshine40
Copy link
Contributor Author

Demo:

image

Corresponding code:

/// 这是一个加法函数
#[doc(alias = "加法")]
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

/// 这等效于 add 函数,但是用中文命名
pub fn 中文名称的加法API(left: usize, right: usize) -> usize {
    left + right
}

#[macro_export]
macro_rules! 中文命名的加法宏 {
    () => {};
}

/// 英文命名的加法宏
#[doc(alias = "加法")]
#[macro_export]
macro_rules! add {
    () => {};
}

@GuillaumeGomez
Copy link
Member

Seems like a very good start! Can you add tests in rustdoc-js to ensure we don't break it in the future please?

Also cc @notriddle

@Sunshine40
Copy link
Contributor Author

Can you add tests in rustdoc-js to ensure we don't break it in the future please?

Done.

@rust-log-analyzer

This comment has been minimized.

@Sunshine40
Copy link
Contributor Author

Sunshine40 commented Jun 6, 2024

I think you'll need to bump the EcmaScript version in the eslint configuration. It's currently set to 8, but if I'm understanding the Introduction correctly, it need bumped to 9.

I'd be happy to do that if dropping support for some legacy browser versions is acceptable (I must admit, I didn't think about browser compatibility at the beginning)

@notriddle
Copy link
Contributor

Here's where the browser support matrix is defined: https://rust-lang.github.io/rfcs/1985-tiered-browser-support.html.

At the present time, clicking the browserList link in the RFC gives out:

  • Chrome 124, 125
  • Firefox 126, 115
  • Safari 17.5

It also lists these two, but MDN doesn't have compat data for UC Browser, and they're both based on Blink so it probably doesn't matter.

  • Edge 125
  • UC Browser 15.5

According to MDN, Unicode property escapes are available in Chrome 64, Firefox 78, and Safari 11. It should be fine.

@rust-log-analyzer

This comment has been minimized.

@notriddle
Copy link
Contributor

Does anybody know why we have both of these? There's two spots where we're checking es versions.

es-check es8 ../src/librustdoc/html/static/js/*.js && \

@Sunshine40
Copy link
Contributor Author

Does anybody know why we have both of these? There's two spots where we're checking es versions.

Because ES-Check and ESLint are separate tools, and there's no out-of-the-box solution to make them share configurations?

@Sunshine40
Copy link
Contributor Author

Should I bump the EcmaScript version in these files as well?

/src/tools/rustdoc-js/.eslintrc.js
/src/tools/rustdoc-gui/.eslintrc.js

@notriddle
Copy link
Contributor

Probably a smart idea, yes.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jun 7, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member

Looks good to me, thanks a lot! Just letting @notriddle review to ensure I didn't miss something.

@notriddle
Copy link
Contributor

r? notriddle

@bors r+

This seems like a reasonable choice to me. It does change things so that if you just search for _ it gives a "not a valid identifier" error, while it used to actually search for names with underscores in them.

Not a big deal, since that's not a very useful query. We can fix it if it's actually a problem.

@bors
Copy link
Contributor

bors commented Jun 7, 2024

📌 Commit ceaa42b has been approved by notriddle

It is now in the queue for this repository.

@rustbot rustbot assigned notriddle and unassigned fmease Jun 7, 2024
@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 Jun 7, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 8, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#125951 (Stabilize `error_in_core`)
 - rust-lang#125998 (std::unix::fs::get_mode implementation for illumos/solaris.)
 - rust-lang#126057 (Make html rendered by rustdoc allow searching non-English identifier / alias)
 - rust-lang#126065 (mark binding undetermined if target name exist and not obtained)
 - rust-lang#126105 (Add debugging utils and comments to Fuchsia scripts)
 - rust-lang#126138 (Fix typo in docs for std::pin)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1f715eb into rust-lang:master Jun 8, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Jun 8, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 8, 2024
Rollup merge of rust-lang#126057 - Sunshine40:rustdoc-search-non-english, r=notriddle

Make html rendered by rustdoc allow searching non-English identifier / alias

Fix alias search result showing `undefined` description.

Inspired by rust-lang/mdBook#2393 .

Not sure if it's worth it adding full-text search functionality to rustdoc rendered html.
Oneirical pushed a commit to Oneirical/rust that referenced this pull request Jun 9, 2024
lcnr pushed a commit to lcnr/rust that referenced this pull request Jun 12, 2024
@cuviper cuviper modified the milestones: 1.80.0, 1.81.0 Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants