Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups #227

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions src/main/kotlin/org/move/cli/runConfigurations/AptosCommandLine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.move.cli.runConfigurations
import com.intellij.execution.configuration.EnvironmentVariablesData
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.configurations.PtyCommandLine
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.execution.ParametersListUtil
import java.nio.file.Path

data class AptosCommandLine(
Expand All @@ -12,17 +12,16 @@ data class AptosCommandLine(
val workingDirectory: Path? = null,
val environmentVariables: EnvironmentVariablesData = EnvironmentVariablesData.DEFAULT
) {
fun joinArgs(): String {
return StringUtil.join(subCommand?.split(" ").orEmpty() + arguments, " ")
}
val commandLineString: String
get() = ParametersListUtil.join(subCommand?.split(" ").orEmpty() + arguments)

fun toGeneralCommandLine(cliExePath: Path): GeneralCommandLine {
val generalCommandLine = GeneralCommandLine()
.withExePath(cliExePath.toString())
// subcommand can be null
.withParameters(subCommand?.split(" ").orEmpty())
.withParameters(this.arguments)
.withWorkDirectory(this.workingDirectory?.toString())
.withWorkingDirectory(this.workingDirectory)
.withCharset(Charsets.UTF_8)
this.environmentVariables.configureCommandLine(generalCommandLine, true)
return generalCommandLine
Expand All @@ -35,30 +34,11 @@ data class AptosCommandLine(
// subcommand can be null
.withParameters(subCommand?.split(" ").orEmpty())
.withParameters(this.arguments)
.withWorkDirectory(this.workingDirectory?.toString())
.withWorkingDirectory(this.workingDirectory)
.withCharset(Charsets.UTF_8)
// disables default coloring for stderr
.withRedirectErrorStream(true)
this.environmentVariables.configureCommandLine(generalCommandLine, true)
return generalCommandLine
}

// fun createRunConfiguration(
// moveProject: MoveProject,
// configurationName: String,
// save: Boolean
// ): RunnerAndConfigurationSettings {
// val project = moveProject.project
// val runConfiguration =
// AnyCommandConfigurationFactory.createTemplateRunConfiguration(
// project,
// configurationName,
// save = save
// )
// val anyCommandConfiguration = runConfiguration.configuration as AnyCommandConfiguration
// anyCommandConfiguration.command = this.joinArgs()
// anyCommandConfiguration.workingDirectory = this.workingDirectory
// anyCommandConfiguration.environmentVariables = this.environmentVariables
// return runConfiguration
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ abstract class CommandConfigurationBase(
}

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

val aptosPath = project.aptosExecPath ?: return configurationError("No Aptos CLI specified")
if (!aptosPath.exists()) {
Expand Down
12 changes: 2 additions & 10 deletions src/main/kotlin/org/move/cli/runConfigurations/aptos/Aptos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
networkUrl: String? = null,
connectionTimeoutSecs: Int = -1,
nodeApiKey: String? = null,
runner: CapturingProcessHandler.() -> ProcessOutput = {
runProcessWithGlobalProgress(
timeoutInMilliseconds = null
)
}
runner: CapturingProcessHandler.() -> ProcessOutput = { runProcessWithGlobalProgress() }
): RsProcessResult<ProcessOutput> {
val commandLine = AptosCommandLine(
subCommand = "move download",
Expand Down Expand Up @@ -184,11 +180,7 @@ data class Aptos(val cliLocation: Path, val parentDisposable: Disposable?): Disp
private fun executeCommandLine(
commandLine: AptosCommandLine,
listener: ProcessListener? = null,
runner: CapturingProcessHandler.() -> ProcessOutput = {
runProcessWithGlobalProgress(
timeoutInMilliseconds = null
)
}
runner: CapturingProcessHandler.() -> ProcessOutput = { runProcessWithGlobalProgress() }
): RsProcessResult<ProcessOutput> {
return commandLine
.toGeneralCommandLine(this.cliLocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class CommandConfigurationProducerBase:
templateConfiguration.name = cmdConf.configurationName

val commandLine = cmdConf.commandLine
templateConfiguration.command = commandLine.joinArgs()
templateConfiguration.command = commandLine.commandLineString
templateConfiguration.workingDirectory = commandLine.workingDirectory

var environment = commandLine.environmentVariables.envs
Expand All @@ -45,7 +45,7 @@ abstract class CommandConfigurationProducerBase:
val location = context.psiLocation ?: return false
val cmdConf = configFromLocation(location) ?: return false
return configuration.name == cmdConf.configurationName
&& configuration.command == cmdConf.commandLine.joinArgs()
&& configuration.command == cmdConf.commandLine.commandLineString
&& configuration.workingDirectory == cmdConf.commandLine.workingDirectory
&& configuration.environmentVariables == cmdConf.commandLine.environmentVariables
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
package org.move.cli.toolwindow

import com.intellij.diagnostic.PluginException
import com.intellij.execution.Location
import com.intellij.execution.PsiLocation
import com.intellij.execution.actions.RunContextAction
import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
import com.intellij.openapi.diagnostic.LogLevel.WARNING
import com.intellij.openapi.diagnostic.logger
import com.intellij.psi.NavigatablePsiElement
import com.intellij.psi.PsiElement
import com.intellij.util.PsiNavigateUtil
import org.move.cli.toolwindow.MoveProjectsTreeStructure.MoveSimpleNode
import org.move.ide.notifications.logOrShowBalloon
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.SwingUtilities
Expand All @@ -28,40 +15,18 @@ class ProjectsTreeMouseListener: MouseAdapter() {
val projectsTree = e.source as? MoveProjectsTree ?: return
val treeNode = projectsTree.selectionModel
.selectionPath?.lastPathComponent as? DefaultMutableTreeNode ?: return

val userNode = treeNode.userObject
when (userNode) {
is MoveSimpleNode.Entrypoint -> navigateToPsiElement(userNode.function)
is MoveSimpleNode.View -> navigateToPsiElement(userNode.function)
is MoveSimpleNode.Module -> navigateToPsiElement(userNode.module)
}
}

private fun executeContextAction(psiElement: PsiElement) {
val psiLocation =
try {
PsiLocation.fromPsiElement(psiElement) ?: return
} catch (e: PluginException) {
// TODO: figure out why this exception is raised
LOG.logOrShowBalloon(e.message, productionLevel = WARNING)
return
is MoveSimpleNode.Entrypoint -> {
PsiNavigateUtil.navigate(userNode.function)
}
is MoveSimpleNode.View -> {
PsiNavigateUtil.navigate(userNode.function)
}
is MoveSimpleNode.Module -> {
PsiNavigateUtil.navigate(userNode.module)
}
val dataContext =
SimpleDataContext.getSimpleContext(Location.DATA_KEY, psiLocation)
val actionEvent =
AnActionEvent.createFromDataContext(ActionPlaces.TOOLWINDOW_CONTENT, null, dataContext)

val executor = DefaultRunExecutor.getRunExecutorInstance()
RunContextAction(executor).actionPerformed(actionEvent)
}

private fun navigateToPsiElement(psiElement: PsiElement) {
val navigationElement = psiElement.navigationElement as? NavigatablePsiElement ?: return
if (navigationElement.canNavigate()) {
navigationElement.navigate(true)
}
}

companion object {
private val LOG = logger<ProjectsTreeMouseListener>()
}
}
Loading
Loading