fun substituteLanguage()

in idea-plugin/src/main/java/org/jetbrains/bunches/idea/highlighting/BunchLanguageSubstitutor.kt [18:44]


        fun substituteLanguage(file: VirtualFile, project: Project): Language? {
            val bunchExtensions = BunchFileUtils.bunchExtensions(project) ?: return null

            val name = file.name
            val extension = name.substringAfterLast(".", "")
            if (extension !in bunchExtensions) {
                return null
            }

            val nameWithoutExtension = name.substringBeforeLast(".")
            val secondExtension = nameWithoutExtension.substringAfterLast(".", "")
            if (secondExtension.isEmpty()) {
                return null
            }

            if (secondExtension.toLowerCase() == "kt") {
                // Temporary disable till problem with Kotlin resolve is fixed
                return null
            }

            val actualFileType = FileTypeManager.getInstance().getFileTypeByExtension(secondExtension)
            if (actualFileType is LanguageFileType) {
                return actualFileType.language
            }

            return null
        }