From fc97fe78ded88a5f8f2b750e5efbca8c244098fe Mon Sep 17 00:00:00 2001 From: Timothy Lusk Date: Mon, 7 Aug 2023 16:32:03 -0400 Subject: [PATCH] Explicitly highlight all the section headers (#18) * 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 --- build.gradle.kts | 2 +- .../rpmspec/RpmSpecHighlightingAnnotator.kt | 27 +++++++++++++++++++ .../rpmspec/psi/RpmSpecMacroElementImpl.kt | 1 - src/main/resources/META-INF/plugin.xml | 6 ++--- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index de3510e..3567766 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,7 +34,7 @@ detekt { } group = "com.carbonblack" -version = "2.1.0" +version = "2.2.0" tasks.compileJava { options.release.set(17) diff --git a/src/main/kotlin/com/carbonblack/intellij/rpmspec/RpmSpecHighlightingAnnotator.kt b/src/main/kotlin/com/carbonblack/intellij/rpmspec/RpmSpecHighlightingAnnotator.kt index b13dbf7..ad6434a 100644 --- a/src/main/kotlin/com/carbonblack/intellij/rpmspec/RpmSpecHighlightingAnnotator.kt +++ b/src/main/kotlin/com/carbonblack/intellij/rpmspec/RpmSpecHighlightingAnnotator.kt @@ -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 diff --git a/src/main/kotlin/com/carbonblack/intellij/rpmspec/psi/RpmSpecMacroElementImpl.kt b/src/main/kotlin/com/carbonblack/intellij/rpmspec/psi/RpmSpecMacroElementImpl.kt index edf2839..ac45e6c 100644 --- a/src/main/kotlin/com/carbonblack/intellij/rpmspec/psi/RpmSpecMacroElementImpl.kt +++ b/src/main/kotlin/com/carbonblack/intellij/rpmspec/psi/RpmSpecMacroElementImpl.kt @@ -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 { diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 963d247..de115c6 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -9,10 +9,10 @@ - Changes in version 2.1.0: + Changes in version 2.2.0:
]]>