Skip to content

Commit 82886bd

Browse files
Undinyopox
authored andcommitted
INT: use dark theme for cargo expand if IDE uses dark theme
1 parent 6ca8cfb commit 82886bd

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/kotlin/org/rust/cargo/toolchain/tools/Cargo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ class Cargo(toolchain: RsToolchainBase, useWrapper: Boolean = false)
521521

522522
fun checkNeedInstallCargoExpand(project: Project): Boolean {
523523
val crateName = "cargo-expand"
524-
val minVersion = SemVer("v0.4.9", 0, 4, 9)
524+
val minVersion = SemVer("v1.0.0", 1, 0, 0)
525525
return checkNeedInstallBinaryCrate(
526526
project,
527527
crateName,

src/main/kotlin/org/rust/ide/intentions/RunCargoExpandIntention.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
package org.rust.ide.intentions
77

88
import com.intellij.codeInsight.intention.LowPriorityAction
9+
import com.intellij.ide.ui.LafManager
10+
import com.intellij.ide.ui.laf.UIThemeBasedLookAndFeelInfo
911
import com.intellij.openapi.editor.Editor
1012
import com.intellij.openapi.project.Project
1113
import com.intellij.psi.PsiElement
14+
import com.intellij.util.ui.UIUtil
1215
import org.rust.cargo.project.model.CargoProject
1316
import org.rust.cargo.project.workspace.CargoWorkspace
1417
import org.rust.cargo.toolchain.CargoCommandLine
@@ -40,9 +43,10 @@ class RunCargoExpandIntention : RsElementBaseIntentionAction<RunCargoExpandInten
4043
val (cargoProject, cargoTarget, crateRelativePath) = ctx
4144
if (checkNeedInstallCargoExpand(cargoProject.project)) return
4245

46+
val theme = if (isUnderDarkTheme()) "Dracula" else "GitHub"
4347
val additionalArguments = buildList<String> {
4448
add("--color=always")
45-
add("--theme=GitHub")
49+
add("--theme=$theme")
4650
add("--tests")
4751
if (crateRelativePath.isNotEmpty()) {
4852
add(crateRelativePath.removePrefix(PATH_SEPARATOR))
@@ -57,6 +61,11 @@ class RunCargoExpandIntention : RsElementBaseIntentionAction<RunCargoExpandInten
5761
).run(cargoProject, "Expand ${cargoTarget.normName}$crateRelativePath")
5862
}
5963

64+
private fun isUnderDarkTheme(): Boolean {
65+
val lookAndFeel = LafManager.getInstance().currentLookAndFeel
66+
return lookAndFeel is UIThemeBasedLookAndFeelInfo && lookAndFeel.theme.isDark || UIUtil.isUnderDarcula()
67+
}
68+
6069
companion object {
6170
private const val PATH_SEPARATOR: String = "::"
6271
}

0 commit comments

Comments
 (0)