Make Intellij Idea plugin work with Kotlin files

 

I've created this very simple Intellij Idea plugin which folds some reference expressions. It works great for Java files but it doesn't work for Kotlin.

Here is the source: https://github.com/nodes-android/nstack-translation-folding
I will include here the important parts: 
plugin.xml

</idea-plugin>
    <depends>com.intellij.modules.all</depends>

    <application-components>
        <component>
            <implementation-class>com.nodes.folding.TranslationFoldingBuilder</implementation-class>
        </component>
    </application-components>

    <extensions defaultExtensionNs="com.intellij">
        <lang.foldingBuilder language="JAVA" implementationClass="com.nodes.folding.TranslationFoldingBuilder"/>
    </extensions>

</idea-plugin>

TranslationFoldingBuilder.kt

class TranslationFoldingBuilder : FoldingBuilderEx() {

    override fun buildFoldRegions(root: PsiElement, document: Document, quick: Boolean): Array<FoldingDescriptor> {
        if (root !is PsiJavaFile) {
            return FoldingDescriptor.EMPTY
        }

        val descriptors = ArrayList<FoldingDescriptor>()
        // Get all the reference expressions in this Java file
        val referenceExpressions = PsiTreeUtil.findChildrenOfType(root, PsiReferenceExpression::class.java)

        // Some logic

        return descriptors.toTypedArray()
    }
}

My problem is that for Kotlin files the buildFoldRegions() is not called at all.

0
Avatar
Permanently deleted user

I can't believe no one has written a Plugin in Kotlin in this forum. Please help guys. I also created a stackoverflow question https://stackoverflow.com/questions/47439843/make-intellij-idea-plugin-work-with-kotlin-files/47472910

0

Kotlin's Psi files are not Java Psi files.  For example mutli-line java comments are KDoc nodes.  Kotin uses PsiNamedFunction instead of PsiMethod.  I ran into other issues as well. 

See my post here.

https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000712004-How-to-integrate-KotlinPlugin-s-PSI-classes

0

Try looking at the Kotlin plugin. https://github.com/JetBrains/kotlin/tree/master/idea/src
This is what I do to understand the Kotlin PSI model.

0

请先登录再写评论。