From c6cf9f4363adcc53af7f8ad7509d2f6d37343180 Mon Sep 17 00:00:00 2001
From: Arseniy Pendryak
Date: Fri, 10 Sep 2021 11:09:32 +0300
Subject: [PATCH] QDOC: improve documentation rendering for macro 2.0
Previously, we didn't render header for macro 2.0 items as we do for other items.
Also, add some missing tests for macro documentation
---
.../rust/ide/docs/RsDocumentationProvider.kt | 16 ++++---
.../rust/ide/docs/RsQuickDocumentationTest.kt | 43 ++++++++++++++++---
2 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/src/main/kotlin/org/rust/ide/docs/RsDocumentationProvider.kt b/src/main/kotlin/org/rust/ide/docs/RsDocumentationProvider.kt
index 8fc15e277af..3ed14baeb4b 100644
--- a/src/main/kotlin/org/rust/ide/docs/RsDocumentationProvider.kt
+++ b/src/main/kotlin/org/rust/ide/docs/RsDocumentationProvider.kt
@@ -267,7 +267,7 @@ private fun RsDocAndAttributeOwner.header(buffer: StringBuilder) {
is RsNamedFieldDecl -> listOfNotNull((parent?.parent as? RsDocAndAttributeOwner)?.presentableQualifiedName)
is RsStructOrEnumItemElement,
is RsTraitItem,
- is RsMacro -> listOfNotNull(presentableQualifiedModName)
+ is RsMacroDefinitionBase -> listOfNotNull(presentableQualifiedModName)
is RsAbstractable -> when (val owner = owner) {
is RsAbstractableOwner.Foreign,
is RsAbstractableOwner.Free -> listOfNotNull(presentableQualifiedModName)
@@ -287,8 +287,7 @@ fun RsDocAndAttributeOwner.signature(builder: StringBuilder) {
is RsNamedFieldDecl -> listOfNotNull(presentationInfo?.signatureText)
is RsFunction -> {
val buffer = StringBuilder()
- declarationModifiers.joinTo(buffer, " ")
- buffer += " "
+ declarationModifiers.joinTo(buffer, separator = " ", postfix = " ")
buffer.b { it += name }
typeParameterList?.generateDocumentation(buffer)
valueParameterList?.generateDocumentation(buffer)
@@ -297,7 +296,7 @@ fun RsDocAndAttributeOwner.signature(builder: StringBuilder) {
}
is RsConstant -> {
val buffer = StringBuilder()
- declarationModifiers.joinTo(buffer, " ", "", " ")
+ declarationModifiers.joinTo(buffer, separator = " ", postfix = " ")
buffer.b { it += name }
typeReference?.generateDocumentation(buffer, ": ")
expr?.generateDocumentation(buffer, " = ")
@@ -308,7 +307,7 @@ fun RsDocAndAttributeOwner.signature(builder: StringBuilder) {
val name = name
if (name != null) {
val buffer = StringBuilder()
- (this as RsItemElement).declarationModifiers.joinTo(buffer, " ", "", " ")
+ (this as RsItemElement).declarationModifiers.joinTo(buffer, separator = " ", postfix = " ")
buffer.b { it += name }
(this as RsGenericDeclaration).typeParameterList?.generateDocumentation(buffer)
(this as? RsTypeAlias)?.typeReference?.generateDocumentation(buffer, " = ")
@@ -316,6 +315,12 @@ fun RsDocAndAttributeOwner.signature(builder: StringBuilder) {
} else emptyList()
}
is RsMacro -> listOf("macro $name")
+ is RsMacro2 -> {
+ val buffer = StringBuilder()
+ declarationModifiers.joinTo(buffer, separator = " ", postfix = " ")
+ buffer.b { it += name }
+ listOf(buffer.toString())
+ }
is RsImplItem -> declarationText
else -> emptyList()
}
@@ -377,6 +382,7 @@ private val RsItemElement.declarationModifiers: List
}
modifiers += "trait"
}
+ is RsMacro2 -> modifiers += "macro"
else -> error("unexpected type $javaClass")
}
return modifiers
diff --git a/src/test/kotlin/org/rust/ide/docs/RsQuickDocumentationTest.kt b/src/test/kotlin/org/rust/ide/docs/RsQuickDocumentationTest.kt
index 559eb4ed452..3ec9fdebcf3 100644
--- a/src/test/kotlin/org/rust/ide/docs/RsQuickDocumentationTest.kt
+++ b/src/test/kotlin/org/rust/ide/docs/RsQuickDocumentationTest.kt
@@ -732,8 +732,7 @@ class RsQuickDocumentationTest : RsDocumentationProviderTest() {
Module level docs
""")
- //
- fun `test macro outer docstring`() = doTest("""
+ fun `test macro outer docstring 1`() = doTest("""
/// Outer documentation
macro_rules! makro {
//^
@@ -748,16 +747,48 @@ class RsQuickDocumentationTest : RsDocumentationProviderTest() {
""")
- fun `test macro 2 outer docs`() = doTest("""
+ fun `test macro outer docstring 2`() = doTest("""
+ pub mod foo {
+ /// Outer documentation
+ macro_rules! makro {
+ //^
+ () => { };
+ }
+ }
+
+ fn main() {
+ }
+ """, """
+ test_package
+ macro makro
+
+ """)
+
+ fun `test macro 2 outer docs 1`() = doTest("""
pub struct Foo;
/// Outer doc
/// [link](Foo)
- pub macro Bar() {}
+ pub macro bar() {}
//^
""", """
-
+ test_package
+ pub macro bar
+
+ """)
+
+ fun `test macro 2 outer docs 2`() = doTest("""
+ pub mod foo_bar {
+ pub struct Foo;
+
+ /// Outer doc
+ /// [link](Foo)
+ pub macro bar() {}
+ } //^
+ """, """
+ test_package::foo_bar
+ pub macro bar
""")