Skip to content

Commit

Permalink
fix(js): fix lost tsx syntax error issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 4, 2023
1 parent 8bff8fc commit e42bc96
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/main/kotlin/cc/unitmesh/devti/provider/WriteTestService.kt
Expand Up @@ -5,7 +5,6 @@ import cc.unitmesh.devti.provider.context.TestFileContext
import com.intellij.execution.Executor
import com.intellij.execution.ExecutorRegistryImpl
import com.intellij.execution.RunManager
import com.intellij.execution.configurations.LocatableConfigurationBase
import com.intellij.execution.configurations.RunProfile
import com.intellij.ide.actions.runAnything.RunAnythingPopupUI
import com.intellij.openapi.actionSystem.DataContext
Expand Down Expand Up @@ -71,13 +70,36 @@ abstract class WriteTestService : LazyExtensionInstance<WriteTestService>() {
ExtensionPointName.create("cc.unitmesh.testContextProvider")

fun context(psiElement: PsiElement): WriteTestService? {
val lang = psiElement.language.displayName
val lang = psiElement.language.displayName.lowercase()
val extensionList = EP_NAME.extensionList
val providers = extensionList.filter {
it.language?.lowercase() == lang.lowercase() && it.isApplicable(psiElement)
val testServices = filterByLang(extensionList, lang)

val service = if (testServices.isNotEmpty()) {
testServices.first()
} else {
// if lang == "TypeScript JSX", we just use TypeScript
val firstPartLang = lang.split(" ")[0]
val partLang = filterByLang(extensionList, firstPartLang)
if (partLang.isNotEmpty()) {
partLang[0]
} else {
logger<WriteTestService>().warn("No context prompter found for language $lang, will use default")
return null
}
}

return service
}

private fun filterByLang(
extensionList: List<WriteTestService>,
langLowercase: String
): List<WriteTestService> {
val contextPrompter = extensionList.filter {
it.language?.lowercase() == langLowercase
}

return providers.firstOrNull()
return contextPrompter
}
}
}

0 comments on commit e42bc96

Please sign in to comment.