Skip to content

Commit 8addede

Browse files
committed
Update highlighter
1 parent 5903c20 commit 8addede

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Clojure-Kit DevKt
22

3-
This is the devkt version of [Clojure-Kit](https://github.com/gregsh/Clojure-Kit).
3+
This is the DevKt version of [Clojure-Kit](https://github.com/gregsh/Clojure-Kit).
44

55
# Build
66

src/org/intellij/clojure/devkt/clojure-devkt.kt

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package org.intellij.clojure.devkt
22

33
import org.ice1000.devkt.openapi.*
44
import org.intellij.clojure.devkt.lang.*
5+
import org.intellij.clojure.devkt.psi.*
56
import org.intellij.clojure.devkt.psi.ClojureTypes.*
7+
import org.intellij.clojure.devkt.util.*
68
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
79
import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
810

@@ -16,6 +18,11 @@ class Clojure<TextAttributes> : ExtendedDevKtLanguage<TextAttributes>(
1618
fileName.endsWith(".cljs") ||
1719
fileName.endsWith(".cljc")
1820

21+
/**
22+
* @param type IElementType
23+
* @param colorScheme ColorScheme<TextAttributes>
24+
* @return TextAttributes?
25+
*/
1926
override fun attributesOf(type: IElementType, colorScheme: ColorScheme<TextAttributes>) = when (type) {
2027
ClojureTokens.LINE_COMMENT -> colorScheme.lineComments
2128
C_STRING -> colorScheme.string
@@ -33,16 +40,38 @@ class Clojure<TextAttributes> : ExtendedDevKtLanguage<TextAttributes>(
3340
C_QUOTE -> colorScheme.string
3441
C_TILDE, C_TILDE_AT -> colorScheme.operators
3542
C_AT -> colorScheme.operators
36-
// C_HAT, C_SHARP_HAT -> colorScheme.metadata
37-
// C_SHARP, C_SHARP_COMMENT, C_SHARP_EQ, C_SHARP_NS -> pack(ClojureColors.READER_MACRO)
38-
// C_SHARP_QMARK, C_SHARP_QMARK_AT, C_SHARP_QUOTE -> pack(ClojureColors.READER_MACRO)
43+
// C_HAT, C_SHARP_HAT -> colorScheme.metadata
44+
// C_SHARP, C_SHARP_COMMENT, C_SHARP_EQ, C_SHARP_NS -> pack(ClojureColors.READER_MACRO)
45+
// C_SHARP_QMARK, C_SHARP_QMARK_AT, C_SHARP_QUOTE -> pack(ClojureColors.READER_MACRO)
3946
C_PAREN1, C_PAREN2 -> colorScheme.parentheses
4047
C_BRACE1, C_BRACE2 -> colorScheme.braces
4148
C_BRACKET1, C_BRACKET2 -> colorScheme.brackets
4249
else -> null
4350
}
4451

45-
override fun annotate(element: PsiElement, document: AnnotationHolder<TextAttributes>, colorScheme: ColorScheme<TextAttributes>) {
46-
// TODO
52+
/**
53+
* @param element PsiElement
54+
* @param document AnnotationHolder<TextAttributes>
55+
* @param colorScheme ColorScheme<TextAttributes>
56+
*/
57+
override fun annotate(
58+
element: PsiElement,
59+
document: AnnotationHolder<TextAttributes>,
60+
colorScheme: ColorScheme<TextAttributes>) {
61+
val callable = element is CSForm && element.parentForm.let {
62+
it is CList && it.firstForm == element && it.iterate(CReaderMacro::class).isEmpty
63+
}
64+
if (callable) document.highlight(element.valueRange, colorScheme.keywords)
65+
when (element) {
66+
is CMetadata -> {
67+
element.firstForm.let {
68+
/// if (it is CSymbol) document.highlight(it, null)
69+
// TODO metadata
70+
}
71+
}
72+
}
73+
if (element is CForm && element.iterate(CReaderMacro::class)
74+
.find { it.firstChild.elementType == ClojureTypes.C_SHARP_COMMENT } != null)
75+
document.highlight(element, colorScheme.docComments)
4776
}
4877
}

src/org/intellij/clojure/devkt/lang/clojure-parser.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.com.intellij.lang.parser.GeneratedParserUtilBase
2727
import org.jetbrains.kotlin.com.intellij.lexer.FlexAdapter
2828
import org.jetbrains.kotlin.com.intellij.openapi.project.Project
2929
import org.jetbrains.kotlin.com.intellij.psi.FileViewProvider
30-
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement
3130
import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
3231
import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet
3332

@@ -82,26 +81,20 @@ class ClojureParserUtil {
8281

8382
@JvmStatic
8483
fun nospace(b: PsiBuilder, l: Int): Boolean {
85-
if (space(b, l)) {
86-
b.mark().apply { b.tokenType; error("no <whitespace> allowed") }
87-
.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER)
88-
}
84+
if (space(b, l)) b.mark().apply { b.tokenType; error("no <whitespace> allowed") }
85+
.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER)
8986
return true
9087
}
9188

92-
@JvmStatic
93-
fun space(b: PsiBuilder, l: Int): Boolean {
94-
return b.rawLookup(0).wsOrComment() || b.rawLookup(-1).wsOrComment()
95-
}
96-
9789
private val RECOVER_SET = TokenSet.orSet(
9890
ClojureTokens.SHARPS, ClojureTokens.MACROS, ClojureTokens.PAREN_ALIKE, ClojureTokens.LITERALS,
9991
TokenSet.create(C_DOT, C_DOTDASH))
10092

10193
@JvmStatic
102-
fun formRecover(b: PsiBuilder, l: Int): Boolean {
103-
return !RECOVER_SET.contains(b.tokenType)
104-
}
94+
fun space(b: PsiBuilder, l: Int) = b.rawLookup(0).wsOrComment() or b.rawLookup(-1).wsOrComment()
95+
96+
@JvmStatic
97+
fun formRecover(b: PsiBuilder, l: Int) = b.tokenType !in RECOVER_SET
10598

10699
@JvmStatic
107100
fun rootFormRecover(b: PsiBuilder, l: Int): Boolean {

0 commit comments

Comments
 (0)