Skip to content

Commit

Permalink
Explicitly highlight all the section headers (#18)
Browse files Browse the repository at this point in the history
* Explicitly highlight all the section headers

Due to how language injection works these headers can sometimes become
un-highlighted. This should fix that by highlighting them in the
highlighting annotator and not just the syntax highlighter.

Fixes #17
  • Loading branch information
tlusk authored Aug 7, 2023
1 parent 31d2687 commit fc97fe7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ detekt {
}

group = "com.carbonblack"
version = "2.1.0"
version = "2.2.0"

tasks.compileJava {
options.release.set(17)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ class RpmSpecHighlightingAnnotator : Annotator {
}
}

// Explicitly highlight the section headers; this resolves issues with the shell sections
// causing the headers to be un-highlighted.
when (element) {
is RpmSpecFilesSection,
is RpmSpecPackageSection,
is RpmSpecDescriptionSection,
is RpmSpecChangelogSection,
-> element.node.getChildren(TokenSet.ANY)
.firstOrNull {
it.elementType == RpmSpecTypes.FILES ||
it.elementType == RpmSpecTypes.PACKAGE ||
it.elementType == RpmSpecTypes.CHANGELOG ||
it.elementType == RpmSpecTypes.DESCRIPTION
}?.let {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.textAttributes(RpmSpecSyntaxHighligher.RESERVED)
.range(it.textRange).create()
}
is RpmSpecGenericSection -> element.node.getChildren(TokenSet.ANY).firstOrNull()?.let {
if (element.text.firstOrNull() == '%') {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.textAttributes(RpmSpecSyntaxHighligher.RESERVED)
.range(it.textRange).create()
}
}
}

val colorType = when (element) {
is RpmSpecChangelogItem -> RpmSpecSyntaxHighligher.TEXT
is RpmSpecChangelogEntry -> RpmSpecSyntaxHighligher.TEXT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.intellij.extapi.psi.ASTWrapperPsiElement
import com.intellij.lang.ASTNode
import com.intellij.openapi.util.TextRange
import com.intellij.psi.*
import java.util.*

abstract class RpmSpecMacroElementImpl(node: ASTNode) :
ASTWrapperPsiElement(node), PsiNameIdentifierOwner, RpmSpecMacroElement {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

<change-notes><![CDATA[
<html>
<b>Changes in version 2.1.0:</b>
<b>Changes in version 2.2.0:</b>
<ul>
<li>Build against IntelliJ 2022.3 and Java 17</li>
<li>Allow macros such as %autochangelog within the changelog section</li>
<li>Build against IntelliJ 2023.2</li>
<li>Fix section headers sometimes not being highlighted</li>
</ul><br>
</html>
]]>
Expand Down

0 comments on commit fc97fe7

Please sign in to comment.