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

Next-generation syntax highlighting for rustdoc #75981

Open
matklad opened this issue Aug 27, 2020 · 5 comments
Open

Next-generation syntax highlighting for rustdoc #75981

matklad opened this issue Aug 27, 2020 · 5 comments
Labels
A-markdown-parsing Area: Markdown parsing for doc-comments C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@matklad
Copy link
Member

matklad commented Aug 27, 2020

At the moment, rustdoc uses only the lexer to do syntax highlighting (#75775). This has the benefits of simplicity & performance, and gets us 80% of the way quality wise, but it is not perfect. For example, lexer-based highlighting can't properly detect contextual keywords, glued/split operators, etc.

We can and probably should make this better, though this requires a lot of fundamental work on IDE-ification of the compiler

  • the simple thing we can do is to use better heuristic to glue token (Use rustc_lexer for rustdoc syntax highlighting #75775 (comment))
  • the next step is to use parser & syntax tree for highlighting. This probably should be done after parser library-ification (Form t-compiler/wg-parser-library compiler-team#338)
  • the final step is to overlay semantic info, so that references are colored the same way as the things they refer to (which includes "clicking on the name should open the name's definition" as a subtask). This is already available in rust-analyzer, but will take some time to percolate to rustdoc
@matklad matklad added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Aug 27, 2020
@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. labels Aug 27, 2020
@camelid
Copy link
Member

camelid commented Aug 30, 2020

What do you mean by this?

so that references are colored the same way as the things they refer to (which includes "clicking on the name should open the name's definition as a subtask")

@matklad
Copy link
Member Author

matklad commented Aug 30, 2020

image

Note how modules, macros, trait and enums all have different colors in imports

EDIT: ah, I misplaced the quote, the wording should be better now

@camelid
Copy link
Member

camelid commented Aug 30, 2020

Oh, that's cool!

@pickfire
Copy link
Contributor

And it would be cooler if those text are clickable.

@GuillaumeGomez
Copy link
Member

@pickfire: There is a work in progress for that (started in #84176). I need to write an RFC at some point so we can stabilize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-markdown-parsing Area: Markdown parsing for doc-comments C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants