diff options
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 24 | ||||
-rw-r--r-- | src/Model/SourceLinks.kt | 12 |
2 files changed, 29 insertions, 7 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index aa4a0caf..fba74b9b 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -14,11 +14,11 @@ import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag import org.jetbrains.kotlin.lexer.JetSingleValueToken import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetParameter import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant import org.jetbrains.kotlin.resolve.lazy.ResolveSession +import org.jetbrains.kotlin.resolve.source.PsiSourceElement import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.JetType @@ -52,7 +52,7 @@ class DocumentationBuilder(val session: ResolveSession, if (options.reportUndocumented && !descriptor.isDeprecated() && descriptor !is ValueParameterDescriptor && descriptor !is TypeParameterDescriptor && descriptor !is PropertyAccessorDescriptor) { - logger.warn("No documentation for ${descriptor.signature()}") + logger.warn("No documentation for ${descriptor.signatureWithSourceLocation()}") } return Content.Empty } @@ -152,6 +152,24 @@ class DocumentationBuilder(val session: ResolveSession, return typeName } + fun DeclarationDescriptor.sourceLocation(): String? { + if (this is DeclarationDescriptorWithSource) { + val psi = (this.getSource() as? PsiSourceElement)?.getPsi() + if (psi != null) { + val fileName = psi.getContainingFile().getName() + val lineNumber = psi.lineNumber() + return if (lineNumber != null) "$fileName:$lineNumber" else fileName + } + } + return null + } + + fun DeclarationDescriptor.signatureWithSourceLocation(): String { + val signature = signature() + val sourceLocation = sourceLocation() + return if (sourceLocation != null) "$signature ($sourceLocation)" else signature + } + fun resolveContentLink(descriptor: DeclarationDescriptor, href: String): ContentBlock { val symbols = resolveKDocLink(session, descriptor, null, href.split('.').toList()) val symbol = findTargetSymbol(symbols) @@ -163,7 +181,7 @@ class DocumentationBuilder(val session: ResolveSession, if ("/" in href) { return ContentExternalLink(href) } - logger.warn("Unresolved link to $href in doc comment of ${descriptor.signature()}") + logger.warn("Unresolved link to $href in doc comment of ${descriptor.signatureWithSourceLocation()}") return ContentExternalLink("#") } diff --git a/src/Model/SourceLinks.kt b/src/Model/SourceLinks.kt index 556b813b..fc3293f2 100644 --- a/src/Model/SourceLinks.kt +++ b/src/Model/SourceLinks.kt @@ -18,10 +18,8 @@ fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<Sourc if (linkDef != null) { var url = linkDef.url + path.substring(linkDef.path.length()) if (linkDef.lineSuffix != null) { - val doc = PsiDocumentManager.getInstance(psi!!.getProject()).getDocument(psi.getContainingFile()) - if (doc != null) { - // IJ uses 0-based line-numbers; external source browsers use 1-based - val line = doc.getLineNumber(target!!.getTextRange().getStartOffset()) + 1 + val line = target?.lineNumber() + if (line != null) { url += linkDef.lineSuffix + line.toString() } } @@ -29,3 +27,9 @@ fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<Sourc DocumentationReference.Kind.Detail); } } + +fun PsiElement.lineNumber(): Int? { + val doc = PsiDocumentManager.getInstance(getProject()).getDocument(getContainingFile()) + // IJ uses 0-based line-numbers; external source browsers use 1-based + return doc?.getLineNumber(getTextRange().getStartOffset())?.plus(1) +} |