Skip to content

Commit a963624

Browse files
FoxKianalerno
authored andcommitted
Implement ElementColorProvider
- added C3ElementColorProvider to display colors represented by a hexadecimal integer
1 parent 9967bce commit a963624

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.c3lang.intellij
2+
3+
import com.intellij.openapi.editor.ElementColorProvider
4+
import com.intellij.psi.PsiElement
5+
import com.intellij.ui.JBColor
6+
import org.c3lang.intellij.psi.C3LiteralExpr
7+
import java.awt.Color
8+
9+
class C3ElementColorProvider : ElementColorProvider
10+
{
11+
override fun getColorFrom(element: PsiElement): Color?
12+
{
13+
if (element !is C3LiteralExpr) return null
14+
if (!element.text.matches(Regex("0x([\\dA-Fa-f]{8}|[\\dA-Fa-f]{6})"))) return null
15+
16+
val rgb = element.text.substring(2).toLong(16)
17+
18+
return JBColor(rgb.toInt(), rgb.toInt())
19+
}
20+
21+
override fun setColorTo(element: PsiElement, color: Color)
22+
{
23+
}
24+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
<codeInsight.lineMarkerProvider language="C3"
7676
implementationClass="org.c3lang.intellij.C3LineMarkerProvider" />
7777

78+
<colorProvider implementation="org.c3lang.intellij.C3ElementColorProvider" />
79+
7880
<!--<gotoDeclarationHandler implementation="org.c3lang.intellij.actions.C3GotoDeclarationHandler"/>-->
7981

8082
<lang.findUsagesProvider language="C3" implementationClass="org.c3lang.intellij.findUsages.C3FindUsagesProvider"/>

0 commit comments

Comments
 (0)