diff --git a/docs/CHANGELOG.html b/docs/CHANGELOG.html
index 8f6eb05..09d3b44 100644
--- a/docs/CHANGELOG.html
+++ b/docs/CHANGELOG.html
@@ -4,6 +4,7 @@
Changelog
18.0.0
+
17.0.1
Fixes
diff --git a/src/main/java/com/mallowigi/visitors/DartVisitor.kt b/src/main/java/com/mallowigi/visitors/DartVisitor.kt
index 859f33e..2931913 100644
--- a/src/main/java/com/mallowigi/visitors/DartVisitor.kt
+++ b/src/main/java/com/mallowigi/visitors/DartVisitor.kt
@@ -29,8 +29,19 @@ package com.mallowigi.visitors
import com.intellij.codeInsight.daemon.impl.HighlightVisitor
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
+import com.intellij.psi.PsiWhiteSpace
+import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.util.PsiUtilCore
+import com.intellij.psi.util.childLeafs
+import com.intellij.psi.util.parentOfType
+import com.jetbrains.lang.dart.DartTokenTypes
+import com.jetbrains.lang.dart.psi.DartRecursiveVisitor
+import com.jetbrains.lang.dart.psi.DartReference
+import com.jetbrains.lang.dart.psi.DartVarDeclarationList
+import com.jetbrains.lang.dart.psi.DartVarInit
import com.mallowigi.search.ColorSearchEngine
+import org.rust.lang.core.psi.ext.descendantOfType
+import org.toml.lang.psi.ext.elementType
import java.awt.Color
class DartVisitor : ColorVisitor() {
@@ -38,7 +49,7 @@ class DartVisitor : ColorVisitor() {
"dart",
)
- private val allowedTypes = setOf("REGULAR_STRING_PART", "NUMBER")
+ private val allowedTypes = setOf("REGULAR_STRING_PART", "NUMBER", "REFERENCE_EXPRESSION")
override fun clone(): HighlightVisitor = DartVisitor()
@@ -49,8 +60,38 @@ class DartVisitor : ColorVisitor() {
val type = PsiUtilCore.getElementType(element).toString()
if (type !in allowedTypes) return null
- val value = element.text
- return ColorSearchEngine.getColor(value, this)
+ if (element is DartReference) {
+ if (element.parentOfType()?.resolve() == element.resolve()) return null
+ return element.readReferencedValue()
+ } else {
+ return ColorSearchEngine.getColor(element.text, this)
+ }
}
+ private fun createVisitor(): ColorInitializer = ColorInitializer(this)
+
+ private fun DartReference.readReferencedValue(): Color? {
+ if (this.descendantOfType { it.elementType == DartTokenTypes.IDENTIFIER } != null) {
+ val visitor = createVisitor()
+ this.resolve()?.let { visitor.visitElement(it) }
+ return visitor.result
+ }
+ return null
+ }
+}
+
+class ColorInitializer(private val visitor: DartVisitor) : DartRecursiveVisitor() {
+ var result: Color? = null
+
+ override fun visitElement(element: PsiElement) {
+ val filteredElements =
+ element.parentOfType()?.descendantOfType { true }?.childLeafs()
+ ?.filter { it !is PsiWhiteSpace && it.elementType != DartTokenTypes.EQ }
+ result = filteredElements?.windowed(4, 1)?.firstOrNull { window ->
+ Triple(window[0].elementType, window[0].text, window[2].elementType).let {
+ it.first == DartTokenTypes.IDENTIFIER && it.second == "Color" && it.third == DartTokenTypes.NUMBER
+ }
+ }?.elementAt(2)?.let { ColorSearchEngine.getColor(it.text, visitor) }
+ if (result == null) element.acceptChildren(this) else return
+ }
}