Skip to content

Commit

Permalink
Perform refreshAndFindFileByIoFile on a pooled thread
Browse files Browse the repository at this point in the history
  • Loading branch information
sxhya committed Oct 18, 2024
1 parent b795b67 commit f7655aa
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/main/kotlin/org/arend/actions/mark/ArendMarkActionUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.ide.projectView.actions.MarkRootActionBase
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.module.Module
Expand Down Expand Up @@ -117,13 +118,27 @@ internal fun isNotOtherDirectionType(e: AnActionEvent): Boolean {
val arendModuleConfigService = ArendModuleConfigService.getInstance(module)

val localFileSystem = LocalFileSystem.getInstance()
val sourceDir = localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.sourcesDir))
val testDir = localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.testsDir))
val binariesDirectory = localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.binariesDirectory))
return when (dir) {
sourceDir, testDir, binariesDirectory -> false
else -> true
}
return ApplicationManager.getApplication().executeOnPooledThread<Boolean> {
val (sourceDir, testDir, binariesDirectory) = triple(localFileSystem, arendModuleConfigService)

when (dir) {
sourceDir, testDir, binariesDirectory -> false
else -> true
}
}.get()
}

private fun triple(
localFileSystem: LocalFileSystem,
arendModuleConfigService: ArendModuleConfigService?
): Triple<VirtualFile?, VirtualFile?, VirtualFile?> {
val sourceDir =
localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.sourcesDir))
val testDir =
localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.testsDir))
val binariesDirectory =
localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.binariesDirectory))
return Triple(sourceDir, testDir, binariesDirectory)
}

internal fun hasSpecialDirectories(e: AnActionEvent): Boolean {
Expand All @@ -132,16 +147,18 @@ internal fun hasSpecialDirectories(e: AnActionEvent): Boolean {
val arendModuleConfigService = ArendModuleConfigService.getInstance(module)

val localFileSystem = LocalFileSystem.getInstance()
val sourceDir = localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.sourcesDir))
val testDir = localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.testsDir))
val binariesDirectory = localFileSystem.refreshAndFindFileByIoFile(File(arendModuleConfigService?.root?.path + File.separator + arendModuleConfigService?.binariesDirectory))
for (file in files) {
when (file) {
sourceDir, testDir, binariesDirectory -> return true
else -> continue
return ApplicationManager.getApplication().executeOnPooledThread<Boolean> {
val (sourceDir, testDir, binariesDirectory) = triple(localFileSystem, arendModuleConfigService)

var result = false
for (file in files) {
when (file) {
sourceDir, testDir, binariesDirectory -> result = true
else -> continue
}
}
}
return false
result
}.get()
}

internal fun unmarkOldDirectory(e: AnActionEvent, directoryType: DirectoryType) {
Expand Down

0 comments on commit f7655aa

Please sign in to comment.