From 3815104c04c3bcd0ad49cb241d0d58fb38fdcb12 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Sat, 3 Feb 2024 12:21:58 +0300 Subject: [PATCH] support Sui in notifications --- .../settings/MoveProjectSettingsService.kt | 7 +++++++ ...t => InvalidBlockchainCliConfiguration.kt} | 20 ++++++++++++------- ...MoveProjectDetectedNotificationProvider.kt | 5 +++-- .../resources/META-INF/intellij-move-core.xml | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) rename src/main/kotlin/org/move/ide/notifications/{InvalidAptosExecNotification.kt => InvalidBlockchainCliConfiguration.kt} (69%) diff --git a/src/main/kotlin/org/move/cli/settings/MoveProjectSettingsService.kt b/src/main/kotlin/org/move/cli/settings/MoveProjectSettingsService.kt index 20f5fd4da..030a7d5ab 100644 --- a/src/main/kotlin/org/move/cli/settings/MoveProjectSettingsService.kt +++ b/src/main/kotlin/org/move/cli/settings/MoveProjectSettingsService.kt @@ -15,6 +15,7 @@ import org.move.cli.settings.aptos.AptosExec import org.move.openapiext.debugInProduction import org.move.stdext.exists import org.move.stdext.isExecutableFile +import org.move.stdext.toPathOrNull import java.nio.file.Path import kotlin.reflect.KProperty1 import kotlin.reflect.full.memberProperties @@ -34,6 +35,8 @@ interface MoveSettingsListener { enum class Blockchain { APTOS, SUI; + + fun name(): String = if (this == APTOS) "Aptos" else "Sui" } private const val settingsServiceName: String = "MoveProjectSettingsService_1" @@ -156,10 +159,14 @@ val Project.moveSettings: MoveProjectSettingsService get() = service() val Project.collapseSpecs: Boolean get() = this.moveSettings.state.foldSpecs +val Project.blockchain: Blockchain get() = this.moveSettings.state.blockchain + val Project.aptosExec: AptosExec get() = this.moveSettings.state.aptosExec() val Project.aptosPath: Path? get() = this.aptosExec.toPathOrNull() +val Project.suiPath: Path? get() = this.moveSettings.state.suiPath.toPathOrNull() + fun Path?.isValidExecutable(): Boolean { return this != null && this.toString().isNotBlank() diff --git a/src/main/kotlin/org/move/ide/notifications/InvalidAptosExecNotification.kt b/src/main/kotlin/org/move/ide/notifications/InvalidBlockchainCliConfiguration.kt similarity index 69% rename from src/main/kotlin/org/move/ide/notifications/InvalidAptosExecNotification.kt rename to src/main/kotlin/org/move/ide/notifications/InvalidBlockchainCliConfiguration.kt index 0c58d7573..f303fe1c4 100644 --- a/src/main/kotlin/org/move/ide/notifications/InvalidAptosExecNotification.kt +++ b/src/main/kotlin/org/move/ide/notifications/InvalidBlockchainCliConfiguration.kt @@ -5,15 +5,14 @@ import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.EditorNotificationPanel -import org.move.cli.settings.PerProjectMoveConfigurable -import org.move.cli.settings.aptosExec +import org.move.cli.settings.* import org.move.lang.isMoveFile import org.move.lang.isMoveTomlManifestFile import org.move.openapiext.common.isUnitTestMode import org.move.openapiext.showSettings -class InvalidAptosExecNotification(project: Project): MvEditorNotificationProvider(project), - DumbAware { +class InvalidBlockchainCliConfiguration(project: Project): MvEditorNotificationProvider(project), + DumbAware { override val VirtualFile.disablingKey: String get() = NOTIFICATION_STATUS_KEY + path @@ -24,11 +23,18 @@ class InvalidAptosExecNotification(project: Project): MvEditorNotificationProvid if (!project.isTrusted()) return null if (isNotificationDisabled(file)) return null - if (project.aptosExec.isValid()) return null -// if (project.aptosPath.isValidExecutable()) return null + val blockchain = project.blockchain + when (blockchain) { + Blockchain.APTOS -> { + if (project.aptosExec.isValid()) return null + } + Blockchain.SUI -> { + if (project.suiPath.isValidExecutable()) return null + } + } return EditorNotificationPanel().apply { - text = "Aptos binary path is not provided or invalid" + text = "${blockchain.name()} CLI path is not provided or invalid" createActionLabel("Configure") { project.showSettings() } diff --git a/src/main/kotlin/org/move/ide/notifications/NoMoveProjectDetectedNotificationProvider.kt b/src/main/kotlin/org/move/ide/notifications/NoMoveProjectDetectedNotificationProvider.kt index 24a034dc7..b1862c594 100644 --- a/src/main/kotlin/org/move/ide/notifications/NoMoveProjectDetectedNotificationProvider.kt +++ b/src/main/kotlin/org/move/ide/notifications/NoMoveProjectDetectedNotificationProvider.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.EditorNotificationPanel import org.move.cli.moveProjectsService +import org.move.cli.settings.blockchain import org.move.lang.isMoveFile import org.move.lang.isMoveTomlManifestFile import org.move.openapiext.common.isDispatchThread @@ -38,7 +39,7 @@ class NoMoveProjectDetectedNotificationProvider(project: Project): MvEditorNotif if (moveProjectsService.allProjects.isEmpty()) { // no move projects available return EditorNotificationPanel().apply { - text = "No Aptos projects found" + text = "No ${project.blockchain.name()} projects found" createActionLabel("Do not show again") { disableNotification(file) updateAllNotifications(project) @@ -48,7 +49,7 @@ class NoMoveProjectDetectedNotificationProvider(project: Project): MvEditorNotif if (moveProjectsService.findMoveProjectForFile(file) == null) { return EditorNotificationPanel().apply { - text = "File does not belong to any known Aptos project" + text = "File does not belong to any known ${project.blockchain.name()} project" createActionLabel("Do not show again") { disableNotification(file) updateAllNotifications(project) diff --git a/src/main/resources/META-INF/intellij-move-core.xml b/src/main/resources/META-INF/intellij-move-core.xml index 84d1be7ad..b1393d5c7 100644 --- a/src/main/resources/META-INF/intellij-move-core.xml +++ b/src/main/resources/META-INF/intellij-move-core.xml @@ -310,7 +310,7 @@ + implementation="org.move.ide.notifications.InvalidBlockchainCliConfiguration" />