From 12e91159f3d865088c86cfb6e9f4d7876705d4b3 Mon Sep 17 00:00:00 2001 From: Dinesh Date: Sat, 19 Nov 2022 15:01:36 -0400 Subject: [PATCH 1/4] feature: go syntax highlighting improvements. --- CHANGELOG.md | 10 ++++--- .../annotators/DefaultAnnotator.kt | 18 ++++++++++++ .../vscodetheme/annotators/KotlinAnnotator.kt | 28 +++++++++++++------ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d6ccdc..534089f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,14 @@ # vscode-theme Changelog ## [Unreleased] +### Changed +- Default Annotation - optimizations only when it is unsupported language. ## [1.7.3] -### Fixed -- Go - improve syntax highlighting +### Fixed +- Go - improve syntax highlighting -### Changed +### Changed - Option to star the github repo ## [1.7.2] @@ -119,4 +121,4 @@ - Added extensive syntax highlighting for Dart/Flutter. ### Fixed -- WelcomeScreen color issues and Toolbar border \ No newline at end of file +- WelcomeScreen color issues and Toolbar border diff --git a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/DefaultAnnotator.kt b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/DefaultAnnotator.kt index 287437c..756a5fe 100644 --- a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/DefaultAnnotator.kt +++ b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/DefaultAnnotator.kt @@ -21,6 +21,24 @@ class DefaultAnnotator : BaseAnnotator() { override fun getKeywordType(element: PsiElement): TextAttributesKey? { var type: TextAttributesKey? = null + val supportLanguages = listOf( + "kotlin", + "ObjectiveC", + "Dart", + "go", + "JAVA", + "JavaScript", + "php", + "python", + "rust", + "typescript" + ) + + try { + if (supportLanguages.map { it.lowercase() }.contains(element.language.id.lowercase())) return null + } catch(_: Exception) { + } + when (element.text) { "new", "return" -> type = SECONDARY_KEYWORD "if", "else", "switch", "case", "default", "break", "continue", "assert" -> type = SECONDARY_KEYWORD diff --git a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/KotlinAnnotator.kt b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/KotlinAnnotator.kt index 9d2d471..eaec372 100644 --- a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/KotlinAnnotator.kt +++ b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/KotlinAnnotator.kt @@ -1,12 +1,21 @@ package com.github.dinbtechit.vscodetheme.annotators +import com.intellij.lang.ParserDefinition import com.intellij.openapi.editor.DefaultLanguageHighlighterColors import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.psi.PsiElement import com.intellij.psi.PsiTypeElement +import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.psi.util.elementType import com.intellij.util.ObjectUtils +import org.jetbrains.kotlin.idea.editor.wordSelection.KotlinStringLiteralSelectioner import org.jetbrains.kotlin.lexer.KtKeywordToken +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.parsing.KotlinParserDefinition +import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry +import org.jetbrains.kotlin.psi.KtStringTemplateEntry +import org.jetbrains.uast.kotlin.KotlinStringULiteralExpression class KotlinAnnotator : BaseAnnotator() { companion object { @@ -30,15 +39,16 @@ class KotlinAnnotator : BaseAnnotator() { override fun getKeywordType(element: PsiElement): TextAttributesKey? { var type: TextAttributesKey? = null - if (element.elementType is KtKeywordToken) { - when (element.text) { - "return", "as" -> type = SECONDARY_KEYWORD - "if", "else", "when", "default", "break", "continue" -> type = SECONDARY_KEYWORD - "try", "finally", "throw" -> type = SECONDARY_KEYWORD - "catch" -> type = SECONDARY_KEYWORD_BG - "for", "while", "do" -> type = SECONDARY_KEYWORD - else -> {} - } + + if ((element as LeafPsiElement).elementType == KtTokens.REGULAR_STRING_PART) return null + + when (element.text) { + "return", "as" -> type = SECONDARY_KEYWORD + "if", "else", "when", "default", "break", "continue" -> type = SECONDARY_KEYWORD + "try", "finally", "throw" -> type = SECONDARY_KEYWORD + "catch" -> type = SECONDARY_KEYWORD_BG + "for", "while", "do" -> type = SECONDARY_KEYWORD + else -> {} } when (element.parent) { From 1c096bc81be70cd1dc761ec6f47ba941f104d9c7 Mon Sep 17 00:00:00 2001 From: Dinesh Date: Sat, 3 Dec 2022 10:44:34 -0400 Subject: [PATCH 2/4] Fix: #38 --- CHANGELOG.md | 2 +- src/main/resources/META-INF/plugin.xml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 534089f..dd5d55c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## [Unreleased] ### Changed -- Default Annotation - optimizations only when it is unsupported language. +- Default Annotation - Decommissioning Default Annotator due to Issue #38 ## [1.7.3] ### Fixed diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index b43eb3e..a76df88 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -28,7 +28,8 @@ serviceImplementation="com.github.dinbtechit.vscodetheme.settings.VSCodeThemeSettingsStore"/> - + + Date: Sat, 3 Dec 2022 16:01:53 -0400 Subject: [PATCH 3/4] Fix: typescript inconsisten colors for await keyword --- .../vscodetheme/annotators/JSAnnotator.kt | 15 +++++++++++++-- src/main/resources/themes/vscode_dark.xml | 1 + .../resources/themes/vscode_dark_brighter.xml | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/JSAnnotator.kt b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/JSAnnotator.kt index e97ed85..4409f7e 100644 --- a/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/JSAnnotator.kt +++ b/src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators/JSAnnotator.kt @@ -1,12 +1,18 @@ package com.github.dinbtechit.vscodetheme.annotators import com.intellij.lang.ecmascript6.psi.ES6FromClause +import com.intellij.lang.ecmascript6.psi.ES6ImportDeclaration import com.intellij.lang.ecmascript6.psi.ES6ImportSpecifier +import com.intellij.lang.ecmascript6.psi.ES6ImportedBinding +import com.intellij.lang.ecmascript6.types.ES6ImportDeclarationElementType +import com.intellij.lang.javascript.JSElementType import com.intellij.lang.javascript.psi.JSLoopStatement +import com.intellij.lang.javascript.psi.JSReferenceExpression import com.intellij.lang.javascript.psi.JSStatement import com.intellij.openapi.editor.DefaultLanguageHighlighterColors import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.psi.PsiElement +import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.util.ObjectUtils class JSAnnotator : BaseAnnotator() { @@ -29,6 +35,10 @@ class JSAnnotator : BaseAnnotator() { "JS.SECONDARY_KEYWORDS", JS_KEYWORD ) + val SECONDARY_KEYWORDS_WITH_BG: TextAttributesKey = TextAttributesKey.createTextAttributesKey( + "DEFAULT_SECONDARY_KEYWORD_WITH_BG", JS_KEYWORD + ) + val FROM_KEYWORD: TextAttributesKey = TextAttributesKey.createTextAttributesKey( "JS.FROM_KEYWORD", JS_KEYWORD ) @@ -39,7 +49,8 @@ class JSAnnotator : BaseAnnotator() { var type: TextAttributesKey? = null when (element.text) { "package", "export", "import", "require", "module", "return" -> type = SECONDARY_KEYWORDS - "await", "try", "throw", "catch", "finally", "yield", "break", "continue", "with", + "await" -> type = SECONDARY_KEYWORDS_WITH_BG + "try", "throw", "catch", "finally", "yield", "break", "continue", "with", "if", "else", "switch", "case", "default" -> type = SECONDARY_KEYWORDS "for", "while", "do" -> if (element.context is JSLoopStatement) type = SECONDARY_KEYWORDS "from" -> if (element.parent is ES6FromClause) type = FROM_KEYWORD @@ -49,7 +60,7 @@ class JSAnnotator : BaseAnnotator() { } when (element.parent) { - is ES6ImportSpecifier -> type = IMPORT_SPECIFIER + is ES6ImportSpecifier, is ES6ImportedBinding -> type = IMPORT_SPECIFIER else -> {} } diff --git a/src/main/resources/themes/vscode_dark.xml b/src/main/resources/themes/vscode_dark.xml index ea2f06c..adac86a 100644 --- a/src/main/resources/themes/vscode_dark.xml +++ b/src/main/resources/themes/vscode_dark.xml @@ -374,6 +374,7 @@