-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[rustdoc] Add highlighting for comments in items declaration #117869
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
Merged
bors
merged 3 commits into
rust-lang:master
from
GuillaumeGomez:comment-highlighting-item-decl
Dec 3, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// This test checks that comments in item declarations are highlighted. | ||
go-to: "file://" + |DOC_PATH| + "/test_docs/private/enum.Enum.html" | ||
show-text: true | ||
|
||
define-function: ( | ||
"check-item-decl-comment", | ||
(theme, url, comment_color), | ||
block { | ||
go-to: |url| | ||
set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} | ||
reload: | ||
assert-css: (".item-decl .comment", {"color": |comment_color|}, ALL) | ||
} | ||
) | ||
|
||
define-function: ( | ||
"check-items-for-theme", | ||
(theme, comment_color), | ||
block { | ||
call-function: ("check-item-decl-comment", { | ||
"theme": |theme|, | ||
"url": "file://" + |DOC_PATH| + "/test_docs/private/enum.Enum.html", | ||
"comment_color": |comment_color|, | ||
}) | ||
call-function: ("check-item-decl-comment", { | ||
"theme": |theme|, | ||
"url": "file://" + |DOC_PATH| + "/test_docs/private/struct.Struct.html", | ||
"comment_color": |comment_color|, | ||
}) | ||
call-function: ("check-item-decl-comment", { | ||
"theme": |theme|, | ||
"url": "file://" + |DOC_PATH| + "/test_docs/private/struct.Tuple.html", | ||
"comment_color": |comment_color|, | ||
}) | ||
call-function: ("check-item-decl-comment", { | ||
"theme": |theme|, | ||
"url": "file://" + |DOC_PATH| + "/test_docs/private/union.Union.html", | ||
"comment_color": |comment_color|, | ||
}) | ||
call-function: ("check-item-decl-comment", { | ||
"theme": |theme|, | ||
"url": "file://" + |DOC_PATH| + "/proc_macro_test/macro.make_answer.html", | ||
"comment_color": |comment_color|, | ||
}) | ||
call-function: ("check-item-decl-comment", { | ||
"theme": |theme|, | ||
"url": "file://" + |DOC_PATH| + "/proc_macro_test/derive.HelperAttr.html", | ||
"comment_color": |comment_color|, | ||
}) | ||
} | ||
) | ||
|
||
call-function: ( | ||
"check-items-for-theme", | ||
{ | ||
"theme": "ayu", | ||
"comment_color": "#788797", | ||
} | ||
) | ||
call-function: ( | ||
"check-items-for-theme", | ||
{ | ||
"theme": "dark", | ||
"comment_color": "#8d8d8b", | ||
} | ||
) | ||
call-function: ( | ||
"check-items-for-theme", | ||
{ | ||
"theme": "light", | ||
"comment_color": "#8e908c", | ||
} | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This file is automatically @generated by Cargo. | ||
# It is not intended for manual editing. | ||
version = 3 | ||
|
||
[[package]] | ||
name = "proc_macro_test" | ||
version = "0.1.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "proc_macro_test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
path = "lib.rs" | ||
proc-macro = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro] | ||
pub fn make_answer(_item: TokenStream) -> TokenStream { | ||
"fn answer() -> u32 { 42 }".parse().unwrap() | ||
} | ||
|
||
#[proc_macro_derive(HelperAttr, attributes(helper))] | ||
pub fn derive_helper_attr(_item: TokenStream) -> TokenStream { | ||
TokenStream::new() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<pre class="rust item-decl"><code>pub struct Simd<T>(/* private fields */) | ||
<pre class="rust item-decl"><code>pub struct Simd<T>(<span class="comment">/* private fields */</span>) | ||
<span class="where">where | ||
T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre> | ||
T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<code>pub struct Alpha<A>(/* private fields */) | ||
<code>pub struct Alpha<A>(<span class="comment">/* private fields */</span>) | ||
<span class="where">where | ||
A: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<pre class="rust item-decl"><code>pub union Union<'a, B><div class="where">where | ||
B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</div>{ | ||
/* private fields */ | ||
<span class="comment">/* private fields */</span> | ||
}</code></pre> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<pre class="rust item-decl"><code>pub union Union2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>> + 'a> { | ||
/* private fields */ | ||
<span class="comment">/* private fields */</span> | ||
}</code></pre> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anybody know what's going on with trailing newlines here? This seems like something that should be fixable, though presumably it should go in a separate PR.