Skip to content

Commit

Permalink
Merge pull request #165 from pontem-network/test-run-configuration
Browse files Browse the repository at this point in the history
Test tool window support
  • Loading branch information
mkurnikov authored Jun 27, 2024
2 parents a44c64e + 7b175d4 commit 546f268
Show file tree
Hide file tree
Showing 68 changed files with 809 additions and 1,062 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun gitTimestamp(): String {
}

val shortPlatformVersion = prop("shortPlatformVersion")
val codeVersion = "1.36.1"
val codeVersion = "1.37.0"

var pluginVersion = "$codeVersion.$shortPlatformVersion"
if (publishingChannel != "default") {
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/org/move/bytecode/AptosDecompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import com.intellij.openapi.vfs.*
import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import org.move.cli.runConfigurations.aptos.Aptos
import org.move.cli.settings.getAptosCli
import org.move.openapiext.pathAsPath
import org.move.openapiext.rootPluginDisposable
import org.move.openapiext.rootPath
import org.move.openapiext.rootPluginDisposable
import org.move.stdext.RsResult
import org.move.stdext.unwrapOrElse
import java.io.File
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/org/move/cli/MoveProjectsService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.externalSystem.autoimport.AutoImportProjectTracker
import com.intellij.openapi.externalSystem.autoimport.ExternalSystemProjectTracker
import com.intellij.openapi.module.ModuleUtilCore
import com.intellij.openapi.progress.ProcessCanceledException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@

package org.move.cli.externalLinter

import com.intellij.openapi.components.Service
import com.intellij.openapi.components.*
import com.intellij.openapi.components.Service.Level.PROJECT
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.components.StoragePathMacros
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import org.move.cli.externalLinter.MvExternalLinterProjectSettingsService.MvExternalLinterProjectSettings
import org.move.cli.settings.MvProjectSettingsServiceBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.intellij.openapi.project.Project
import org.move.cli.MoveProjectsService
import org.move.cli.MoveProjectsService.MoveRefreshStatus
import org.move.cli.moveProjectsService
import org.move.openapiext.saveAllDocuments

class MoveExternalSystemProjectAware(
private val project: Project
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/move/cli/manifest/AptosConfigYaml.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.move.cli.manifest

import kotlin.io.path.readText
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.error.YAMLException
import java.nio.file.Path
import kotlin.io.path.readText

data class AptosConfigYaml(
val configYamlPath: Path,
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/org/move/cli/manifest/MoveToml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.move.cli.manifest
import com.intellij.openapi.project.Project
import org.move.cli.*
import org.move.openapiext.*
import org.move.openapiext.common.isUnitTestMode
import org.move.stdext.chain
import org.toml.lang.psi.TomlFile
import java.nio.file.Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.intellij.task.*
import org.jetbrains.concurrency.Promise
import org.jetbrains.concurrency.resolvedPromise
import org.move.cli.moveProjectRoot
import org.move.cli.runConfigurations.aptos.any.AnyCommandConfiguration
import org.move.cli.runConfigurations.aptos.cmd.AptosCommandConfiguration
import org.move.ide.newProject.ProjectInitializationSteps
import org.move.openapiext.aptosCommandConfigurationsSettings
import org.move.openapiext.runManager
Expand All @@ -26,7 +26,7 @@ class AptosBuildTaskRunner: ProjectTaskRunner() {
): Promise<Result> {
val compileConfigurationWithSettings =
project.aptosCommandConfigurationsSettings()
.find { (it.configuration as AnyCommandConfiguration).command == "move compile" }
.find { (it.configuration as AptosCommandConfiguration).command == "move compile" }
?: ProjectInitializationSteps.createDefaultCompileConfiguration(project, false)
// val compileConfiguration =
// project.aptosCommandConfigurations().find { it.command.startsWith("move compile") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.openapi.util.text.StringUtil
import java.nio.file.Path

data class CliCommandLineArgs(
data class AptosCommandLine(
val subCommand: String?,
val arguments: List<String> = emptyList(),
val workingDirectory: Path? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.process.ProcessTerminatedListener
import com.intellij.execution.runners.ExecutionEnvironment
import org.move.cli.MoveFileHyperlinkFilter
import java.nio.file.Path

open class MoveCommandLineState(
execEnv: ExecutionEnvironment,
private val aptosPath: Path,
private val commandLine: CliCommandLineArgs
) :
CommandLineState(execEnv) {
abstract class AptosRunStateBase(
environment: ExecutionEnvironment,
val runConfiguration: CommandConfigurationBase,
val config: CommandConfigurationBase.CleanConfiguration.Ok
): CommandLineState(environment) {

val project = environment.project

init {
createFilters().forEach { addConsoleFilters(it) }
}
val commandLine: AptosCommandLine = config.cmd

override fun startProcess(): ProcessHandler {
val generalCommandLine =
commandLine.toGeneralCommandLine(aptosPath)
val generalCommandLine = commandLine.toGeneralCommandLine(config.aptosPath)
val handler = KillableColoredProcessHandler(generalCommandLine)
consoleBuilder.console.attachToProcess(handler)
ProcessTerminatedListener.attach(handler) // shows exit code upon termination
Expand All @@ -39,5 +33,17 @@ open class MoveCommandLineState(
}
return filters
}
}

class AptosRunState(
environment: ExecutionEnvironment,
runConfiguration: CommandConfigurationBase,
config: CommandConfigurationBase.CleanConfiguration.Ok
):
AptosRunStateBase(environment, runConfiguration, config) {

init {
createFilters().forEach { consoleBuilder.addFilter(it) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,35 @@ package org.move.cli.runConfigurations

import com.intellij.execution.Executor
import com.intellij.execution.configuration.EnvironmentVariablesData
import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.LocatableConfigurationBase
import com.intellij.execution.configurations.RunConfigurationWithSuppressedDefaultDebugAction
import com.intellij.execution.configurations.RuntimeConfigurationError
import com.intellij.execution.configurations.*
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.notification.NotificationType
import com.intellij.openapi.options.advanced.AdvancedSettings
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.NlsContexts
import com.intellij.util.execution.ParametersListUtil
import org.jdom.Element
import org.move.cli.readPath
import org.move.cli.readString
import org.move.cli.runConfigurations.CommandConfigurationBase.CleanConfiguration.Companion.configurationError
import org.move.cli.runConfigurations.legacy.MoveCommandConfiguration
import org.move.cli.runConfigurations.test.AptosTestConsoleProperties.Companion.TEST_TOOL_WINDOW_SETTING_KEY
import org.move.cli.runConfigurations.test.AptosTestRunState
import org.move.cli.settings.aptosExecPath
import org.move.cli.writePath
import org.move.cli.writeString
import org.move.ide.notifications.MvNotifications
import org.move.stdext.exists
import java.nio.file.Path

abstract class CommandConfigurationBase(
project: Project,
factory: ConfigurationFactory
):
LocatableConfigurationBase<MoveCommandLineState>(project, factory),
LocatableConfigurationBase<AptosRunState>(project, factory),
RunConfigurationWithSuppressedDefaultDebugAction {

var command: String = ""
var workingDirectory: Path? = null
var environmentVariables: EnvironmentVariablesData = EnvironmentVariablesData.DEFAULT

abstract fun getCliPath(project: Project): Path?

override fun writeExternal(element: Element) {
super.writeExternal(element)
element.writeString("command", this.command)
Expand All @@ -48,49 +45,55 @@ abstract class CommandConfigurationBase(
this.environmentVariables = EnvironmentVariablesData.readExternal(element)
}

override fun getState(executor: Executor, environment: ExecutionEnvironment): MoveCommandLineState? {
@Throws(RuntimeConfigurationException::class)
override fun checkConfiguration() {
val config = clean()
when (config) {
is CleanConfiguration.Ok -> {
return MoveCommandLineState(environment, config.cliPath, config.commandLine)
}
is CleanConfiguration.Err -> {
val errorMessage = config.error.messageHtml.toString()
MvNotifications.pluginNotifications()
.createNotification("Run Configuration error", errorMessage, NotificationType.ERROR)
.notify(project)
return null
}
if (config is CleanConfiguration.Err) {
throw config.error
}
}

override fun getState(executor: Executor, environment: ExecutionEnvironment): AptosRunStateBase? {
val config = clean().ok ?: return null
return if (showTestToolWindow(config.cmd)) {
AptosTestRunState(environment, this, config)
} else {
AptosRunState(environment, this, config)
}
// return clean().ok
// ?.let { config ->
// MoveCommandLineState(environment, config.cliPath, config.commandLine)
// }
}

fun clean(): CleanConfiguration {
val workingDirectory = workingDirectory
?: return configurationError("No working directory specified")
val parsedCommand = MoveCommandConfiguration.ParsedCommand.parse(command)
val (subcommand, arguments) = parseAptosCommand(command)
?: return configurationError("No subcommand specified")

val cliLocation =
this.getCliPath(project) ?: return configurationError("No blockchain CLI specified")
if (!cliLocation.exists()) {
return configurationError("Invalid CLI location: $cliLocation")
val aptosPath = project.aptosExecPath ?: return configurationError("No Aptos CLI specified")
if (!aptosPath.exists()) {
return configurationError("Invalid Aptos CLI location: $aptosPath")
}
val commandLine =
CliCommandLineArgs(
parsedCommand.command,
parsedCommand.additionalArguments,
AptosCommandLine(
subcommand,
arguments,
workingDirectory,
environmentVariables
)
return CleanConfiguration.Ok(cliLocation, commandLine)
return CleanConfiguration.Ok(aptosPath, commandLine)
}

protected fun showTestToolWindow(commandLine: AptosCommandLine): Boolean =
when {
!AdvancedSettings.getBoolean(TEST_TOOL_WINDOW_SETTING_KEY) -> false
commandLine.subCommand != "move test" -> false
// "--nocapture" in commandLine.additionalArguments -> false
// Cargo.TEST_NOCAPTURE_ENABLED_KEY.asBoolean() -> false
// else -> !hasRemoteTarget
else -> true
}

sealed class CleanConfiguration {
class Ok(val cliPath: Path, val commandLine: CliCommandLineArgs): CleanConfiguration()
class Ok(val aptosPath: Path, val cmd: AptosCommandLine): CleanConfiguration()
class Err(val error: RuntimeConfigurationError): CleanConfiguration()

val ok: Ok? get() = this as? Ok
Expand All @@ -101,4 +104,20 @@ abstract class CommandConfigurationBase(
)
}
}

companion object {
fun parseAptosCommand(rawAptosCommand: String): Pair<String, List<String>>? {
val args = ParametersListUtil.parse(rawAptosCommand)
val rootCommand = args.firstOrNull() ?: return null
return if (rootCommand == "move") {
val subcommand = args.drop(1).firstOrNull() ?: return null
val command = "move $subcommand"
val additionalArguments = args.drop(2)
Pair(command, additionalArguments)
} else {
val additionalArguments = args.drop(1)
Pair(rootCommand, additionalArguments)
}
}
}
}
22 changes: 10 additions & 12 deletions src/main/kotlin/org/move/cli/runConfigurations/aptos/Aptos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.move.cli.Consts
import org.move.cli.MoveProject
import org.move.cli.externalLinter.ExternalLinter
import org.move.cli.externalLinter.externalLinterSettings
import org.move.cli.runConfigurations.CliCommandLineArgs
import org.move.cli.runConfigurations.AptosCommandLine
import org.move.cli.settings.moveSettings
import org.move.openapiext.*
import org.move.openapiext.common.isUnitTestMode
Expand Down Expand Up @@ -41,10 +41,9 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
if (!isUnitTestMode) {
checkIsBackgroundThread()
}
val commandLine = CliCommandLineArgs(
"move",
val commandLine = AptosCommandLine(
"move init",
listOf(
"init",
"--name", packageName,
"--assume-yes"
),
Expand All @@ -67,10 +66,9 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
): RsProcessResult<Unit> {
if (project.moveSettings.fetchAptosDeps) {
val commandLine =
CliCommandLineArgs(
subCommand = "move",
AptosCommandLine(
subCommand = "move compile",
arguments = listOfNotNull(
"compile",
"--skip-fetch-latest-git-deps".takeIf { skipLatest }
),
workingDirectory = projectDir
Expand All @@ -89,7 +87,7 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
// val checkCommand = if (useClippy) "clippy" else "check"
val extraArguments = ParametersListUtil.parse(args.extraArguments)
val commandLine =
CliCommandLineArgs(
AptosCommandLine(
"move compile",
buildList {
// add("--message-format=json")
Expand Down Expand Up @@ -134,7 +132,7 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
)
}
): RsProcessResult<ProcessOutput> {
val commandLine = CliCommandLineArgs(
val commandLine = AptosCommandLine(
subCommand = "move download",
arguments = buildList {
add("--account"); add(accountAddress)
Expand All @@ -156,7 +154,7 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
fun decompileDownloadedPackage(downloadedPackagePath: Path): RsProcessResult<ProcessOutput> {
val bytecodeModulesPath =
downloadedPackagePath.resolve("bytecode_modules").toAbsolutePath().toString()
val commandLine = CliCommandLineArgs(
val commandLine = AptosCommandLine(
subCommand = "move decompile",
arguments = buildList {
add("--package-path"); add(bytecodeModulesPath)
Expand All @@ -172,7 +170,7 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
outputDir: String?,
): RsProcessResult<ProcessOutput> {
val fileRoot = Paths.get(bytecodeFilePath).parent
val commandLine = CliCommandLineArgs(
val commandLine = AptosCommandLine(
subCommand = "move decompile",
arguments = buildList {
add("--bytecode-path"); add(bytecodeFilePath)
Expand All @@ -188,7 +186,7 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
}

private fun executeCommandLine(
commandLine: CliCommandLineArgs,
commandLine: AptosCommandLine,
listener: ProcessListener? = null,
runner: CapturingProcessHandler.() -> ProcessOutput = {
runProcessWithGlobalProgress(
Expand Down
Loading

0 comments on commit 546f268

Please sign in to comment.