Skip to content

Commit

Permalink
remove creation of default compile configuration and default build task
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Oct 29, 2024
1 parent c1d1034 commit e0b259c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.move.cli.runConfigurations.aptos.Aptos
import org.move.cli.settings.getAptosCliDisposedOnFileChange
import org.move.ide.notifications.showDebugBalloon
import org.move.ide.notifications.updateAllNotifications
import org.move.openapiext.openFile
import org.move.openapiext.openFileInEditor
import org.move.openapiext.pathAsPath
import org.move.stdext.RsResult
import org.move.stdext.unwrapOrElse
Expand Down Expand Up @@ -60,7 +60,8 @@ class AptosBytecodeNotificationProvider(project: Project): EditorNotificationPro
// file exists
text = "Decompiled source file exists"
createActionLabel("Open source file") {
project.openFile(existingDecompiledFile)
project.openFileInEditor(existingDecompiledFile)
updateAllNotifications(project)
}
return@apply
}
Expand All @@ -70,15 +71,16 @@ class AptosBytecodeNotificationProvider(project: Project): EditorNotificationPro
if (decompilationFailed) {
text = "Decompilation command failed"
createActionLabel("Try again") {
val virtualFile = decompilationTask.runWithProgress()
val decompiledFile = decompilationTask.runWithProgress()
.unwrapOrElse {
// something went wrong with the decompilation command again
project.showDebugBalloon("Error with decompilation process", it, ERROR)
return@createActionLabel
}

properties.setValue(decompilationFailedKey, false)
project.openFile(virtualFile)
project.openFileInEditor(decompiledFile, true)

updateAllNotifications(project)
}
} else {
Expand All @@ -92,8 +94,9 @@ class AptosBytecodeNotificationProvider(project: Project): EditorNotificationPro
// something went wrong with the decompilation command
properties.setValue(decompilationFailedKey, true)
} else {
project.openFile(decompiledFile)
project.openFileInEditor(decompiledFile)
}

updateAllNotifications(project)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.move.bytecode.AptosBytecodeNotificationProvider.DecompilationModalTas
import org.move.cli.settings.getAptosCli
import org.move.ide.MoveIcons
import org.move.ide.notifications.showBalloon
import org.move.openapiext.openFile
import org.move.openapiext.openFileInEditor
import org.move.stdext.unwrapOrElse
import java.util.*

Expand All @@ -27,7 +27,7 @@ class DecompileAptosMvFileAction: DumbAwareAction("Decompile .mv File", null, Mo
project.showBalloon("Error with decompilation process", it, ERROR)
return
}
project.openFile(decompiledFile)
project.openFileInEditor(decompiledFile)
}

override fun update(e: AnActionEvent) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.intellij.platform.PlatformProjectOpenProcessor
import com.intellij.projectImport.ProjectOpenProcessor
import org.move.cli.MvConstants
import org.move.ide.MoveIcons
import org.move.ide.notifications.updateAllNotifications
import org.move.openapiext.openFileInEditor
import javax.swing.Icon

/// called only when IDE opens a project from existing sources
Expand All @@ -35,11 +37,14 @@ class MoveLangProjectOpenProcessor: ProjectOpenProcessor() {
StartupManager.getInstance(project)
.runWhenProjectIsInitialized(object: DumbAwareRunnable {
override fun run() {
ProjectInitializationSteps.createDefaultCompileConfigurationIfNotExists(project)
// NOTE:
// this cannot be moved to a ProjectActivity, as Move.toml files
// are not created by the time those activities are executed
ProjectInitializationSteps.openMoveTomlInEditor(project)
val moveTomlFile = project.guessMoveTomlFile()
if (moveTomlFile != null) {
project.openFileInEditor(moveTomlFile, true)
}
updateAllNotifications(project)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.move.cli.settings.aptos.AptosExecType
import org.move.cli.settings.moveSettings
import org.move.ide.MoveIcons
import org.move.openapiext.computeWithCancelableProgress
import org.move.openapiext.openFileInEditor
import org.move.stdext.unwrapOrThrow

data class AptosProjectConfig(
Expand Down Expand Up @@ -45,7 +46,7 @@ class MoveProjectGenerator: DirectoryProjectGeneratorBase<AptosProjectConfig>(),
AptosExecType.aptosExecPath(projectConfig.aptosExecType, projectConfig.localAptosPath)
?: error("validated before")
val aptos = Aptos(aptosPath, disposable)
val manifestFile =
val moveTomlFile =
project.computeWithCancelableProgress("Generating Aptos project...") {
val manifestFile =
aptos.init(
Expand All @@ -62,11 +63,10 @@ class MoveProjectGenerator: DirectoryProjectGeneratorBase<AptosProjectConfig>(),
it.localAptosPath = projectConfig.localAptosPath
}

ProjectInitializationSteps.createDefaultCompileConfigurationIfNotExists(project)
// NOTE:
// this cannot be moved to a ProjectActivity, as Move.toml files
// are not created by the time those activities are executed
ProjectInitializationSteps.openMoveTomlInEditor(project, manifestFile)
project.openFileInEditor(moveTomlFile)

project.moveProjectsService.scheduleProjectsRefresh("After `aptos move init`")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,18 @@
package org.move.ide.newProject

import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import org.move.cli.MvConstants
import org.move.cli.runConfigurations.aptos.AptosTransactionConfigurationType
import org.move.cli.runConfigurations.aptos.cmd.AptosCommandConfiguration
import org.move.cli.runConfigurations.aptos.cmd.AptosCommandConfigurationFactory
import org.move.ide.notifications.updateAllNotifications
import org.move.openapiext.addRunConfiguration
import org.move.openapiext.contentRoots
import org.move.openapiext.openFile
import org.move.openapiext.runManager
import org.move.stdext.toPath
import org.move.openapiext.openFileInEditor

object ProjectInitializationSteps {
fun openMoveTomlInEditor(project: Project, moveTomlFile: VirtualFile? = null) {
val file =
moveTomlFile ?: run {
val packageRoot = project.contentRoots.firstOrNull()
if (packageRoot != null) {
val manifest = packageRoot.findChild(MvConstants.MANIFEST_FILE)
return@run manifest
}
return@run null
}
if (file != null) {
project.openFile(file)
}
updateAllNotifications(project)
}

fun createDefaultCompileConfigurationIfNotExists(project: Project) {
if (project.runManager.allConfigurationsList.isEmpty()) {
createDefaultCompileConfiguration(project, true)
}
}

fun createDefaultCompileConfiguration(project: Project, selected: Boolean): RunnerAndConfigurationSettings {
val runConfigurationAndWithSettings =
project.addRunConfiguration(selected) { runManager, _ ->
val configurationFactory = AptosTransactionConfigurationType.getInstance()
.configurationFactories.find { it is AptosCommandConfigurationFactory }
?: error("AnyCommandConfigurationFactory should be present in the factories list")
runManager.createConfiguration("Compile Project", configurationFactory)
.apply {
(configuration as? AptosCommandConfiguration)?.apply {
command = "move compile"
workingDirectory = project.basePath?.toPath()
}
}
}
return runConfigurationAndWithSettings
fun Project.guessMoveTomlFile(): VirtualFile? {
val packageRoot = this.contentRoots.firstOrNull()
if (packageRoot != null) {
val manifest = packageRoot.findChild(MvConstants.MANIFEST_FILE)
return manifest
}
return null
}

11 changes: 4 additions & 7 deletions src/main/kotlin/org/move/openapiext/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package org.move.openapiext
import com.intellij.execution.RunManager
import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.ide.util.PsiNavigationSupport
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import org.move.cli.runConfigurations.aptos.cmd.AptosCommandConfiguration
import org.move.ide.notifications.updateAllNotifications
import org.move.openapiext.common.isHeadlessEnvironment

val Project.runManager: RunManager get() = RunManager.getInstance(this)
Expand Down Expand Up @@ -41,14 +41,11 @@ fun Project.addRunConfiguration(
return runnerAndConfigurationSettings
}

data class GeneratedFilesHolder(val manifest: VirtualFile)

fun Project.openFile(file: VirtualFile) = openFiles(GeneratedFilesHolder(file))

fun Project.openFiles(files: GeneratedFilesHolder) = invokeLater {
fun Project.openFileInEditor(file: VirtualFile, requestFocus: Boolean = true) {
if (!isHeadlessEnvironment) {
val navigation = PsiNavigationSupport.getInstance()
navigation.createNavigatable(this, files.manifest, -1).navigate(false)
val navigatable = PsiNavigationSupport.getInstance().createNavigatable(this, file, -1)
navigatable.navigate(requestFocus)
}
}

2 changes: 0 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@
<additionalTextAttributes scheme="Default" file="colors/MoveDefault.xml" />
<additionalTextAttributes scheme="Darcula" file="colors/MoveDarcula.xml" />

<projectTaskRunner implementation="org.move.cli.runConfigurations.AptosBuildTaskRunner" />

<!-- Project Creation -->
<projectOpenProcessor id="Move" implementation="org.move.ide.newProject.MoveLangProjectOpenProcessor" />
<directoryProjectGenerator implementation="org.move.ide.newProject.MoveProjectGenerator" />
Expand Down

0 comments on commit e0b259c

Please sign in to comment.