aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Kotlin/DocumentationBuilder.kt35
-rw-r--r--test/data/format/brokenLink.html12
-rw-r--r--test/data/format/brokenLink.kt4
-rw-r--r--test/src/format/HtmlFormatTest.kt6
4 files changed, 40 insertions, 17 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 6403f14c..be6d5d7c 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
-import org.jetbrains.kotlin.resolve.source.getPsi
import java.io.File
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiNameIdentifierOwner
@@ -506,24 +505,26 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
}
fun resolveContentLinks(node: DocumentationNode, content: ContentNode) {
- val snapshot = content.children.toList()
- for (child in snapshot) {
- if (child is ContentExternalLink) {
- val referenceText = child.href
- val symbol = resolveReference(getResolutionScope(node), referenceText)
- if (symbol != null) {
- val targetNode = descriptorToNode[symbol]
- val contentLink = if (targetNode != null) ContentNodeLink(targetNode) else ContentExternalLink("#")
-
- val index = content.children.indexOf(child)
- content.children.remove(index)
- contentLink.children.addAll(child.children)
- content.children.add(index, contentLink)
- }
-
+ val resolvedContentChildren = content.children.map { resolveContentLink(node, it) }
+ content.children.clear()
+ content.children.addAll(resolvedContentChildren)
+ }
+
+ private fun resolveContentLink(node: DocumentationNode, content: ContentNode): ContentNode {
+ if (content is ContentExternalLink) {
+ val referenceText = content.href
+ val symbol = resolveReference(getResolutionScope(node), referenceText)
+ // 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 (symbol != null || "/" !in referenceText) {
+ val targetNode = descriptorToNode[symbol]
+ val contentLink = if (targetNode != null) ContentNodeLink(targetNode) else ContentExternalLink("#")
+ contentLink.children.addAll(content.children.map { resolveContentLink(node, it) })
+ return contentLink
}
- resolveContentLinks(node, child)
}
+ resolveContentLinks(node, content)
+ return content
}
private fun resolveReference(context: DeclarationDescriptor, reference: String): DeclarationDescriptor? {
diff --git a/test/data/format/brokenLink.html b/test/data/format/brokenLink.html
new file mode 100644
index 00000000..d5f8707f
--- /dev/null
+++ b/test/data/format/brokenLink.html
@@ -0,0 +1,12 @@
+<HTML>
+<HEAD>
+</HEAD>
+<BODY>
+<a href="out.html">test</a>&nbsp;/&nbsp;<a href="out.html"></a>&nbsp;/&nbsp;<a href="out.html">f</a><br/>
+<br/>
+<h1>f</h1>
+<pre><code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code></pre><p>This references <a href="#">noSuchIdentifier</a>.</p>
+<br/>
+<br/>
+</BODY>
+</HTML>
diff --git a/test/data/format/brokenLink.kt b/test/data/format/brokenLink.kt
new file mode 100644
index 00000000..268a986e
--- /dev/null
+++ b/test/data/format/brokenLink.kt
@@ -0,0 +1,4 @@
+/**
+ * This references [noSuchIdentifier].
+ */
+fun f() { }
diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt
index 47fe9c4e..dfecb4d4 100644
--- a/test/src/format/HtmlFormatTest.kt
+++ b/test/src/format/HtmlFormatTest.kt
@@ -33,4 +33,10 @@ public class HtmlFormatTest {
htmlService.appendNodes(tempLocation, output, model.members.single().members)
}
}
+
+ Test fun brokenLink() {
+ verifyOutput("test/data/format/brokenLink.kt", ".html") { model, output ->
+ htmlService.appendNodes(tempLocation, output, model.members.single().members)
+ }
+ }
}