From 0ec4c444eff7021c29e42b58175c3c5d461ba6dd Mon Sep 17 00:00:00 2001 From: Jonas Ha Date: Sun, 8 Dec 2024 19:28:44 -0500 Subject: [PATCH 1/2] added context aware color for async keyword based upon if its followed by `def` or not. --- .../vscodetheme/annotators/PyAnnotator.kt | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt index 8035705..82b0a33 100644 --- a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt +++ b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt @@ -5,6 +5,7 @@ import com.intellij.lang.Language import com.intellij.openapi.editor.DefaultLanguageHighlighterColors import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.psi.PsiElement +import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.util.elementType import com.intellij.util.ObjectUtils import com.jetbrains.python.PyTokenTypes @@ -101,8 +102,26 @@ class PyAnnotator : BaseAnnotator() { "elif", "else", "if", "except", "pass", "raise", "return", "try", "while", "with" -> type = SECONDARY_KEYWORD "self" -> type = DEFAULT_KEYWORD - "async", "await" -> type = if(isJupyterNoteBook(element)) SECONDARY_KEYWORD_WITH_BG_JUPYTER - else SECONDARY_KEYWORD_WITH_BG + "await" -> + type = + if(isJupyterNoteBook(element)) + SECONDARY_KEYWORD_WITH_BG_JUPYTER + else + SECONDARY_KEYWORD_WITH_BG + "async" -> { + type = + generateSequence(element.nextSibling) { it.nextSibling } + .firstOrNull { it !is PsiWhiteSpace } + ?.let { nextWord -> + when { + nextWord.elementType == PyTokenTypes.DEF_KEYWORD -> DEFAULT_KEYWORD + isJupyterNoteBook(element) -> SECONDARY_KEYWORD_WITH_BG_JUPYTER + else -> SECONDARY_KEYWORD_WITH_BG + } + } + ?: if (isJupyterNoteBook(element)) SECONDARY_KEYWORD_WITH_BG_JUPYTER + else SECONDARY_KEYWORD_WITH_BG + } else -> {} } @@ -117,5 +136,4 @@ class PyAnnotator : BaseAnnotator() { return element.containingFile.name.contains(".ipynb") || element.containingFile.language == Language.findLanguageByID("JupyterPython") } - } From ef0501e864b05ac42d2eb1f55b404944f91992f4 Mon Sep 17 00:00:00 2001 From: Jonas Ha Date: Sun, 8 Dec 2024 19:59:58 -0500 Subject: [PATCH 2/2] fixed formatting --- .../github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt index 82b0a33..26b5f16 100644 --- a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt +++ b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/PyAnnotator.kt @@ -104,10 +104,8 @@ class PyAnnotator : BaseAnnotator() { "self" -> type = DEFAULT_KEYWORD "await" -> type = - if(isJupyterNoteBook(element)) - SECONDARY_KEYWORD_WITH_BG_JUPYTER - else - SECONDARY_KEYWORD_WITH_BG + if (isJupyterNoteBook(element)) SECONDARY_KEYWORD_WITH_BG_JUPYTER + else SECONDARY_KEYWORD_WITH_BG "async" -> { type = generateSequence(element.nextSibling) { it.nextSibling }