Skip to content

Conversation

@ltentrup
Copy link
Contributor

This commit adds a function that tries to determine the syntax highlighting class of NAME_REFs based on the usage.
It is used for highlighting injections (such as highlighting of doctests) as the semantic logic will most of the time result in unresolved references.
It also adds a color to unresolved references in HTML encoding.

Follow up of #4683.
Fixes #4809.


stack.push();
for mut h in analysis.highlight(tmp_file_id).unwrap() {
for mut h in analysis.highlight_injection(tmp_file_id).unwrap() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use super::highlight(&analysis.db, tmp_file_id, None, false) here to avoid adding a new method to Analysis.

Also, looking at this I now realize that there's a big problem with cancellation here... Basically, we can't cancel stuff while we are doing highlighting of the injection. Seems bad, long term.

We need some salsa-level magic to solve this in a nicer way...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative, wouldn't it be better to parse doc comments (maybe including markdown) directly when parsing the file? This would certainly remove a lot of complexity from the current injection logic (and the extraction part) and maybe one can simulate the steps from https://doc.rust-lang.org/rustdoc/documentation-tests.html in order to get a faithful semantic representation.

This commit adds a function that tries to determine the syntax highlighting class of NAME_REFs based on the usage.
It is used for highlighting injections (such as highlighting of doctests) as the semantic logic will most of the time result in unresolved references.
It also adds a color to unresolved references in HTML encoding.
@matklad
Copy link
Contributor

matklad commented Jun 16, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 16, 2020

@bors bors bot merged commit 4342b71 into rust-lang:master Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strange highlighting in rdoc

2 participants