https://kotlinlang.org logo
b

Benni

09/07/2022, 8:38 PM
Hi friends. I am working with Kotlin embedded compiler and I have a
org.jetbrains.kotlin.psi.KtNamedFunction
. Anyone know how I can get the line number in which the function resides. I can get the location with
startOffsetSkippingComments
and I assume I could calculate it myself by reading the file, but I was wondering, if there might be a different way.
a

alp

09/07/2022, 9:01 PM
I was using
PsiDiagnosticUtils.getLineAndColumnInPsiFile
for getting line numbers:
Copy code
internal fun PsiElement.lineAndColumn(): PsiDiagnosticUtils.LineAndColumn {
    return DiagnosticUtils.getLineAndColumnInPsiFile(containingFile, textRange) // wrap this in try catch
14 Views