|
| 1 | +package cc.unitmesh.dependencies |
| 2 | + |
| 3 | +import com.intellij.openapi.actionSystem.ActionUpdateThread |
| 4 | +import com.intellij.openapi.actionSystem.AnAction |
| 5 | +import com.intellij.openapi.actionSystem.AnActionEvent |
| 6 | +import com.intellij.openapi.actionSystem.PlatformDataKeys |
| 7 | +import com.intellij.openapi.fileEditor.FileDocumentManager |
| 8 | +import com.intellij.packageChecker.service.PackageChecker |
| 9 | +import com.intellij.packageChecker.service.PackageService |
| 10 | +import com.intellij.psi.PsiManager |
| 11 | + |
| 12 | +class AutoDevDependenciesCheck : AnAction("Check dependencies has Issues") { |
| 13 | + override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT |
| 14 | + |
| 15 | + override fun update(e: AnActionEvent) { |
| 16 | + val project = e.project ?: return |
| 17 | + val editor = e.getData(PlatformDataKeys.EDITOR) ?: return |
| 18 | + val document = editor.document |
| 19 | + val file = FileDocumentManager.getInstance().getFile(document) ?: return |
| 20 | + |
| 21 | + val psiFile = PsiManager.getInstance(project).findFile(file) ?: return |
| 22 | + e.presentation.isEnabled = PackageService.getInstance(project).declaredDependencies(psiFile).isNotEmpty() |
| 23 | + } |
| 24 | + |
| 25 | + override fun actionPerformed(event: AnActionEvent) { |
| 26 | + val project = event.project ?: return |
| 27 | + val editor = event.getData(PlatformDataKeys.EDITOR) ?: return |
| 28 | + val document = editor.document |
| 29 | + val file = FileDocumentManager.getInstance().getFile(document) ?: return |
| 30 | + val psiFile = PsiManager.getInstance(project).findFile(file) ?: return |
| 31 | + |
| 32 | + val dependencies = PackageService.getInstance(project).declaredDependencies(psiFile) |
| 33 | + val checker = PackageChecker.getInstance(project) |
| 34 | + dependencies.forEach { |
| 35 | + checker.packageStatus(it.pkg) |
| 36 | + } |
| 37 | + } |
| 38 | +} |
0 commit comments