diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/Kotlin/KotlinLanguageService.kt | 58 | ||||
-rw-r--r-- | core/src/test/kotlin/format/MarkdownFormatTest.kt | 5 |
2 files changed, 43 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) |