Skip to content

Commit

Permalink
Add custom keyword highlight for Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
xdrop committed Aug 5, 2018
1 parent 2ef4fea commit dd0bae8
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 9 deletions.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
}

group 'me.xdrop'
version '1.2.1'
version '1.3.0'

def isDevMode = System.getProperty("dev")?.toBoolean() ?: false

Expand All @@ -34,14 +34,13 @@ compileKotlin {
}
}

def pluginDependencies = ['izhangzhihao.rainbow.brackets:5.9.1', 'com.chrisrm.idea.MaterialThemeUI:2.7.1']

intellij {
pluginName 'nightowl-theme'
version '2018.2'
updateSinceUntilBuild true
if (isDevMode) {
plugins = pluginDependencies
plugins = ['izhangzhihao.rainbow.brackets:5.9.1',
'com.chrisrm.idea.MaterialThemeUI:2.7.1']
}
}
patchPluginXml {
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<h1>Changelog</h1>
<p>----</p>
<h1>1.3.0</h1>
<ul>
<li>Add custom highlight for some Javascript keywords</li>
</ul>
<h1>1.2.1</h1>
<ul>
<li>Add dialog confirmation before updating settings</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class NightOwlProjectComponent(project: Project) : AbstractProjectComponent(proj
<b>Night Owl</b> successfully updated!<br/>
<br/>
<b>In this release</b>: <ul>
<li>Add dialog confirmation before updating settings</li>
<li>Add custom highlight for some Javascript keywords. (Edit under Color Scheme > Night Owl)</li>
</ul>
</br>
Visit our <a href="https://github.com/xdrop/night-owl-jetbrains/issues">Github page</a> for any issues you have
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<maximumSize width="900" height="119"/>
<preferredSize width="500" height="102"/>
<text value="&lt;html&gt;Night Owl comes with a set of recommended editor and appearance settings, for a fully minimal experience. This involves hiding several toolbars, changing tab limits etc. &lt;br/&gt;&lt;br/&gt;&#10;&#10;&lt;b&gt;The theme will now apply the &lt;i&gt;recommended&lt;/i&gt; appearance settings to your editor.&lt;/b&gt;&#10;&#10;If you do not want your editor preferences to be changed please click &lt;b&gt;Cancel&lt;/b&gt; now.&#10;&lt;/html&gt;"/>
<text value="&lt;html&gt;Night Owl comes with a set of recommended editor and appearance settings, for a fully minimal experience. This involves hiding several toolbars and outlines. &lt;br/&gt;&lt;br/&gt;&#10;&#10;&lt;b&gt;The theme will now apply the &lt;i&gt;recommended&lt;/i&gt; appearance settings to your editor.&lt;/b&gt;&#10;&#10;If you do not want your editor preferences to be changed please click &lt;b&gt;Cancel&lt;/b&gt; now.&#10;&lt;/html&gt;"/>
<verticalAlignment value="0"/>
</properties>
</component>
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/me/xdrop/nightowl/dialog/SetSettingsDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package me.xdrop.nightowl.dialog
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import me.xdrop.nightowl.NightOwlAppearance
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.*
import javax.swing.JComponent
import javax.swing.JPanel

class SetSettingsDialog(project: Project) : DialogWrapper(project) {
var panel: JPanel? = null
Expand All @@ -22,5 +21,6 @@ class SetSettingsDialog(project: Project) : DialogWrapper(project) {

override fun doOKAction() {
NightOwlAppearance.applyIdeSettings()
super.doOKAction()
}
}
36 changes: 36 additions & 0 deletions src/main/kotlin/me/xdrop/nightowl/highlight/NightOwlJSAnnotator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.xdrop.nightowl.highlight

import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.source.tree.LeafPsiElement

class NightOwlJSAnnotator : Annotator {
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
if (element is LeafPsiElement) {
val kind = when (element.text) {
"this" -> JS_THIS_SUPER;
"super" -> JS_THIS_SUPER
"export" -> JS_MODULE_KEYWORD
"default" -> JS_MODULE_KEYWORD
"module" -> JS_MODULE_KEYWORD
"debugger" -> JS_DEBUGGER
else -> {
return
}
}
val range = TextRange(element.textRange.startOffset, element.textRange.endOffset)
val annotation = holder.createAnnotation(HighlightSeverity.INFORMATION, range, null)
annotation.textAttributes = kind
}
}

companion object {
public val JS_THIS_SUPER = TextAttributesKey.createTextAttributesKey("JS_THIS_SUPER")
public val JS_MODULE_KEYWORD = TextAttributesKey.createTextAttributesKey("JS_MODULE_KEYWORD")
public val JS_DEBUGGER = TextAttributesKey.createTextAttributesKey("JS_DEBUGGER_STMT")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package me.xdrop.nightowl.settings

import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.fileTypes.PlainSyntaxHighlighter
import com.intellij.openapi.fileTypes.SyntaxHighlighter
import com.intellij.openapi.options.colors.AttributesDescriptor
import com.intellij.openapi.options.colors.ColorDescriptor
import com.intellij.openapi.options.colors.ColorSettingsPage
import me.xdrop.nightowl.highlight.NightOwlJSAnnotator
import java.awt.Component
import java.awt.Graphics
import javax.swing.Icon

class NightOwlColorSettingsPage : ColorSettingsPage {

class EmptyIcon : Icon {
override fun getIconHeight(): Int {
return 32
}

override fun paintIcon(c: Component?, g: Graphics?, x: Int, y: Int) {
}

override fun getIconWidth(): Int {
return 32
}

}

override fun getHighlighter(): SyntaxHighlighter {
return PlainSyntaxHighlighter()
}

override fun getAdditionalHighlightingTagToDescriptorMap(): MutableMap<String, TextAttributesKey> {
return HashMap()
}

override fun getIcon(): Icon? {
return EmptyIcon()
}

override fun getAttributeDescriptors(): Array<AttributesDescriptor> {
return DESCRIPTORS
}

override fun getColorDescriptors(): Array<ColorDescriptor> {
return emptyArray();
}

override fun getDisplayName(): String = "Night Owl"
override fun getDemoText(): String = " "

companion object {
private var DESCRIPTORS = arrayOf(
AttributesDescriptor("JSlike - this, super", NightOwlJSAnnotator.JS_THIS_SUPER),
AttributesDescriptor("JSlike - export, default, module", NightOwlJSAnnotator.JS_MODULE_KEYWORD),
AttributesDescriptor("JSlike - debugger", NightOwlJSAnnotator.JS_DEBUGGER)
)
}
}
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<extensions defaultExtensionNs="com.intellij">
<applicationConfigurable instance="me.xdrop.nightowl.settings.NightOwlConfigurable"/>
<applicationService serviceImplementation="me.xdrop.nightowl.settings.NightOwlSettings"/>
<annotator language="JavaScript" implementationClass="me.xdrop.nightowl.highlight.NightOwlJSAnnotator"/>
<annotator language="TypeScript" implementationClass="me.xdrop.nightowl.highlight.NightOwlJSAnnotator"/>
<colorSettingsPage implementation="me.xdrop.nightowl.settings.NightOwlColorSettingsPage"/>
</extensions>

<application-components>
Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/colors/NightOwl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3757,5 +3757,20 @@
<option name="FONT_TYPE" value="1"/>
</value>
</option>
<option name="JS_THIS_SUPER">
<value>
<option name="FOREGROUND" value="7fdbca" />
</value>
</option>
<option name="JS_MODULE_KEYWORD">
<value>
<option name="FOREGROUND" value="7fdbca" />
</value>
</option>
<option name="JS_DEBUGGER_STMT">
<value>
<option name="FOREGROUND" value="7fdbca" />
</value>
</option>
</attributes>
</scheme>

0 comments on commit dd0bae8

Please sign in to comment.