PsiFileFactory Not Generating File Extension Follow
Answered
Hello, I'm currently developing a plugin that generates a Kotlin file. Everything works except that the resulting file is for example only "TestData", and not "TestData.kt" and as such is not detected by IntelliJ IDEA as a Kotlin file. Here are the pertinent snippets:
class KotlinFileType : FileType {
override fun getName(): String {
return "Kotlin file"
}
override fun getDescription(): String {
return "Kotlin source file"
}
override fun getDefaultExtension(): String {
return ".kt"
}
override fun getIcon(): Icon? {
return null
}
override fun isBinary(): Boolean {
return false
}
companion object {
val INSTANCE = KotlinFileType()
}
}
val fileName = "TestData"
// fileContent generated elsewhere
val classFile = factory.createFileFromText(fileName, KotlinFileType.INSTANCE, fileContent)
WriteCommandAction.runWriteCommandAction(directory.project) {
directory.add(classFile)
}
Did I miss anything? Any help would be appreciated, thanks!
Please sign in to leave a comment.
Please re-use existing org.jetbrains.kotlin.idea.KotlinFileType#INSTANCE from Kotlin plugin instead of duplicating it in your plugin.
'fileName' parameter in createFileFromText() does not automatically append an extension, so it must be:
fileName + "." + KotlinFileType.INSTANCE.defaultExtension
Ah, I see. Alright. Thank you!