Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
fix: fix json file with keywords issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 24, 2022
1 parent 1fefc0c commit e198995
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -13,11 +13,13 @@ class LanguageService {
private val SHE_BANG: String = "#!"
private var extToLanguages: MutableMap<String, List<String>> = mutableMapOf()
private var filenameToLanguage: MutableMap<String, String> = mutableMapOf()
private var languageMap: MutableMap<String, Language> = mutableMapOf()

init {
val fileContent = this.javaClass.classLoader.getResource("languages.json").readText()
val languages = Json.decodeFromString<Array<Language>>(fileContent)
languages.forEach { entry ->
languageMap[entry.name] = entry
entry.extensions.forEach {
if (extToLanguages[it] == null) {
extToLanguages[it] = listOf()
Expand All @@ -37,7 +39,14 @@ class LanguageService {
return langs[0]
}

return langs[0]
var primaryLanguage = langs[0]
langs.forEach {
if (languageMap[it]!!.keywords.isNullOrEmpty()) {
primaryLanguage = it
}
}

return primaryLanguage
}

fun detectLanguages(name: String): List<String> {
Expand Down

0 comments on commit e198995

Please sign in to comment.