Skip to content

Next-generation syntax highlighting for rustdoc #75981

Open
@matklad

Description

@matklad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-markdown-parsingArea: Markdown parsing for doc-commentsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions