aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Languages/JavaLanguageService.kt4
-rw-r--r--src/Model/DocumentationNode.kt1
-rw-r--r--src/Model/SourceLinks.kt24
3 files changed, 19 insertions, 10 deletions
diff --git a/src/Languages/JavaLanguageService.kt b/src/Languages/JavaLanguageService.kt
index 7446b34f..e491d1bd 100644
--- a/src/Languages/JavaLanguageService.kt
+++ b/src/Languages/JavaLanguageService.kt
@@ -123,9 +123,9 @@ public class JavaLanguageService : LanguageService {
val receiver = node.details(Kind.Receiver).singleOrNull()
append("(")
if (receiver != null)
- append((listOf(receiver) + node.details(Kind.Parameter)).map { renderParameter(it) }.join())
+ (listOf(receiver) + node.details(Kind.Parameter)).map { renderParameter(it) }.joinTo(this)
else
- append(node.details(Kind.Parameter).map { renderParameter(it) }.join())
+ node.details(Kind.Parameter).map { renderParameter(it) }.joinTo(this)
append(")")
}.toString()
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index 7f862183..2f0638bc 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -101,6 +101,7 @@ public open class DocumentationNode(val name: String,
Value,
SourceUrl,
+ SourcePosition,
/**
* A note which is rendered once on a page documenting a group of overloaded functions.
diff --git a/src/Model/SourceLinks.kt b/src/Model/SourceLinks.kt
index fc3293f2..dff4b36b 100644
--- a/src/Model/SourceLinks.kt
+++ b/src/Model/SourceLinks.kt
@@ -4,16 +4,15 @@ import com.intellij.psi.PsiElement
import java.io.File
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiNameIdentifierOwner
+import org.jetbrains.kotlin.psi.psiUtil.startOffset
class SourceLinkDefinition(val path: String, val url: String, val lineSuffix: String?)
fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<SourceLinkDefinition>) {
- val path = psi?.getContainingFile()?.getVirtualFile()?.getPath()
- if (path == null) {
- return
- }
- val target = if (psi is PsiNameIdentifierOwner) psi.getNameIdentifier() else psi
- val absPath = File(path).getAbsolutePath()
+ val path = psi?.containingFile?.virtualFile?.path ?: return
+
+ val target = if (psi is PsiNameIdentifierOwner) psi.nameIdentifier else psi
+ val absPath = File(path).absolutePath
val linkDef = sourceLinks.firstOrNull { absPath.startsWith(it.path) }
if (linkDef != null) {
var url = linkDef.url + path.substring(linkDef.path.length())
@@ -26,10 +25,19 @@ fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<Sourc
append(DocumentationNode(url, Content.Empty, DocumentationNode.Kind.SourceUrl),
DocumentationReference.Kind.Detail);
}
+
+ append(DocumentationNode("$path:${target?.lineNumber()}:${target?.columnNumber()}", Content.Empty, DocumentationNode.Kind.SourcePosition), DocumentationReference.Kind.Detail)
}
fun PsiElement.lineNumber(): Int? {
- val doc = PsiDocumentManager.getInstance(getProject()).getDocument(getContainingFile())
+ val doc = PsiDocumentManager.getInstance(project).getDocument(containingFile)
// IJ uses 0-based line-numbers; external source browsers use 1-based
- return doc?.getLineNumber(getTextRange().getStartOffset())?.plus(1)
+ return doc?.getLineNumber(textRange.startOffset)?.plus(1)
}
+
+fun PsiElement.columnNumber(): Int? {
+ val doc = PsiDocumentManager.getInstance(project).getDocument(containingFile)
+ // IJ uses 0-based line-numbers; external source browsers use 1-based
+ val lineNumber = doc?.getLineNumber(textRange.startOffset)?.plus(1) ?: return null
+ return startOffset - doc!!.getLineStartOffset(lineNumber)
+} \ No newline at end of file