-
-
Notifications
You must be signed in to change notification settings - Fork 23
Add Language support
In this example we will be adding additional highlighting for GoLang.
-
Intellij IDE installed on your machine. (Either Community version or the EAP version)
-
JDK v11 (Preferably OpenJDK or ZuluJDK) Install
brew install openjdk@11 # Create Symbolic Link mkdir -p /Library/Java/JavaVirtualMachines cd /Library/Java/JavaVirtualMachines ln -s /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk openjdk-11.jdk
edit ~/.zprofile
vi ~/.zprofile
and add the following JDK env variables
# Java export JAVA_HOME="/opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home" export PATH="$JAVA_HOME/bin:$PATH" export CPPFLAGS="-I$JAVA_HOME/include"
-
Clone the repository (Internal Developer) or Fork the repository (External Developers).
git clone https://github.com/dinbtechit/vscode-theme
Note: if you already have the SSH keys feel free to use the SSH URL.
-
Create a new feature branch.
Provide a descriptive name for the feature branch. <GITHUB_ISSUE#>-<BRIEF_DESCRIPTION>.
git checkout -b feature/15-golang-vscode-syntax-support
-
Open the project in IntelliJ. Intellij should start syncing all the Gradle dependencies and might take a while.
Note: Gradle dependencies gets cached in your home directory (
$HOME/.gradle/caches
). Just like maven or npm. Over time they take a significant amount of the disk space. Its a good practice to clean up the cache when you are done developing.
-
In this case, we are going to add GoLang dependency (
org.jetbrains.plugins.go:221.5591.52
) to theplatformPlugins
. As shown belowgradle.properties
platformPlugins = ..., org.jetbrains.plugins.go:221.5591.52
Note: You can get the dependency information (i.e., pluginID + Version) from Jetbrains MarketPlace by searching for the plugin -> Plugin homepage -> under the
Versions
tab -> click on the version.
-
Navigate to
src/main/resources/META-INF/lang-config
and create a new xml config file for Go,dinbtechit-go.xml
(i.e., dinbtechit-[LANG].xml). And update the contents as shown below.<idea-plugin> <extensions defaultExtensionNs="com.intellij"> <annotator language="go" order="last" implementationClass="com.github.dinbtechit.vscodetheme.annotators.GoAnnotator"/> </extensions> </idea-plugin>
-
Add a new
depends
tag insrc/main/resources/META-INF/plugin.xml
to include the language config,dinbtechit-go.xml
that we just created. Add it to the bottom of the existingdepends
tags (As shown below)plugin.xml
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html --> <idea-plugin require-restart="true"> . . . <depends config-file="lang-config/dinbtechit-go.xml" optional="true">org.jetbrains.plugins.go</depends> . . . <idea-plugin>
- Navigate to
src/main/kotlin/com/github/dinbtechit/vscodetheme/annotators
and create a new kotlin Class file,GoAnnotator
, and update the contents as shown below.
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.psi.PsiElement
import com.intellij.util.ObjectUtils
class GoAnnotator : BaseAnnotator() {
companion object {
val DEFAULT_KEYWORD: TextAttributesKey = ObjectUtils.notNull(
TextAttributesKey.find("DEFAULT_KEYWORD"), DefaultLanguageHighlighterColors.KEYWORD
)
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) {
"if", "else", "goto", "switch", "select", "case", "default", "break", "continue" -> type = SECONDARY_KEYWORD
"defer", "go", "fallthrough" -> type = SECONDARY_KEYWORD
"for", "range" -> type = SECONDARY_KEYWORD
"return" -> type = SECONDARY_KEYWORD
else -> {}
}
return type
}
}
Note: Currently there are no unit tests for this project. But I'm working on a plan to incorporate testing in the near future.
Awesome, you have successfully completed the coding. You are almost there!
-
Increment the
pluginVersion
ingradle.properties
. We are using semantic versioning. Adding new language support is a minor release so we will increment the version from1.5.4
to1.6.0
-
Update
CHANGELOG.md
- Add the following under the## [Unreleased]
. Github actions will automatically update the Unreleased to the appropriate version fromgradle.properties
## [Unreleased] ### Added - (feature #15) Added extensive syntax highlighting for Go
-
Update
README.md
:- In
Supported Languages
section -> move theGo
from Basic Syntax highlighting to the Advance Syntax highlighting. - In the RoadMap section -> Remove GoLang
- In
-
Commit all your changes, push the branch to remote and Submit a Pull Request against the
main
branch.Note once your PR is approved and merged to the main branch. Github actions will automatically kick off a build and release the plugin to the Jetbrains Market place. Once it is released in the market place it will take about a day or two for Jetbrains to approve the new version of the plugin and show up in your IDE.