diff options
-rw-r--r-- | core/src/main/kotlin/Kotlin/KotlinLanguageService.kt | 58 | ||||
-rw-r--r-- | core/src/test/kotlin/format/MarkdownFormatTest.kt | 5 | ||||
-rw-r--r-- | core/testdata/format/suspendParam.kt | 3 | ||||
-rw-r--r-- | core/testdata/format/suspendParam.md | 5 | ||||
-rw-r--r-- | core/testdata/format/suspendParam.package.md | 8 |
5 files changed, 59 insertions, 20 deletions
diff --git a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt index 75a8a948..faac9f7d 100644 --- a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt +++ b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt @@ -151,26 +151,43 @@ class KotlinLanguageService : LanguageService { } } - private fun ContentBlock.renderType(node: DocumentationNode, renderMode: RenderMode) { + private fun ContentBlock.renderFunctionalType(node: DocumentationNode, renderMode: RenderMode) { var typeArguments = node.details(NodeKind.Type) - if (node.name == "Function${typeArguments.count() - 1}") { - // lambda - val isExtension = node.annotations.any { it.name == "ExtensionFunctionType" } - if (isExtension) { - renderType(typeArguments.first(), renderMode) - symbol(".") - typeArguments = typeArguments.drop(1) - } - symbol("(") - renderList(typeArguments.take(typeArguments.size - 1), noWrap = true) { - renderFunctionalTypeParameterName(it, renderMode) - renderType(it, renderMode) - } - symbol(")") - nbsp() - symbol("->") - nbsp() - renderType(typeArguments.last(), renderMode) + + if (node.name.startsWith("Suspend")) { + keyword("suspend ") + } + + // lambda + val isExtension = node.annotations.any { it.name == "ExtensionFunctionType" } + if (isExtension) { + renderType(typeArguments.first(), renderMode) + symbol(".") + typeArguments = typeArguments.drop(1) + } + symbol("(") + renderList(typeArguments.take(typeArguments.size - 1), noWrap = true) { + renderFunctionalTypeParameterName(it, renderMode) + renderType(it, renderMode) + } + symbol(")") + nbsp() + symbol("->") + nbsp() + renderType(typeArguments.last(), renderMode) + + } + + private fun DocumentationNode.isFunctionalType(): Boolean { + val typeArguments = details(NodeKind.Type) + val functionalTypeName = "Function${typeArguments.count() - 1}" + val suspendFunctionalTypeName = "Suspend$functionalTypeName" + return name == functionalTypeName || name == suspendFunctionalTypeName + } + + private fun ContentBlock.renderType(node: DocumentationNode, renderMode: RenderMode) { + if (node.isFunctionalType()) { + renderFunctionalType(node, renderMode) return } if (renderMode == RenderMode.FULL) { @@ -178,7 +195,8 @@ class KotlinLanguageService : LanguageService { } renderModifiersForNode(node, renderMode, true) renderLinked(node) { identifier(it.name, IdentifierKind.TypeName) } - if (typeArguments.any()) { + val typeArguments = node.details(NodeKind.Type) + if (typeArguments.isNotEmpty()) { symbol("<") renderList(typeArguments, noWrap = true) { renderType(it, renderMode) diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index c425e3f6..f870d898 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -236,6 +236,11 @@ class MarkdownFormatTest { verifyMarkdownPackage("typeAliases") } + @Test fun suspendParam() { + verifyMarkdownNode("suspendParam") + verifyMarkdownPackage("suspendParam") + } + private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) diff --git a/core/testdata/format/suspendParam.kt b/core/testdata/format/suspendParam.kt new file mode 100644 index 00000000..ea3f56f9 --- /dev/null +++ b/core/testdata/format/suspendParam.kt @@ -0,0 +1,3 @@ +fun takesSuspendParam(func: suspend () -> Unit) { + +}
\ No newline at end of file diff --git a/core/testdata/format/suspendParam.md b/core/testdata/format/suspendParam.md new file mode 100644 index 00000000..cf11f57b --- /dev/null +++ b/core/testdata/format/suspendParam.md @@ -0,0 +1,5 @@ +[test](test/index) / [takesSuspendParam](test/takes-suspend-param) + +# takesSuspendParam + +`fun takesSuspendParam(func: suspend () -> Unit): Unit`
\ No newline at end of file diff --git a/core/testdata/format/suspendParam.package.md b/core/testdata/format/suspendParam.package.md new file mode 100644 index 00000000..463ba356 --- /dev/null +++ b/core/testdata/format/suspendParam.package.md @@ -0,0 +1,8 @@ +[test](test/index) + +## Package <root> + +### Functions + +| [takesSuspendParam](test/takes-suspend-param) | `fun takesSuspendParam(func: suspend () -> Unit): Unit` | + |