Skip to content

Commit 85d9433

Browse files
authored
Merge pull request #4 from ahankinson/upgrade-color
Upgrade the colormath plugin and other dependencies
2 parents 347dc04 + 05dad7e commit 85d9433

File tree

53 files changed

+366
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+366
-310
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
uses: actions/setup-java@v4
5151
with:
5252
distribution: corretto
53-
java-version: 17
53+
java-version: 21
5454

5555
# Setup Gradle
5656
- name: Setup Gradle
@@ -115,7 +115,7 @@ jobs:
115115
uses: actions/setup-java@v4
116116
with:
117117
distribution: corretto
118-
java-version: 17
118+
java-version: 21
119119

120120
# Setup Gradle
121121
- name: Setup Gradle
@@ -174,7 +174,7 @@ jobs:
174174
uses: actions/setup-java@v4
175175
with:
176176
distribution: corretto
177-
java-version: 17
177+
java-version: 21
178178

179179
# Run Qodana inspections
180180
- name: Qodana - Code Inspection
@@ -206,7 +206,7 @@ jobs:
206206
uses: actions/setup-java@v4
207207
with:
208208
distribution: corretto
209-
java-version: 17
209+
java-version: 21
210210

211211
# Setup Gradle
212212
- name: Setup Gradle

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ jobs:
2929
uses: actions/setup-java@v4
3030
with:
3131
distribution: corretto
32-
java-version: 17
32+
java-version: 21
3333

3434
# Setup Gradle
3535
- name: Setup Gradle
36-
uses: gradle/actions/setup-gradle@v3
37-
with:
38-
gradle-home-cache-cleanup: true
36+
uses: gradle/actions/setup-gradle@v4
3937

4038
# Set environment variables
4139
- name: Export Properties

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ testData/
1010
todos/
1111
src/main/gen
1212
.intellijPlatform/
13+
.DS_Store

build.gradle.kts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22
import org.jetbrains.changelog.Changelog
33
import org.jetbrains.changelog.markdownToHTML
44
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
5+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
6+
57

68
fun properties(key: String) = project.findProperty(key).toString()
79

810
plugins {
911
// Java support
1012
id("java")
1113
// Kotlin support
12-
id("org.jetbrains.kotlin.jvm") version "1.9.25"
14+
id("org.jetbrains.kotlin.jvm") version "2.2.0"
1315
// Gradle IntelliJ Plugin
14-
id("org.jetbrains.intellij.platform") version "2.1.0"
16+
id("org.jetbrains.intellij.platform") version "2.6.0"
1517
// GrammarKit Plugin
1618
id("org.jetbrains.grammarkit") version "2022.3.2.2"
1719
// Gradle Changelog Plugin
18-
id("org.jetbrains.changelog") version "1.3.1"
20+
id("org.jetbrains.changelog") version "2.2.1"
1921
// Gradle Qodana Plugin
20-
id("org.jetbrains.qodana") version "0.1.13"
22+
id("org.jetbrains.qodana") version "2025.1.1"
2123
}
2224

2325
group = properties("pluginGroup")
@@ -37,14 +39,14 @@ dependencies {
3739

3840
plugins(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
3941

40-
instrumentationTools()
4142
pluginVerifier()
4243
testFramework(TestFrameworkType.Platform)
4344
}
4445

45-
implementation("com.github.ajalt.colormath:colormath:2.1.0")
46+
implementation("com.github.ajalt.colormath:colormath:3.6.1")
4647

47-
testImplementation("org.jetbrains.kotlin:kotlin-test:1.9.25")
48+
testImplementation("org.jetbrains.kotlin:kotlin-test:2.2.0")
49+
implementation("org.opentest4j:opentest4j:1.3.0")
4850
}
4951

5052
// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
@@ -61,13 +63,23 @@ changelog {
6163
}
6264

6365
// Configure Gradle Qodana Plugin - read more: https://github.com/JetBrains/gradle-qodana-plugin
66+
// Updating quodana marks these as red. I'm afraid I'm not familiar enough with how quodana works
67+
// to fix it.
68+
//
69+
// I did try updating to 2025.1.1 in the GH actions and it blew up if I updated it to the latest
70+
// version. So I set it back to the original, and maybe somebody can look at it later. -- AH July 2025
6471
qodana {
6572
cachePath.set(projectDir.resolve(".qodana").canonicalPath)
66-
reportPath.set(projectDir.resolve("build/reports/inspections").canonicalPath)
67-
saveReport.set(true)
68-
showReport.set(System.getenv("QODANA_SHOW_REPORT")?.toBoolean() ?: false)
73+
resultsPath.set(projectDir.resolve("build/reports/inspections").canonicalPath)
74+
// saveReport.set(true)
75+
// showReport.set(System.getenv("QODANA_SHOW_REPORT")?.toBoolean() ?: false)
6976
}
7077

78+
//qodanaScan {
79+
// resultsPath.set(projectDir.resolve("build/reports/inspections").canonicalPath)
80+
// arguments.set(listOf("--fail-threshold", "0"))
81+
//}
82+
7183
val generateGrammars = tasks.register("generateGrammars") {
7284
dependsOn("generateParser", "generateLexer")
7385
}
@@ -107,13 +119,16 @@ tasks {
107119
}
108120

109121
// Set the JVM compatibility versions
110-
properties("javaVersion").let {
111-
withType<JavaCompile> {
112-
sourceCompatibility = it
113-
targetCompatibility = it
114-
}
115-
withType<KotlinCompile> {
116-
kotlinOptions.jvmTarget = it
122+
val javaVersion = properties("javaVersion")
123+
124+
withType<JavaCompile>().configureEach {
125+
sourceCompatibility = javaVersion
126+
targetCompatibility = javaVersion
127+
}
128+
129+
withType<KotlinCompile>().configureEach {
130+
compilerOptions {
131+
jvmTarget.set(JvmTarget.fromTarget(javaVersion))
117132
}
118133
}
119134

@@ -165,9 +180,10 @@ tasks {
165180
val changelog = project.changelog // local variable for configuration cache compatibility
166181
// Get the latest available change notes from the changelog file
167182
changeNotes.set(provider {
168-
changelog.run {
169-
(getOrNull(properties("pluginVersion")) ?: getUnreleased()).withHeader(false)
170-
}.toHTML()
183+
changelog.renderItem(
184+
changelog.run {
185+
(getOrNull(properties("pluginVersion")) ?: getUnreleased()).withHeader(false)
186+
}, Changelog.OutputType.HTML)
171187
})
172188
}
173189

gradle.properties

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,34 @@
44
pluginGroup = io.github.elm-tooling
55
pluginName = Elm Language
66
# SemVer format -> https://semver.org
7-
pluginVersion = 5.1.0-beta1
7+
pluginVersion = 5.1.0-beta2
88

99
# We also set since and until build manually in `plugin.xml`. Keep them in sync!
1010
# See: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010590059-Why-pluginUntilBuild-is-mandatory
11-
pluginSinceBuild = 223
11+
pluginSinceBuild = 242
1212
# We do not set until build, as we want it to be compatible with new versions. See `plugin.xml`.
13-
pluginUntilBuild = 251.*
13+
pluginUntilBuild = 252.*
1414

1515
# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
1616
# 2022.3 and newer require JDK17
1717
# Upgrading 2021.3.2 to 2022.2.4 resulted in a lot of `Failed to load /src/elm.json: Manifest file not found: /src/elm.json` warnings
1818
# Upgrading to 2022.3.3 or newer results in massive test failure
1919
platformType = IC
20-
platformVersion = 2022.3
20+
platformVersion = 2024.2
2121

2222
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
2323
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
2424
platformPlugins =
2525

2626
# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
27-
javaVersion = 17
27+
javaVersion = 21
2828

2929
# Gradle Releases -> https://github.com/gradle/gradle/releases
30-
gradleVersion = 8.10.2
30+
gradleVersion = 8.14.3
3131

3232
# Since kotlin 1.4, stdlib dependency is added by default by kotlin gradle plugin.
3333
# But we don't need it because all necessary kotlin libraries are already bundled into IDE.
3434
# See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for more details
3535
kotlin.stdlib.default.dependency=false
3636

37-
# Since kotlin 1.8.20, Gradle Kotlin plugin may produce OOM during compilation
38-
# See https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#incremental-compilation
39-
# and https://youtrack.jetbrains.com/issue/KT-57757 for more details
40-
kotlin.incremental.useClasspathSnapshot=false
41-
4237
org.gradle.jvmargs=-Dkotlin.daemon.jvm.options=-Xmx2400m

src/main/kotlin/org/elm/ide/color/ElmColorProvider.kt

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package org.elm.ide.color
22

3-
import com.github.ajalt.colormath.*
3+
import com.github.ajalt.colormath.AngleUnit
4+
import com.github.ajalt.colormath.Color
5+
import com.github.ajalt.colormath.formatCssString
6+
import com.github.ajalt.colormath.hueOr
7+
import com.github.ajalt.colormath.model.HSL
8+
import com.github.ajalt.colormath.model.RGB
9+
import com.github.ajalt.colormath.parse
410
import com.intellij.openapi.command.CommandProcessor
511
import com.intellij.openapi.editor.ElementColorProvider
612
import com.intellij.psi.PsiDocumentManager
@@ -10,15 +16,14 @@ import org.elm.lang.core.psi.ElmTypes.LOWER_CASE_IDENTIFIER
1016
import org.elm.lang.core.psi.ElmTypes.REGULAR_STRING_PART
1117
import org.elm.lang.core.psi.elementType
1218
import org.elm.lang.core.psi.elements.*
13-
import java.awt.Color
19+
import java.awt.Color as AwtColor
1420
import java.util.Locale
15-
import kotlin.math.roundToInt
1621

1722
private val colorRegex = Regex("""#[0-9a-fA-F]{3,8}\b|\b(?:rgb|hsl)a?\([^)]+\)""")
1823

1924
/** Adds color blocks to the gutter when hex colors exist in a string */
2025
class ElmColorProvider : ElementColorProvider {
21-
override fun getColorFrom(element: PsiElement): Color? {
26+
override fun getColorFrom(element: PsiElement): AwtColor? {
2227
// Like all line markers, we should only provide colors on leaf elements
2328
if (element.firstChild != null) return null
2429
return getCssColorFromString(element) ?: getColorFromFuncCall(element)
@@ -27,31 +32,31 @@ class ElmColorProvider : ElementColorProvider {
2732
// Parse a CSS color from any string that contains one, since "1px solid #1a2b3c" probably
2833
// contains a color. We don't parse color keywords, since "The red fire truck" is probably not
2934
// supposed to contain a color.
30-
private fun getCssColorFromString(element: PsiElement): Color? {
35+
private fun getCssColorFromString(element: PsiElement): AwtColor? {
3136
if (element.elementType != REGULAR_STRING_PART) return null
3237
return colorRegex.find(element.text)
33-
?.let { runCatching { ConvertibleColor.fromCss(it.value) }.getOrNull() }
38+
?.let { runCatching { Color.parse(it.value) }.getOrNull() }
3439
?.toAwtColor()
3540
}
3641

37-
private fun getColorFromFuncCall(element: PsiElement): Color? {
42+
private fun getColorFromFuncCall(element: PsiElement): AwtColor? {
3843
val call = getFuncCall(element) ?: return null
3944
val color = runCatching {
4045
// color constructors will throw if the args are out of bounds
4146
when (call.name) {
4247
"rgb", "rgba" -> {
4348
if (call.a == null && call.name == "rgba") return null
4449
if (call.useFloat) RGB(call.c1, call.c2, call.c3, call.a ?: 1f)
45-
else RGB(call.c1.toInt(), call.c2.toInt(), call.c3.toInt(), call.a ?: 1f)
50+
else RGB.from255(call.c1.toInt(), call.c2.toInt(), call.c3.toInt(), ((call.a ?: 1f) * 255).toInt())
4651
}
47-
"rgb255" -> RGB(call.c1.toInt(), call.c2.toInt(), call.c3.toInt())
48-
"rgba255" -> RGB(call.c1.toInt(), call.c2.toInt(), call.c3.toInt(), call.a ?: return null)
52+
"rgb255" -> RGB.from255(call.c1.toInt(), call.c2.toInt(), call.c3.toInt())
53+
"rgba255" -> RGB.from255(call.c1.toInt(), call.c2.toInt(), call.c3.toInt(), ((call.a ?: 1f) * 255).toInt())
4954
"hsl" -> HSL(call.c1, call.c2, call.c3)
5055
"hsla" -> HSL(call.c1, call.c2, call.c3, call.a ?: return null)
5156
else -> return null
52-
}
57+
}.toAwtColor()
5358
}.getOrNull()
54-
return color?.toAwtColor()
59+
return color
5560
}
5661

5762
private fun getFuncCall(element: PsiElement): FuncCall? {
@@ -82,7 +87,7 @@ class ElmColorProvider : ElementColorProvider {
8287
)
8388
}
8489

85-
override fun setColorTo(element: PsiElement, color: Color) {
90+
override fun setColorTo(element: PsiElement, color: AwtColor) {
8691
if (element.firstChild != null) return
8792
val command = stringColorSettingRunnable(element, color)
8893
?: functionColorSettingRunnable(element, color)
@@ -99,13 +104,13 @@ class ElmColorProvider : ElementColorProvider {
99104
)
100105
}
101106

102-
private fun functionColorSettingRunnable(element: PsiElement, color: Color): Runnable? {
107+
private fun functionColorSettingRunnable(element: PsiElement, color: AwtColor): Runnable? {
103108
val funcCall = getFuncCall(element)
104109
val call = funcCall ?: return null
105110
return Runnable { setColorInFunctionCall(element, color, call) }
106111
}
107112

108-
private fun setColorInFunctionCall(element: PsiElement, color: Color, call: FuncCall) {
113+
private fun setColorInFunctionCall(element: PsiElement, color: AwtColor, call: FuncCall) {
109114
val factory = ElmPsiFactory(element.project)
110115

111116
fun ElmNumberConstantExpr.replace(c: Int, float: Boolean) {
@@ -115,9 +120,9 @@ class ElmColorProvider : ElementColorProvider {
115120

116121
if (call.name.startsWith("hsl")) {
117122
val hsl = color.toRGB().toHSL()
118-
call.args[0].replace(factory.createNumberConstant(hsl.h.toFloat().render()))
119-
call.args[1].replace(factory.createNumberConstant((hsl.s / 100f).render()))
120-
call.args[2].replace(factory.createNumberConstant((hsl.l / 100f).render()))
123+
call.args[0].replace(factory.createNumberConstant(hsl.hueOr(0).render()))
124+
call.args[1].replace(factory.createNumberConstant(hsl.s.render()))
125+
call.args[2].replace(factory.createNumberConstant(hsl.l.render()))
121126
} else {
122127
call.args[0].replace(color.red, call.useFloat)
123128
call.args[1].replace(color.green, call.useFloat)
@@ -127,12 +132,12 @@ class ElmColorProvider : ElementColorProvider {
127132
call.args.getOrNull(3)?.replace(color.alpha, true)
128133
}
129134

130-
private fun stringColorSettingRunnable(element: PsiElement, color: Color): Runnable? {
135+
private fun stringColorSettingRunnable(element: PsiElement, color: AwtColor): Runnable? {
131136
if (element.elementType != REGULAR_STRING_PART) return null
132137
return Runnable { setCssColorInString(element, color) }
133138
}
134139

135-
private fun setCssColorInString(element: PsiElement, color: Color) {
140+
private fun setCssColorInString(element: PsiElement, color: AwtColor) {
136141
val parent = element.parent as? ElmStringConstantExpr ?: return
137142
val match = colorRegex.find(element.text)?.value ?: return
138143

@@ -142,15 +147,15 @@ class ElmColorProvider : ElementColorProvider {
142147

143148
val newColor = when {
144149
match.startsWith("#") -> rgb.toHex()
145-
match.startsWith("rgb") -> rgb.toCssRgb(
146-
commas = commas,
147-
namedRgba = match.startsWith("rgba"),
148-
rgbPercent = percentCount > 1,
150+
match.startsWith("rgb") -> rgb.formatCssString(
151+
legacyFormat = commas,
152+
legacyName = match.startsWith("rgba"),
153+
unitsPercent = percentCount > 1,
149154
alphaPercent = percentCount == 1 || percentCount == 4
150155
)
151-
match.startsWith("hsl") -> rgb.toCssHsl(
152-
commas = commas,
153-
namedHsla = match.startsWith("hsla"),
156+
match.startsWith("hsl") -> rgb.toHSL().formatCssString(
157+
legacyFormat = commas,
158+
legacyName = match.startsWith("hsla"),
154159
hueUnit = when {
155160
"deg" in match -> AngleUnit.DEGREES
156161
"grad" in match -> AngleUnit.GRADIANS
@@ -189,14 +194,14 @@ private data class FuncCall(
189194
}
190195
}
191196

192-
fun com.github.ajalt.colormath.Color.toAwtColor(): Color = toRGB().let {
193-
Color(it.r, it.g, it.b, (it.a * 255).roundToInt())
197+
fun Color.toAwtColor(): AwtColor = toSRGB().let {
198+
AwtColor(it.r, it.g, it.b, it.alpha)
194199
}
195200

196-
private fun Color.toRGB() = RGB(red, green, blue, alpha / 255f)
201+
private fun AwtColor.toRGB() = RGB.from255(red, green, blue, alpha)
197202

198203
private fun Float.render(): String = when (this) {
199204
0f -> "0"
200205
1f -> "1"
201-
else -> String.format(Locale.ENGLISH, "%.4f", this).trimEnd('0').trimEnd('.')
206+
else -> String.format(Locale.ENGLISH, "%.2f", this).trimEnd('0').trimEnd('.')
202207
}

src/main/kotlin/org/elm/ide/docs/ElmDocumentationProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private fun documentationFor(element: ElmFieldType): String? = buildString {
217217
i { append("field") }
218218
append(" ", name)
219219
if (fieldTy !is TyUnknown) {
220-
append(": ", fieldTy.renderedText(true, false))
220+
append(": ", fieldTy.renderedText(linkify = true, withModule = false))
221221
}
222222
if (recordTy.alias != null) {
223223
i { append(" of record ") }

0 commit comments

Comments
 (0)