Skip to content

Commit

Permalink
Merge pull request #33 from dinbtechit/feature/rust-highligting
Browse files Browse the repository at this point in the history
feature: syntax highlighting for rust
  • Loading branch information
dinbtechit authored Nov 7, 2022
2 parents 1e8fa2a + 3738331 commit 3e0b66c
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
### Fixed
- Bug #31 - Inconsistent ANSI Console Colors

### Added
- Adding Default syntax highlighting for base control statements to match vscode
- Adding a basic version of Rust specific syntax highlighting.

## [1.7.1]
### Fixed
Expand Down
5 changes: 3 additions & 2 deletions 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.1
pluginVersion = 1.7.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 211
Expand All @@ -16,7 +16,8 @@ platformVersion = 2022.1.1
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = JavaScript, com.intellij.java, io.flutter:67.1.4, Dart:221.5591.58, PsiViewer:221-SNAPSHOT, \
Pythonid:221.5591.52, org.jetbrains.kotlin, com.jetbrains.php:221.5591.58, org.jetbrains.plugins.go:221.5591.52
Pythonid:221.5591.52, org.jetbrains.kotlin, com.jetbrains.php:221.5591.58, org.jetbrains.plugins.go:221.5591.52, \
org.rust.lang:0.4.179.4903-221

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 7.5.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.dinbtechit.vscodetheme.annotators

import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.psi.PsiElement


class DefaultAnnotator : BaseAnnotator() {
companion object {
private val DEFAULT_KEYWORD: TextAttributesKey = DefaultLanguageHighlighterColors.KEYWORD
val TYPE_KEYWORD: TextAttributesKey = DefaultLanguageHighlighterColors.CLASS_NAME
val SECONDARY_KEYWORD: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
"DEFAULT_SECONDARY_KEYWORD",
DEFAULT_KEYWORD
)
val SECONDARY_KEYWORD_BG: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
"DEFAULT_SECONDARY_KEYWORD_WITH_BG",
DEFAULT_KEYWORD
)
}

override fun getKeywordType(element: PsiElement): TextAttributesKey? {
var type: TextAttributesKey? = null
when (element.text) {
"new", "return" -> type = SECONDARY_KEYWORD
"if", "else", "switch", "case", "default", "break", "continue", "assert" -> type = SECONDARY_KEYWORD
"try", "catch", "finally", "throw" -> type = SECONDARY_KEYWORD
"for", "while", "do", "in" -> type = SECONDARY_KEYWORD
else -> {}
}

return type
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.dinbtechit.vscodetheme.annotators

import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.psi.PsiElement


class RustAnnotator : BaseAnnotator() {
companion object {
private val DEFAULT_KEYWORD: TextAttributesKey = DefaultLanguageHighlighterColors.KEYWORD
val TYPE_KEYWORD: TextAttributesKey = DefaultLanguageHighlighterColors.CLASS_NAME
val SECONDARY_KEYWORD: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
"DEFAULT_SECONDARY_KEYWORD",
DEFAULT_KEYWORD
)
val SECONDARY_KEYWORD_BG: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
"DEFAULT_SECONDARY_KEYWORD_WITH_BG",
DEFAULT_KEYWORD
)
}

override fun getKeywordType(element: PsiElement): TextAttributesKey? {
var type: TextAttributesKey? = null
when (element.text) {
"mut", "match","return" -> type = SECONDARY_KEYWORD
"if", "else", "switch", "case", "default", "break", "continue", "as" -> type = SECONDARY_KEYWORD
"try", "catch", "finally", "throw" -> type = SECONDARY_KEYWORD
"for", "while", "loop", "in" -> type = SECONDARY_KEYWORD
"await", "async", "yield", "on" -> type = SECONDARY_KEYWORD_BG
"*" -> if (element.prevSibling != null) {
when (element.prevSibling.text) {
"await", "sync", "async", "yield" -> type = SECONDARY_KEYWORD_BG
}
}
else -> {}
}

return type
}

}
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/lang-config/dinbtechit-rust.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<annotator language="Rust" order="last"
implementationClass="com.github.dinbtechit.vscodetheme.annotators.RustAnnotator"/>
<!--<colorSettingsPage order="last" implementation="com.github.dinbtechit.vscodetheme.annotators.settings.DartColorSettingsPage"/>-->
</extensions>
</idea-plugin>
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<depends config-file="lang-config/dinbtechit-php.xml" optional="true">com.jetbrains.php</depends>
<depends config-file="lang-config/dinbtechit-clion.xml" optional="true">com.intellij.cidr.lang</depends>
<depends config-file="lang-config/dinbtechit-go.xml" optional="true">org.jetbrains.plugins.go</depends>
<depends config-file="lang-config/dinbtechit-rust.xml" optional="true">org.rust.lang</depends>
<!--<depends config-file="lang-config/dinbtechit-typescript.xml" optional="true">JavaScript</depends>-->

<extensions defaultExtensionNs="com.intellij">
Expand All @@ -27,6 +28,7 @@
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"/>
</extensions>
<actions>
<action id="AlwaysApplyThemeAction" class="com.github.dinbtechit.vscodetheme.actions.AlwaysApplyThemeAction"
Expand Down

0 comments on commit 3e0b66c

Please sign in to comment.