Skip to content

Commit

Permalink
Merge pull request #40 from dinbtechit/feature/default_annotator_opti…
Browse files Browse the repository at this point in the history
…mization

Feature/default annotator optimization
  • Loading branch information
dinbtechit authored Dec 3, 2022
2 parents 6f09c7c + 6e786cb commit e7a1b2f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 17 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
# vscode-theme Changelog

## [Unreleased]
### Changed
- Default Annotation - Decommissioning Default Annotator due to Issue #38
- Typescript await keyword inconsistency.

## [1.7.3]
### Fixed
- Go - improve syntax highlighting
### Fixed
- Go - improve syntax highlighting

### Changed
### Changed
- Option to star the github repo

## [1.7.2]
Expand Down Expand Up @@ -119,4 +122,4 @@
- Added extensive syntax highlighting for Dart/Flutter.

### Fixed
- WelcomeScreen color issues and Toolbar border
- WelcomeScreen color issues and Toolbar border
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pluginGroup = com.github.dinbtechit.vscodetheme
pluginName = VSCode Theme
# SemVer format -> https://semver.org
pluginVersion = 1.7.3
pluginVersion = 1.7.4

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 211
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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
)
Expand All @@ -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
Expand All @@ -49,7 +60,7 @@ class JSAnnotator : BaseAnnotator() {
}

when (element.parent) {
is ES6ImportSpecifier -> type = IMPORT_SPECIFIER
is ES6ImportSpecifier, is ES6ImportedBinding -> type = IMPORT_SPECIFIER
else -> {}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
serviceImplementation="com.github.dinbtechit.vscodetheme.settings.VSCodeThemeSettingsStore"/>
<applicationService serviceImplementation="com.github.dinbtechit.vscodetheme.services.ApplicationService"/>
<notificationGroup id="VSCode Theme Notification Group" displayType="STICKY_BALLOON"/>
<annotator language="" order="last" implementationClass="com.github.dinbtechit.vscodetheme.annotators.DefaultAnnotator"/>
<!--https://github.com/dinbtechit/vscode-theme/issues/38 Default Annotator Issues-->
<!--<annotator language="" order="last" implementationClass="com.github.dinbtechit.vscodetheme.annotators.DefaultAnnotator"/>-->
</extensions>
<actions>
<action id="AlwaysApplyThemeAction" class="com.github.dinbtechit.vscodetheme.actions.AlwaysApplyThemeAction"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/themes/vscode_dark.xml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
<option name="DEFAULT_SECONDARY_KEYWORD_WITH_BG">
<value>
<option name="FOREGROUND" value="ce80b6"/>
<option name="BACKGROUND" value="1e1e1e"/>
</value>
</option>
<option name="DEFAULT_SEMICOLON">
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/themes/vscode_dark_brighter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
<option name="DEFAULT_SECONDARY_KEYWORD_WITH_BG">
<value>
<option name="FOREGROUND" value="cc85c6"/>
<option name="BACKGROUND" value="1e1e1e"/>
</value>
</option>
<option name="DEFAULT_SEMICOLON">
Expand Down

0 comments on commit e7a1b2f

Please sign in to comment.