Skip to content

Commit be3868b

Browse files
committed
clunky fix for #139 - Jupyter background - Need to find a way for long term fix.
1 parent c1da154 commit be3868b

File tree

5 files changed

+105
-5
lines changed

5 files changed

+105
-5
lines changed

src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dinbtechit.vscodetheme.annotators
22

3+
34
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
45
import com.intellij.openapi.editor.colors.TextAttributesKey
56
import com.intellij.psi.PsiElement
@@ -9,6 +10,7 @@ import com.jetbrains.python.psi.*
910
import com.jetbrains.python.psi.impl.PyImportedModule
1011
import com.jetbrains.python.psi.impl.references.PyImportReference
1112
import com.jetbrains.python.psi.impl.stubs.PyClassElementType
13+
import org.jetbrains.plugins.notebooks.jupyter.python.JupyterPyDialect
1214

1315

1416
class PyAnnotator : BaseAnnotator() {
@@ -25,26 +27,43 @@ class PyAnnotator : BaseAnnotator() {
2527
"PY.SECONDARY_KEYWORD_WITH_BG",
2628
DEFAULT_KEYWORD
2729
)
30+
val SECONDARY_KEYWORD_WITH_BG_JUPYTER: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
31+
"PY.Jupyter.SECONDARY_KEYWORD_WITH_BG",
32+
DEFAULT_KEYWORD
33+
)
2834

2935
val FUNCTION_WITH_BG: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
3036
"PY.FUNCTION_CALL",
3137
DefaultLanguageHighlighterColors.FUNCTION_CALL
3238
)
39+
val FUNCTION_WITH_BG_JUPYTER: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
40+
"PY.Jupyter.FUNCTION_CALL",
41+
DefaultLanguageHighlighterColors.FUNCTION_CALL
42+
)
3343

3444
val CLASS_REFERENCE_WITH_BG: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
3545
"PY.CLASS_REFERENCE",
3646
DefaultLanguageHighlighterColors.CLASS_REFERENCE
3747
)
48+
val CLASS_REFERENCE_WITH_BG_JUPYTER: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
49+
"PY.Jupyter.CLASS_REFERENCE",
50+
DefaultLanguageHighlighterColors.CLASS_REFERENCE
51+
)
3852

3953
val IMPORT_REFERENCE_WITH_BG: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
4054
"PY.IMPORTS",
4155
DefaultLanguageHighlighterColors.CLASS_REFERENCE
4256
)
57+
val IMPORT_REFERENCE_WITH_BG_JUPYTER: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
58+
"PY.Jupyter.IMPORTS",
59+
DefaultLanguageHighlighterColors.CLASS_REFERENCE
60+
)
4361
}
4462

4563
override fun getKeywordType(element: PsiElement): TextAttributesKey? {
4664
var type: TextAttributesKey? = null
4765

66+
4867
if ((element.elementType is PyElementType
4968
&& (element.parent is PyTargetExpression
5069
|| element.parent is PyReferenceExpression)) && (element.parent !is PyFunction)
@@ -55,21 +74,23 @@ class PyAnnotator : BaseAnnotator() {
5574
if ((element.parent is PyClass && element.nextSibling is PyArgumentList)
5675
|| element.parent.reference?.resolve().elementType is PyClassElementType
5776
) {
58-
type = CLASS_REFERENCE_WITH_BG
77+
type = if(isJupyterNoteBook(element)) CLASS_REFERENCE_WITH_BG_JUPYTER else CLASS_REFERENCE_WITH_BG
78+
5979
}
6080

6181
if ((element.parent is PyFunction && element.text != "def")
6282
|| (element.parent.reference?.resolve() is PyFunction && element.text != "def")
6383
) {
64-
type = FUNCTION_WITH_BG
84+
type = if(isJupyterNoteBook(element)) FUNCTION_WITH_BG_JUPYTER else FUNCTION_WITH_BG
6585
}
6686

6787

6888
if (element.parent.reference is PyImportReference
6989
|| element.parent.reference?.resolve() is PyImportedModule
7090
|| element.parent.reference?.resolve() is PyFile
7191
) {
72-
type = IMPORT_REFERENCE_WITH_BG
92+
type = if(isJupyterNoteBook(element)) IMPORT_REFERENCE_WITH_BG_JUPYTER else IMPORT_REFERENCE_WITH_BG
93+
7394
}
7495

7596

@@ -79,11 +100,18 @@ class PyAnnotator : BaseAnnotator() {
79100
"elif", "else", "if", "except", "pass", "raise", "return", "try", "while",
80101
"with" -> type = SECONDARY_KEYWORD
81102
"self" -> type = DEFAULT_KEYWORD
82-
"async", "await" -> type = SECONDARY_KEYWORD_WITH_BG
103+
"async", "await" -> type = if(isJupyterNoteBook(element)) SECONDARY_KEYWORD_WITH_BG_JUPYTER
104+
else SECONDARY_KEYWORD_WITH_BG
83105
else -> {}
84106
}
85107

86108
return type
87109
}
88110

111+
private fun isJupyterNoteBook(element: PsiElement): Boolean {
112+
return element.containingFile.name.contains(".ipynb")
113+
|| element.containingFile.language.displayName == JupyterPyDialect.displayName
114+
115+
}
116+
89117
}

src/main/resources/themes/vscode_dark.xml

+24
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,12 @@
980980
<option name="BACKGROUND" value="1e1e1e"/>
981981
</value>
982982
</option>
983+
<option name="PY.Jupyter.CLASS_REFERENCE">
984+
<value>
985+
<option name="FOREGROUND" value="4ec9b0"/>
986+
<option name="BACKGROUND" value="2B2D30"/>
987+
</value>
988+
</option>
983989
<option name="PY.DECORATOR">
984990
<value>
985991
<option name="FOREGROUND" value="4ec9b0"/>
@@ -997,12 +1003,24 @@
9971003
<option name="FOREGROUND" value="47CCB1"/>
9981004
</value>
9991005
</option>
1006+
<option name="PY.Jupyter.IMPORTS">
1007+
<value>
1008+
<option name="FOREGROUND" value="47ccb1"/>
1009+
<option name="BACKGROUND" value="2B2D30"/>
1010+
</value>
1011+
</option>
10001012
<option name="PY.FUNCTION_CALL">
10011013
<value>
10021014
<option name="FOREGROUND" value="dbdbaa"/>
10031015
<option name="BACKGROUND" value="1e1e1e"/>
10041016
</value>
10051017
</option>
1018+
<option name="PY.Jupyter.FUNCTION_CALL">
1019+
<value>
1020+
<option name="FOREGROUND" value="dbdbaa"/>
1021+
<option name="BACKGROUND" value="2B2D30"/>
1022+
</value>
1023+
</option>
10061024
<option name="PY.KEYWORD_ARGUMENT">
10071025
<value>
10081026
<option name="FOREGROUND" value="94dbfd"/>
@@ -1029,6 +1047,12 @@
10291047
<option name="BACKGROUND" value="1e1e1e"/>
10301048
</value>
10311049
</option>
1050+
<option name="PY.Jupyter.SECONDARY_KEYWORD_WITH_BG">
1051+
<value>
1052+
<option name="FOREGROUND" value="c586C0"/>
1053+
<option name="BACKGROUND" value="2B2D30"/>
1054+
</value>
1055+
</option>
10321056
<option name="PY.SELF_PARAMETER">
10331057
<value>
10341058
<option name="FOREGROUND" value="569cd5"/>

src/main/resources/themes/vscode_dark_brighter.xml

+24
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,12 @@
980980
<option name="BACKGROUND" value="1e1e1e"/>
981981
</value>
982982
</option>
983+
<option name="PY.Jupyter.CLASS_REFERENCE">
984+
<value>
985+
<option name="FOREGROUND" value="47ccb1"/>
986+
<option name="BACKGROUND" value="2B2D30"/>
987+
</value>
988+
</option>
983989
<option name="PY.DECORATOR">
984990
<value>
985991
<option name="FOREGROUND" value="e6e6aa"/>
@@ -997,12 +1003,24 @@
9971003
<option name="BACKGROUND" value="1e1e1e"/>
9981004
</value>
9991005
</option>
1006+
<option name="PY.Jupyter.FUNCTION_CALL">
1007+
<value>
1008+
<option name="FOREGROUND" value="e6e6aa"/>
1009+
<option name="BACKGROUND" value="2B2D30"/>
1010+
</value>
1011+
</option>
10001012
<option name="PY.IMPORTS">
10011013
<value>
10021014
<option name="FOREGROUND" value="47ccb1"/>
10031015
<option name="BACKGROUND" value="1e1e1e"/>
10041016
</value>
10051017
</option>
1018+
<option name="PY.Jupyter.IMPORTS">
1019+
<value>
1020+
<option name="FOREGROUND" value="47ccb1"/>
1021+
<option name="BACKGROUND" value="2B2D30"/>
1022+
</value>
1023+
</option>
10061024
<option name="PY.KEYWORD_ARGUMENT">
10071025
<value>
10081026
<option name="FOREGROUND" value="94dbfd"/>
@@ -1034,6 +1052,12 @@
10341052
<option name="BACKGROUND" value="1e1e1e"/>
10351053
</value>
10361054
</option>
1055+
<option name="PY.Jupyter.SECONDARY_KEYWORD_WITH_BG">
1056+
<value>
1057+
<option name="FOREGROUND" value="cc85c6"/>
1058+
<option name="BACKGROUND" value="2B2D30"/>
1059+
</value>
1060+
</option>
10371061
<option name="PY.SELF_PARAMETER">
10381062
<value>
10391063
<option name="FOREGROUND" value="569cd5"/>

src/main/resources/themes/vscode_light.theme.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"editorScheme": "/themes/vscode_light_modern.xml",
66
"ui": {
77
"*": {
8-
"background": "#F8F8F8"
8+
99
},
1010

1111
"Editor": {

src/main/resources/themes/vscode_light_modern.xml

+24
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,12 @@
10981098
<option name="BACKGROUND" value="ffffff"/>
10991099
</value>
11001100
</option>
1101+
<option name="PY.Jupyter.CLASS_REFERENCE">
1102+
<value>
1103+
<option name="FOREGROUND" value="267f99"/>
1104+
<option name="BACKGROUND" value="F7F8FA"/>
1105+
</value>
1106+
</option>
11011107
<option name="PY.CLASS_DEFINITION">
11021108
<value>
11031109
<option name="FOREGROUND" value="267f99"/>
@@ -1124,6 +1130,12 @@
11241130
<option name="BACKGROUND" value="ffffff"/>
11251131
</value>
11261132
</option>
1133+
<option name="PY.Jupyter.FUNCTION_CALL">
1134+
<value>
1135+
<option name="FOREGROUND" value="795e26"/>
1136+
<option name="BACKGROUND" value="F7F8FA"/>
1137+
</value>
1138+
</option>
11271139
<option name="PY.FUNC_DEFINITION">
11281140
<value>
11291141
<option name="FOREGROUND" value="795e26"/>
@@ -1135,6 +1147,12 @@
11351147
<option name="BACKGROUND" value="ffffff"/>
11361148
</value>
11371149
</option>
1150+
<option name="PY.Jupyter.IMPORTS">
1151+
<value>
1152+
<option name="FOREGROUND" value="277f99"/>
1153+
<option name="BACKGROUND" value="F7F8FA"/>
1154+
</value>
1155+
</option>
11381156
<option name="PY.INVALID_STRING_ESCAPE">
11391157
<value>
11401158
<option name="FOREGROUND" value="cd3131"/>
@@ -1181,6 +1199,12 @@
11811199
<option name="BACKGROUND" value="ffffff"/>
11821200
</value>
11831201
</option>
1202+
<option name="PY.Jupyter.SECONDARY_KEYWORD_WITH_BG">
1203+
<value>
1204+
<option name="FOREGROUND" value="bf3be2"/>
1205+
<option name="BACKGROUND" value="F7F8FA"/>
1206+
</value>
1207+
</option>
11841208
<option name="PY.STRING">
11851209
<value>
11861210
<option name="FOREGROUND" value="a31515"/>

0 commit comments

Comments
 (0)