From 3d2e40aec1f5ffe7898d3b2d9df32f9530917976 Mon Sep 17 00:00:00 2001 From: JiHwan Oh Date: Sat, 28 Dec 2024 18:40:35 +0900 Subject: [PATCH] fix mise toolwindow toolname showing --- .../mise/core/command/MiseCommandLine.kt | 52 +++++++++++-------- .../core/toolwindow/nodes/MiseToolNode.kt | 2 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/modules/core/src/main/kotlin/com/github/l34130/mise/core/command/MiseCommandLine.kt b/modules/core/src/main/kotlin/com/github/l34130/mise/core/command/MiseCommandLine.kt index 3f3903a6..bd99e773 100644 --- a/modules/core/src/main/kotlin/com/github/l34130/mise/core/command/MiseCommandLine.kt +++ b/modules/core/src/main/kotlin/com/github/l34130/mise/core/command/MiseCommandLine.kt @@ -7,13 +7,13 @@ import com.intellij.execution.ExecutionException import com.intellij.execution.configurations.GeneralCommandLine import com.intellij.execution.util.ExecUtil import com.intellij.openapi.diagnostic.Logger +import com.intellij.util.concurrency.annotations.RequiresBackgroundThread internal class MiseCommandLine( private val workDir: String? = null, private val configEnvironment: String? = null, ) { - inline fun runCommandLine(vararg params: String): Result = - runCommandLine(params.toList()) + inline fun runCommandLine(vararg params: String): Result = runCommandLine(params.toList()) inline fun runCommandLine(params: List): Result { val miseVersion = getMiseVersion() @@ -44,21 +44,25 @@ internal class MiseCommandLine( } } - private fun runCommandLine(commandLineArgs: List, transform: (String) -> T): Result { + private fun runCommandLine( + commandLineArgs: List, + transform: (String) -> T, + ): Result { val generalCommandLine = GeneralCommandLine(commandLineArgs).withWorkDirectory(workDir) - val processOutput = try { - logger.debug("Running command: $commandLineArgs") - ExecUtil.execAndGetOutput(generalCommandLine, 5000) - } catch (e: ExecutionException) { - logger.info("Failed to execute command. (command=$generalCommandLine)", e) - return Result.failure( - MiseCommandLineNotFoundException( - generalCommandLine, - e.message ?: "Failed to execute command.", - e + val processOutput = + try { + logger.debug("Running command: $commandLineArgs") + ExecUtil.execAndGetOutput(generalCommandLine, 5000) + } catch (e: ExecutionException) { + logger.info("Failed to execute command. (command=$generalCommandLine)", e) + return Result.failure( + MiseCommandLineNotFoundException( + generalCommandLine, + e.message ?: "Failed to execute command.", + e, + ), ) - ) - } + } if (!processOutput.isExitCodeSet) { when { @@ -89,18 +93,20 @@ internal class MiseCommandLine( } companion object { + @RequiresBackgroundThread fun getMiseVersion(): MiseVersion { val miseCommandLine = MiseCommandLine() val versionString = miseCommandLine.runCommandLine(listOf("mise", "version")) { it } - val miseVersion = versionString.fold( - onSuccess = { - MiseVersion.parse(it) - }, - onFailure = { _ -> - MiseVersion(0, 0, 0) - } - ) + val miseVersion = + versionString.fold( + onSuccess = { + MiseVersion.parse(it) + }, + onFailure = { _ -> + MiseVersion(0, 0, 0) + }, + ) return miseVersion } diff --git a/modules/core/src/main/kotlin/com/github/l34130/mise/core/toolwindow/nodes/MiseToolNode.kt b/modules/core/src/main/kotlin/com/github/l34130/mise/core/toolwindow/nodes/MiseToolNode.kt index aa760863..b41d535d 100644 --- a/modules/core/src/main/kotlin/com/github/l34130/mise/core/toolwindow/nodes/MiseToolNode.kt +++ b/modules/core/src/main/kotlin/com/github/l34130/mise/core/toolwindow/nodes/MiseToolNode.kt @@ -49,7 +49,7 @@ class MiseToolNode( toolInfo, AllIcons.General.Gear, ) { - override fun displayName(): String = "$toolName@${toolInfo.version}" + override fun displayName(): String = "${toolName.value}@${toolInfo.version}" override fun isActive(): Boolean = toolInfo.active