aboutsummaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/SourceLinks.kt12
1 files changed, 8 insertions, 4 deletions
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)
+}