Added semantic highlighting.

This commit is contained in:
Chris Hodges 2022-08-16 21:41:46 +02:00
parent 87cca67049
commit b785b716bb
5 changed files with 50 additions and 20 deletions

View File

@ -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.). _MC68000 Assembly Language Plugin_ is plugin for Jetbrains IDEs (CLion, IntelliJ, etc.).

View File

@ -7,7 +7,7 @@ plugins {
} }
group = 'de.platon42' group = 'de.platon42'
version = '0.9' version = '0.10'
sourceCompatibility = "1.8" sourceCompatibility = "1.8"
targetCompatibility = "1.8" targetCompatibility = "1.8"
@ -61,12 +61,9 @@ runPluginVerifier {
patchPluginXml { patchPluginXml {
setChangeNotes(""" setChangeNotes("""
<h4>V0.9 (16-Aug-22)</h4> <h4>V0.10 (undefined)</h4>
<ul> <ul>
<li>Maintenance. Updated all dependencies to the latest versions. <li>New: Added semantic highlighting. Currently available for data and address registers and local labels.
<li>Bugfix: Fixed condition code for asr/lsr/lsl, which is has a different behaviour for V flag than asl.
<li>Bugfix: Fixed 'Unknown op size' exception when uppercase sizes were used.
<li>Bugfix: Refactoring was broken for newer IDE versions, at least for me, this now works again by unknown magic.
</ul> </ul>
<p>Full changelog available at <a href="https://github.com/chrisly42/mc68000-asm-plugin#changelog">Github project site</a>.</p> <p>Full changelog available at <a href="https://github.com/chrisly42/mc68000-asm-plugin#changelog">Github project site</a>.</p>
""") """)

View File

@ -1,11 +1,13 @@
package de.platon42.intellij.plugins.m68k.syntax package de.platon42.intellij.plugins.m68k.syntax
import com.intellij.codeHighlighting.RainbowHighlighter
import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.fileTypes.SyntaxHighlighter import com.intellij.openapi.fileTypes.SyntaxHighlighter
import com.intellij.openapi.options.colors.AttributesDescriptor import com.intellij.openapi.options.colors.AttributesDescriptor
import com.intellij.openapi.options.colors.ColorDescriptor 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.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.AREG
import de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighter.Companion.BAD_CHARACTER import de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighter.Companion.BAD_CHARACTER
import de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighter.Companion.COLON 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 org.jetbrains.annotations.NonNls
import javax.swing.Icon import javax.swing.Icon
class M68kColorSettingsPage : ColorSettingsPage { class M68kColorSettingsPage : RainbowColorSettingsPage {
override fun getLanguage() = MC68000Language.INSTANCE
override fun getIcon(): Icon { override fun getIcon(): Icon {
return FILE return FILE
@ -49,6 +53,8 @@ class M68kColorSettingsPage : ColorSettingsPage {
return """; This is an example assembly language program return """; This is an example assembly language program
PIC_HEIGHT = 256 PIC_HEIGHT = 256
* Semantic highlighting is available for registers and local labels
include "../includes/hardware/custom.i" include "../includes/hardware/custom.i"
BLTHOGON MACRO ; macro definition BLTHOGON MACRO ; macro definition
@ -80,23 +86,21 @@ hello: dc.b 'Hello World!',10,0
""" """
} }
override fun getAdditionalHighlightingTagToDescriptorMap(): Map<String, TextAttributesKey>? { override fun getAdditionalHighlightingTagToDescriptorMap(): Map<String, TextAttributesKey> {
return null return RainbowHighlighter.createRainbowHLM()
} }
override fun getAttributeDescriptors(): Array<AttributesDescriptor> { override fun isRainbowType(type: TextAttributesKey) = RAINBOW_TYPES.contains(type)
return DESCRIPTORS
}
override fun getColorDescriptors(): Array<ColorDescriptor> { override fun getAttributeDescriptors() = DESCRIPTORS
return ColorDescriptor.EMPTY_ARRAY
}
override fun getDisplayName(): String { override fun getColorDescriptors() = ColorDescriptor.EMPTY_ARRAY
return "M68k Assembly"
} override fun getDisplayName() = "M68k Assembly"
companion object { companion object {
private val RAINBOW_TYPES = setOf(AREG, DREG, LOCAL_LABEL)
private val DESCRIPTORS = arrayOf( private val DESCRIPTORS = arrayOf(
AttributesDescriptor("Global labels", GLOBAL_LABEL), AttributesDescriptor("Global labels", GLOBAL_LABEL),
AttributesDescriptor("Local labels", LOCAL_LABEL), AttributesDescriptor("Local labels", LOCAL_LABEL),

View File

@ -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()
}

View File

@ -21,6 +21,7 @@
implementationClass="de.platon42.intellij.plugins.m68k.parser.M68kParserDefinition"/> implementationClass="de.platon42.intellij.plugins.m68k.parser.M68kParserDefinition"/>
<lang.syntaxHighlighterFactory language="MC68000" <lang.syntaxHighlighterFactory language="MC68000"
implementationClass="de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighterFactory"/> implementationClass="de.platon42.intellij.plugins.m68k.syntax.M68kSyntaxHighlighterFactory"/>
<highlightVisitor implementation="de.platon42.intellij.plugins.m68k.syntax.M68kRainbowVisitor"/>
<colorSettingsPage implementation="de.platon42.intellij.plugins.m68k.syntax.M68kColorSettingsPage"/> <colorSettingsPage implementation="de.platon42.intellij.plugins.m68k.syntax.M68kColorSettingsPage"/>
<completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.asm.M68kMnemonicCompletionContributor"/> <completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.asm.M68kMnemonicCompletionContributor"/>
<completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.refs.M68kGlobalLabelSymbolCompletionContributor"/> <completion.contributor language="MC68000" implementationClass="de.platon42.intellij.plugins.m68k.refs.M68kGlobalLabelSymbolCompletionContributor"/>