Uh oh!
There was an error while loading. Please reload this page.
Use rustc_lexer for rustdoc syntax highlighting - #75775
Conversation
matklad
commented
Aug 21, 2020
This is not ready for review yet, but just to give a heads up |
Uh oh!
There was an error while loading. Please reload this page.
GuillaumeGomez
commented
Aug 21, 2020
It looks like a nice start after a quick read. Don't forget to put back tests. :p |
There was a problem hiding this comment.
This bit is now gone, and, for example, && will always produce two spans now. I wonder if that is important? We need a real parser to do this precisely, but an approximate gluing heuristic won't be hard to add, if we need that.
There was a problem hiding this comment.
For now it's fine, but please open an issue about it so it's not forgotten.
There was a problem hiding this comment.
Hmm, I wonder if this would fix rust-lang/docs.rs#484.
There was a problem hiding this comment.
Good question, that'd be nice!
There was a problem hiding this comment.
@matklad could you add a test/screenshot of how this highlights assert!(self.length < N && index <= self.length);?
There was a problem hiding this comment.
Added the test. There are two spans for <= and one span for && but they all are ops, so the end result looks fine.
On a meta note, I would be surprised if this doesn't regress some corner cases, but I think it should be fine to fix them as they come up, until we complete #75981.
There was a problem hiding this comment.
Looks great, thanks!
On a meta note, I would be surprised if this doesn't regress some corner cases, but I think it should be fine to fix them as they come up, until we complete #75981.
I agree, and I don't expect this to be any more broken than the existing code.
matklad
commented
Aug 21, 2020
@GuillaumeGomez that particular test is deliberately removed, see the commit message in b48b66c. I do plan to add more unit-tests here, using #75773 |
ab1987c to
1d083ceCompareUh oh!
There was an error while loading. Please reload this page.
3788b43 to
63f6533Compare63f6533 to
957511eComparematklad
commented
Aug 27, 2020
This is ready for review @GuillaumeGomez ! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
5f18bab to
f54359dComparematklad
commented
Aug 27, 2020
Moved the tests, will open the issue about more precise highlighting shortly |
GuillaumeGomez
commented
Aug 27, 2020
Looks good to me now! However, considering this is a big PR, I'd like to have another reviewer from @rust-lang/rustdoc to check if I didn't miss anything. :) |
jyn514
left a comment
There was a problem hiding this comment.
Can you post a screenshot of what the sample file looks like when highlighted?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
f54359d to
22f709fCompare22f709f to
fe9d84dComparematklad
commented
Aug 27, 2020
@jyn514 thanks for the review, comments addressed (unless I've missed something)! Filed #75981 for further improvements. FYI, here's the html bit of rust-analyzer's syntax highlighting. Here the bulk of actual highlighting. Screenshot it #75775 (comment) |
jyn514
commented
Aug 27, 2020
Looks great, thanks! |
Uh oh!
There was an error while loading. Please reload this page.
| } | ||
| #[test] | ||
| fn test_html_highlighting() { |
There was a problem hiding this comment.
It doesn't make sense to put this test here. Syntax highlighting doesn't have anything to do with running doctests which is what this file is a submodule of. I suggest keeping these tests in src/librustdoc/html/highlight/tests.rs.
There was a problem hiding this comment.
I disagree with you for the location, however I think those tests should be put into a file on their own (like test/highlight.rs).
rustc_lexer is the lossless lexer, which is a better fit for approximate syntax highlighting. As a side-effect, we can now syntax-highlight even broken code.
fe9d84d to
21c4bd9CompareUh oh!
There was an error while loading. Please reload this page.
21c4bd9 to
0b16ff3Comparematklad
commented
Aug 27, 2020
Move tests back to where they originally were, and submitted #75989 to not be confused with this next time. |
It's a unit-test in a sense that it only checks syntax highlighting. However, the resulting HTML is written to disk and can be easily inspected in the browser. To update the test, run with `--bless` argument or set `UPDATE_EXPEC=1` env var
0b16ff3 to
b4f4db9CompareGuillaumeGomez
commented
Aug 29, 2020
Thanks! @bors: r+ |
bors
commented
Aug 29, 2020
📌 Commit b4f4db9 has been approved by |
bors
commented
Aug 29, 2020
bors
commented
Aug 30, 2020
☀️ Test successful - checks-actions, checks-azure |

r? @ghost