Skip to content

Commit 50dad50

Browse files
bors[bot]ltentrup
andauthored
Merge #4959
4959: Syntax highlighting for documentation comments on macro definitions r=matklad a=ltentrup Two minor changes with regards to syntax highlighting of comments attached to macro definitions. Before <img width="290" alt="Bildschirmfoto 2020-06-20 um 00 05 19" src="https://user-images.githubusercontent.com/201808/85182705-c561b500-b289-11ea-944e-0bdf6508a44f.png"> After <img width="288" alt="Bildschirmfoto 2020-06-20 um 00 03 36" src="https://user-images.githubusercontent.com/201808/85182727-d90d1b80-b289-11ea-9d2d-234731f19302.png"> Fixes #4949 Co-authored-by: Leander Tentrup <leander.tentrup@gmail.com>
2 parents fe25485 + df5b37c commit 50dad50

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

crates/ra_ide/src/snapshots/highlight_doctest.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,13 @@
8484
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration">foo</span>(&<span class="self_keyword">self</span>) -&gt; <span class="builtin_type">bool</span> {
8585
<span class="bool_literal">true</span>
8686
}
87+
}
88+
89+
<span class="comment documentation">/// ```</span>
90+
<span class="comment documentation">/// </span><span class="macro">noop!</span>(<span class="numeric_literal">1</span>);
91+
<span class="comment documentation">/// ```</span>
92+
<span class="macro">macro_rules!</span> <span class="macro declaration">noop</span> {
93+
($expr:expr) =&gt; {
94+
$expr
95+
}
8796
}</code></pre>

crates/ra_ide/src/syntax_highlighting.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ pub(crate) fn highlight(
121121
assert!(current_macro_call == Some(mc));
122122
current_macro_call = None;
123123
format_string = None;
124-
continue;
125124
}
126125
_ => (),
127126
}
@@ -150,7 +149,7 @@ pub(crate) fn highlight(
150149

151150
let range = element.text_range();
152151

153-
let element_to_highlight = if current_macro_call.is_some() {
152+
let element_to_highlight = if current_macro_call.is_some() && element.kind() != COMMENT {
154153
// Inside a macro -- expand it first
155154
let token = match element.clone().into_token() {
156155
Some(it) if it.parent().kind() == TOKEN_TREE => it,

crates/ra_ide/src/syntax_highlighting/tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,15 @@ impl Foo {
344344
true
345345
}
346346
}
347+
348+
/// ```
349+
/// noop!(1);
350+
/// ```
351+
macro_rules! noop {
352+
($expr:expr) => {
353+
$expr
354+
}
355+
}
347356
"#
348357
.trim(),
349358
"crates/ra_ide/src/snapshots/highlight_doctest.html",

0 commit comments

Comments
 (0)