From b785b716bb3ff1eba5201defb86748708c6b67da Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Tue, 16 Aug 2022 21:41:46 +0200 Subject: [PATCH] Added semantic highlighting. --- README.md | 2 +- build.gradle | 9 ++---- .../m68k/syntax/M68kColorSettingsPage.kt | 30 +++++++++++-------- .../plugins/m68k/syntax/M68kRainbowVisitor.kt | 28 +++++++++++++++++ src/main/resources/META-INF/plugin.xml | 1 + 5 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kRainbowVisitor.kt diff --git a/README.md b/README.md index 2a59157..9e022b5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MC68000 Assembly Language Plugin [![Build Status](https://app.travis-ci.com/chrisly42/mc68000-asm-plugin.svg?branch=master)](https://app.travis-ci.com/chrisly42/mc68000-asm-plugin) +# MC68000 Assembly Language Plugin [![Build Status](https://app.travis-ci.com/chrisly42/mc68000-asm-plugin.svg?branch=master)](https://app.travis-ci.com/chrisly42/mc68000-asm-plugin) [![Coverage Status](https://coveralls.io/repos/github/chrisly42/mc68000-asm-plugin/badge.svg?branch=main)](https://coveralls.io/github/chrisly42/mc68000-asm-plugin?branch=main) _MC68000 Assembly Language Plugin_ is plugin for Jetbrains IDEs (CLion, IntelliJ, etc.). diff --git a/build.gradle b/build.gradle index 4cf276e..2f96c46 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'de.platon42' -version = '0.9' +version = '0.10' sourceCompatibility = "1.8" targetCompatibility = "1.8" @@ -61,12 +61,9 @@ runPluginVerifier { patchPluginXml { setChangeNotes(""" -

V0.9 (16-Aug-22)

+

V0.10 (undefined)

Full changelog available at Github project site.

""") diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kColorSettingsPage.kt b/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kColorSettingsPage.kt index bad29c6..573bdfc 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kColorSettingsPage.kt +++ b/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kColorSettingsPage.kt @@ -1,11 +1,13 @@ package de.platon42.intellij.plugins.m68k.syntax +import com.intellij.codeHighlighting.RainbowHighlighter import com.intellij.openapi.editor.colors.TextAttributesKey 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 com.intellij.openapi.options.colors.RainbowColorSettingsPage import de.platon42.intellij.plugins.m68k.M68kIcons.FILE +import de.platon42.intellij.plugins.m68k.MC68000Language import de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighter.Companion.AREG import de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighter.Companion.BAD_CHARACTER import de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighter.Companion.COLON @@ -34,7 +36,9 @@ import de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighter.Companion. import org.jetbrains.annotations.NonNls import javax.swing.Icon -class M68kColorSettingsPage : ColorSettingsPage { +class M68kColorSettingsPage : RainbowColorSettingsPage { + + override fun getLanguage() = MC68000Language.INSTANCE override fun getIcon(): Icon { return FILE @@ -49,6 +53,8 @@ class M68kColorSettingsPage : ColorSettingsPage { return """; This is an example assembly language program PIC_HEIGHT = 256 +* Semantic highlighting is available for registers and local labels + include "../includes/hardware/custom.i" BLTHOGON MACRO ; macro definition @@ -80,23 +86,21 @@ hello: dc.b 'Hello World!',10,0 """ } - override fun getAdditionalHighlightingTagToDescriptorMap(): Map? { - return null + override fun getAdditionalHighlightingTagToDescriptorMap(): Map { + return RainbowHighlighter.createRainbowHLM() } - override fun getAttributeDescriptors(): Array { - return DESCRIPTORS - } + override fun isRainbowType(type: TextAttributesKey) = RAINBOW_TYPES.contains(type) - override fun getColorDescriptors(): Array { - return ColorDescriptor.EMPTY_ARRAY - } + override fun getAttributeDescriptors() = DESCRIPTORS - override fun getDisplayName(): String { - return "M68k Assembly" - } + override fun getColorDescriptors() = ColorDescriptor.EMPTY_ARRAY + + override fun getDisplayName() = "M68k Assembly" companion object { + private val RAINBOW_TYPES = setOf(AREG, DREG, LOCAL_LABEL) + private val DESCRIPTORS = arrayOf( AttributesDescriptor("Global labels", GLOBAL_LABEL), AttributesDescriptor("Local labels", LOCAL_LABEL), diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kRainbowVisitor.kt b/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kRainbowVisitor.kt new file mode 100644 index 0000000..7817f0d --- /dev/null +++ b/src/main/java/de/platon42/intellij/plugins/m68k/syntax/M68kRainbowVisitor.kt @@ -0,0 +1,28 @@ +package de.platon42.intellij.plugins.m68k.syntax + +import com.intellij.codeInsight.daemon.RainbowVisitor +import com.intellij.codeInsight.daemon.impl.HighlightVisitor +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import de.platon42.intellij.plugins.m68k.psi.M68kAddressRegister +import de.platon42.intellij.plugins.m68k.psi.M68kDataRegister +import de.platon42.intellij.plugins.m68k.psi.M68kFile +import de.platon42.intellij.plugins.m68k.psi.M68kLocalLabel + +class M68kRainbowVisitor : RainbowVisitor() { + + override fun suitableForFile(file: PsiFile): Boolean = file is M68kFile + + override fun visit(element: PsiElement) { + when (element) { + is M68kAddressRegister -> addInfo(getInfo(element.containingFile, element, element.text, M68kSyntaxHighlighter.AREG)) + is M68kDataRegister -> addInfo(getInfo(element.containingFile, element, element.text, M68kSyntaxHighlighter.DREG)) +// is M68kGlobalLabel -> addInfo(getInfo(element.containingFile, element, element.text, M68kSyntaxHighlighter.GLOBAL_LABEL)) + is M68kLocalLabel -> addInfo(getInfo(element.containingFile, element, element.text, M68kSyntaxHighlighter.LOCAL_LABEL)) +// is M68kMacroCall -> addInfo(getInfo(element.containingFile, element.firstChild, element.macroName, M68kSyntaxHighlighter.MACRO_CALL)) + } + } + + override fun clone(): HighlightVisitor = M68kRainbowVisitor() + +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index c147df6..3accb3f 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -21,6 +21,7 @@ implementationClass="de.platon42.intellij.plugins.m68k.parser.M68kParserDefinition"/> +