From 4b5b54279ad74316837bcdc7daa195d82bd13d3a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 15 May 2021 17:23:20 +0200 Subject: Attach comments to ast::Impl --- .../syntax_highlighting/test_data/highlight_doctest.html | 14 +++++++++++++- crates/ide/src/syntax_highlighting/tests.rs | 12 ++++++++++++ crates/syntax/src/parsing/text_tree_sink.rs | 4 ++-- crates/syntax/test_data/parser/ok/0045_block_attrs.rast | 6 +++--- 4 files changed, 30 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index 8d83ba206..921a956e6 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html @@ -37,13 +37,25 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
/// ```
+
//! This is a module to test doc injection.
+//! ```
+//! fn test() {}
+//! ```
+
+/// ```
 /// let _ = "early doctests should not go boom";
 /// ```
 struct Foo {
     bar: bool,
 }
 
+/// This is an impl with a code block.
+///
+/// ```
+/// fn foo() {
+///
+/// }
+/// ```
 impl Foo {
     /// ```
     /// let _ = "Call me
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index 32f2d9038..95408dfb2 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -524,6 +524,11 @@ fn main() {
 fn test_highlight_doc_comment() {
     check_highlighting(
         r#"
+//! This is a module to test doc injection.
+//! ```
+//! fn test() {}
+//! ```
+
 /// ```
 /// let _ = "early doctests should not go boom";
 /// ```
@@ -531,6 +536,13 @@ struct Foo {
     bar: bool,
 }
 
+/// This is an impl with a code block.
+///
+/// ```
+/// fn foo() {
+///
+/// }
+/// ```
 impl Foo {
     /// ```
     /// let _ = "Call me
diff --git a/crates/syntax/src/parsing/text_tree_sink.rs b/crates/syntax/src/parsing/text_tree_sink.rs
index 1934204ea..d63ec080b 100644
--- a/crates/syntax/src/parsing/text_tree_sink.rs
+++ b/crates/syntax/src/parsing/text_tree_sink.rs
@@ -147,8 +147,8 @@ fn n_attached_trivias<'a>(
     trivias: impl Iterator,
 ) -> usize {
     match kind {
-        MACRO_CALL | MACRO_RULES | MACRO_DEF | CONST | TYPE_ALIAS | STRUCT | UNION | ENUM
-        | VARIANT | FN | TRAIT | MODULE | RECORD_FIELD | STATIC | USE => {
+        CONST | ENUM | FN | IMPL | MACRO_CALL | MACRO_DEF | MACRO_RULES | MODULE | RECORD_FIELD
+        | STATIC | STRUCT | TRAIT | TUPLE_FIELD | TYPE_ALIAS | UNION | USE | VARIANT => {
             let mut res = 0;
             let mut trivias = trivias.enumerate().peekable();
 
diff --git a/crates/syntax/test_data/parser/ok/0045_block_attrs.rast b/crates/syntax/test_data/parser/ok/0045_block_attrs.rast
index 50ab52d32..5e50b4e0b 100644
--- a/crates/syntax/test_data/parser/ok/0045_block_attrs.rast
+++ b/crates/syntax/test_data/parser/ok/0045_block_attrs.rast
@@ -127,9 +127,9 @@ SOURCE_FILE@0..764
       WHITESPACE@537..538 "\n"
       R_CURLY@538..539 "}"
   WHITESPACE@539..541 "\n\n"
-  COMMENT@541..601 "// https://github.com ..."
-  WHITESPACE@601..602 "\n"
-  IMPL@602..763
+  IMPL@541..763
+    COMMENT@541..601 "// https://github.com ..."
+    WHITESPACE@601..602 "\n"
     IMPL_KW@602..606 "impl"
     WHITESPACE@606..607 " "
     PATH_TYPE@607..615
-- 
cgit v1.2.3