Last active
December 13, 2024 17:41
-
-
Save dkandalov/a48cae4ad5459b7036f3d52307d1afb4 to your computer and use it in GitHub Desktop.
Mini-plugin to optimise imports in the background in all project Kotlin files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.intellij.codeInsight.actions.OptimizeImportsProcessor | |
import com.intellij.lang.Language | |
import com.intellij.psi.PsiFile import liveplugin.PluginUtil | |
import liveplugin.registerAction | |
registerAction("Background Optimize Imports") { event -> | |
val project = event.project ?: return@registerAction | |
val kotlinLanguage = Language.findLanguageByID("kotlin")!! | |
val psiFiles = PluginUtil.allPsiItemsIn(project) | |
.filterIsInstance<PsiFile>() | |
.filter { it.language == kotlinLanguage } | |
liveplugin.runBackgroundTask("Background Optimize Imports") { indicator -> | |
indicator.isIndeterminate = false | |
OptimizeImportsProcessor(project, psiFiles.toTypedArray(), null) | |
.apply { processFilesUnderProgress(indicator) } | |
.run() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment