-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom keyword highlight for Javascript
- Loading branch information
Showing
9 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/me/xdrop/nightowl/highlight/NightOwlJSAnnotator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/kotlin/me/xdrop/nightowl/settings/NightOwlColorSettingsPage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters