Skip to content

Commit 92abc56

Browse files
bors[bot]Veykril
andauthored
Merge #8848
8848: Attach comments to ast::Impl r=Veykril a=Veykril bors r+ Fixes #8847 Co-authored-by: Lukas Wirth <[email protected]>
2 parents 87ef340 + 4b5b542 commit 92abc56

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

crates/ide/src/matching_brace.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ use syntax::{
1919
pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> {
2020
const BRACES: &[SyntaxKind] =
2121
&[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]];
22-
let (brace_token, brace_idx) = file
23-
.syntax()
24-
.token_at_offset(offset)
25-
.filter_map(|node| {
26-
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
27-
Some((node, idx))
28-
})
29-
.next()?;
22+
let (brace_token, brace_idx) = file.syntax().token_at_offset(offset).find_map(|node| {
23+
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
24+
Some((node, idx))
25+
})?;
3026
let parent = brace_token.parent()?;
3127
if brace_token.kind() == T![|] && !ast::ParamList::can_cast(parent.kind()) {
3228
cov_mark::hit!(pipes_not_braces);

crates/ide/src/parent_module.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use hir::Semantics;
2-
use ide_db::base_db::{CrateId, FileId, FilePosition};
3-
use ide_db::RootDatabase;
2+
use ide_db::{
3+
base_db::{CrateId, FileId, FilePosition},
4+
RootDatabase,
5+
};
46
use itertools::Itertools;
57
use syntax::{
68
algo::find_node_at_offset,

crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,25 @@
3737

3838
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
3939
</style>
40-
<pre><code><span class="comment documentation">/// ```</span>
40+
<pre><code><span class="comment documentation">//! This is a module to test doc injection.</span>
41+
<span class="comment documentation">//! ```</span>
42+
<span class="comment documentation">//! </span><span class="keyword injected">fn</span><span class="none injected"> </span><span class="function declaration injected">test</span><span class="parenthesis injected">(</span><span class="parenthesis injected">)</span><span class="none injected"> </span><span class="brace injected">{</span><span class="brace injected">}</span>
43+
<span class="comment documentation">//! ```</span>
44+
45+
<span class="comment documentation">/// ```</span>
4146
<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="punctuation injected">_</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="semicolon injected">;</span>
4247
<span class="comment documentation">/// ```</span>
4348
<span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="brace">{</span>
4449
<span class="field declaration">bar</span><span class="colon">:</span> <span class="builtin_type">bool</span><span class="comma">,</span>
4550
<span class="brace">}</span>
4651

52+
<span class="comment documentation">/// This is an impl with a code block.</span>
53+
<span class="comment documentation">///</span>
54+
<span class="comment documentation">/// ```</span>
55+
<span class="comment documentation">/// </span><span class="keyword injected">fn</span><span class="none injected"> </span><span class="function declaration injected">foo</span><span class="parenthesis injected">(</span><span class="parenthesis injected">)</span><span class="none injected"> </span><span class="brace injected">{</span>
56+
<span class="comment documentation">///</span>
57+
<span class="comment documentation">/// </span><span class="brace injected">}</span>
58+
<span class="comment documentation">/// ```</span>
4759
<span class="keyword">impl</span> <span class="struct">Foo</span> <span class="brace">{</span>
4860
<span class="comment documentation">/// ```</span>
4961
<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="punctuation injected">_</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"Call me</span>

crates/ide/src/syntax_highlighting/tests.rs

+12
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,25 @@ fn main() {
524524
fn test_highlight_doc_comment() {
525525
check_highlighting(
526526
r#"
527+
//! This is a module to test doc injection.
528+
//! ```
529+
//! fn test() {}
530+
//! ```
531+
527532
/// ```
528533
/// let _ = "early doctests should not go boom";
529534
/// ```
530535
struct Foo {
531536
bar: bool,
532537
}
533538
539+
/// This is an impl with a code block.
540+
///
541+
/// ```
542+
/// fn foo() {
543+
///
544+
/// }
545+
/// ```
534546
impl Foo {
535547
/// ```
536548
/// let _ = "Call me

crates/syntax/src/parsing/text_tree_sink.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ fn n_attached_trivias<'a>(
147147
trivias: impl Iterator<Item = (SyntaxKind, &'a str)>,
148148
) -> usize {
149149
match kind {
150-
MACRO_CALL | MACRO_RULES | MACRO_DEF | CONST | TYPE_ALIAS | STRUCT | UNION | ENUM
151-
| VARIANT | FN | TRAIT | MODULE | RECORD_FIELD | STATIC | USE => {
150+
CONST | ENUM | FN | IMPL | MACRO_CALL | MACRO_DEF | MACRO_RULES | MODULE | RECORD_FIELD
151+
| STATIC | STRUCT | TRAIT | TUPLE_FIELD | TYPE_ALIAS | UNION | USE | VARIANT => {
152152
let mut res = 0;
153153
let mut trivias = trivias.enumerate().peekable();
154154

crates/syntax/test_data/parser/ok/0045_block_attrs.rast

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ [email protected]
127127
128128
129129
130-
COMMENT@541..601 "// https://github.com ..."
131-
132-
130+
IMPL@541..763
131+
[email protected] "// https://github.com ..."
132+
133133
134134
135135

0 commit comments

Comments
 (0)