diff options
Diffstat (limited to 'src/Kotlin')
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 12 | ||||
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 6 |
2 files changed, 8 insertions, 10 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 35beec54..b5647ff0 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -5,6 +5,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.name.* +import org.jetbrains.kotlin.idea.kdoc.getResolutionScope import org.intellij.markdown.* import org.jetbrains.kotlin.psi.JetDeclarationWithBody import org.jetbrains.kotlin.psi.JetBlockExpression @@ -119,7 +120,7 @@ public fun DocumentationBuilder.buildInlineContentTo(tree: MarkdownNode, target: } fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functionName: String): ContentNode { - val scope = getResolutionScope(descriptor) + val scope = getResolutionScope(session, descriptor) val rootPackage = session.getModuleDescriptor().getPackage(FqName.ROOT)!! val rootScope = rootPackage.getMemberScope() val symbol = resolveInScope(functionName, scope) ?: resolveInScope(functionName, rootScope) @@ -149,22 +150,19 @@ fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functio private fun DocumentationBuilder.resolveInScope(functionName: String, scope: JetScope): DeclarationDescriptor? { var currentScope = scope val parts = functionName.split('.') + var symbol: DeclarationDescriptor? = null for (part in parts) { // short name val symbolName = Name.guess(part) - val partSymbol = currentScope.getLocalVariable(symbolName) ?: - currentScope.getProperties(symbolName).firstOrNull() ?: - currentScope.getFunctions(symbolName).firstOrNull() ?: - currentScope.getClassifier(symbolName) ?: - currentScope.getPackage(symbolName) + val partSymbol = currentScope.getAllDescriptors().filter { it.getName() == symbolName }.firstOrNull() if (partSymbol == null) { symbol = null break } - currentScope = getResolutionScope(partSymbol) + currentScope = getResolutionScope(session, partSymbol) symbol = partSymbol } diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 041b7617..1b37dc51 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -51,7 +51,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati if (kdoc is KDocSection) { val tags = kdoc.getTags() tags.forEach { - if (it.getName() == "code") { + if (it.getName() == "sample") { content.append(functionBody(descriptor, it.getContent())) } else { val section = content.addSection(displayName(it.getName()), it.getSubjectName()) @@ -529,7 +529,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati } } - fun getResolutionScope(node: DocumentationNode): DeclarationDescriptor { + fun getDescriptorForNode(node: DocumentationNode): DeclarationDescriptor { val descriptor = nodeToDescriptor[node] ?: throw IllegalArgumentException("Node is not known to this context") return descriptor } @@ -543,7 +543,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati private fun resolveContentLink(node: DocumentationNode, content: ContentNode): ContentNode { if (content is ContentExternalLink) { val referenceText = content.href - val symbols = resolveKDocLink(session, getResolutionScope(node), null, referenceText.split('.').toList()) + val symbols = resolveKDocLink(session, getDescriptorForNode(node), null, referenceText.split('.').toList()) // don't include unresolved links in generated doc // assume that if an href doesn't contain '/', it's not an attempt to reference an external file if (symbols.isNotEmpty() || "/" !in referenceText) { |