Skip to content

Commit

Permalink
add raw command viewer to run / view dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Mar 24, 2024
1 parent 39c308b commit c7dd768
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ abstract class CommandConfigurationHandler {

fun generateCommand(
moveProject: MoveProject,
profileName: String,
functionCall: FunctionCall
functionCall: FunctionCall,
signerAccount: String?,
): RsResult<String, String> {
val functionId = functionCall.functionId(moveProject) ?: return RsResult.Err("FunctionId is null")

Expand All @@ -68,13 +68,12 @@ abstract class CommandConfigurationHandler {

val commandArguments = listOf(
subCommand.split(' '),
listOf("--profile", profileName),
listOf("--profile", signerAccount),
listOf("--function-id", functionId),
typeParams,
params
).flatten()
val command = commandArguments.joinToString(" ")
println("Command is $command")
return RsResult.Ok(command)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.intellij.openapi.ui.MessageType
import com.intellij.openapi.util.Disposer
import com.intellij.ui.JBColor
import com.intellij.ui.dsl.builder.*
import com.intellij.xdebugger.impl.ui.TextViewer
import org.move.cli.MoveProject
import org.move.cli.moveProjectsService
import org.move.stdext.RsResult
Expand All @@ -25,7 +26,7 @@ data class MoveProjectItem(val moveProject: MoveProject) {
}

class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(
private val handler: CommandConfigurationHandler,
private val commandHandler: CommandConfigurationHandler,
private var moveProject: MoveProject,
) :
SettingsEditor<T>() {
Expand All @@ -37,8 +38,9 @@ class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(

private val projectComboBox: ComboBox<MoveProjectItem> = ComboBox()
private val accountTextField = JTextField()
private val rawCommandField = TextViewer("", project, true)

private val functionParametersPanel = FunctionParametersPanel(handler, moveProject)
private val functionParametersPanel = FunctionParametersPanel(commandHandler, moveProject)

private val errorLabel = JLabel("")

Expand All @@ -57,6 +59,8 @@ class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(
functionParametersPanel.addFunctionCallListener(object : FunctionParameterPanelListener {
override fun functionParametersChanged(functionCall: FunctionCall) {
editor.functionCall = functionCall
editor.rawCommandField.text =
commandHandler.generateCommand(moveProject, functionCall, signerAccount).unwrapOrNull() ?: ""
}
})
functionParametersPanel.setMoveProjectAndCompletionVariants(moveProject)
Expand All @@ -72,7 +76,7 @@ class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(
return
}

val res = handler.parseCommand(moveProject, s.command)
val res = commandHandler.parseCommand(moveProject, s.command)
val (profile, functionCall) = when (res) {
is RsResult.Ok -> res.ok
is RsResult.Err -> {
Expand All @@ -91,19 +95,8 @@ class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(

override fun applyEditorTo(s: T) {
functionParametersPanel.fireChangeEvent()
val moveProject = moveProject
val profile = signerAccount
val functionCall = functionCall

s.command = rawCommandField.text
s.moveProjectFromWorkingDirectory = moveProject
if (profile != null && functionCall != null) {
s.command =
handler.generateCommand(moveProject, profile, functionCall).unwrapOrNull() ?: ""
} else {
s.command = ""
}

println("Command in applyEditorTo = ${s.command}")
}

override fun disposeEditor() {
Expand All @@ -117,8 +110,6 @@ class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(
row {
cell(editorPanel)
.align(AlignX.FILL + AlignY.FILL)
// .verticalAlign(VerticalAlign.FILL)
// .horizontalAlign(HorizontalAlign.FILL)
}
}
return DumbService.getInstance(project).wrapGently(outerPanel, this)
Expand All @@ -130,7 +121,6 @@ class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(
row("Project") {
cell(projectComboBox)
.align(AlignX.FILL)
// .horizontalAlign(HorizontalAlign.FILL)
.columns(COLUMNS_LARGE)
.whenItemSelectedFromUi {
moveProject = it.moveProject
Expand All @@ -140,7 +130,6 @@ class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(
row("Account") {
cell(accountTextField)
.align(AlignX.FILL)
// .horizontalAlign(HorizontalAlign.FILL)
.whenTextChangedFromUi {
signerAccount = it
}
Expand All @@ -149,8 +138,11 @@ class FunctionCallConfigurationEditor<T : FunctionCallConfigurationBase>(
row {
cell(functionParametersPanel)
.align(AlignX.FILL + AlignY.FILL)
// .verticalAlign(VerticalAlign.FILL)
// .horizontalAlign(HorizontalAlign.FILL)
}
separator()
row("Raw") {
cell(rawCommandField)
.align(AlignX.FILL)
}
}
editorPanel.registerValidators(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class FunctionParametersPanel(
private lateinit var valueParams: MutableMap<String, FunctionCallParam?>

private val functionItemField = CompletionTextField(project, "", emptyList())
private val functionApplyButton = JButton("Select function")
private val functionApplyButton = JButton("Select and refresh UI")

private val functionValidator: ComponentValidator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ profiles:

check(profile == expectedProfile) { "Unexpected profile $profile" }

val generatedCommand = handler.generateCommand(moveProject, profile, functionCall).unwrap()
val generatedCommand = handler.generateCommand(moveProject, functionCall, profile).unwrap()
check(command == generatedCommand) {
"Commands are not equal. \n" +
"Original: $command\n" +
Expand Down

0 comments on commit c7dd768

Please sign in to comment.