Added simple custom navigation bar.

This commit is contained in:
Chris Hodges 2022-10-27 13:31:34 +02:00
parent 64b7042208
commit f87bc7fea9
4 changed files with 92 additions and 5 deletions

View File

@ -1,7 +1,7 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '1.8.0'
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
id 'org.jetbrains.intellij' version '1.9.0'
id 'org.jetbrains.kotlin.jvm' version '1.7.20'
id 'jacoco'
id 'com.github.kt3k.coveralls' version '2.12.0'
}
@ -43,19 +43,19 @@ compileTestKotlin {
}
intellij {
setVersion("2022.2") // LATEST-EAP-SNAPSHOT
setVersion("2022.2.3") // LATEST-EAP-SNAPSHOT
setUpdateSinceUntilBuild(false)
// setPlugins(["com.intellij.java"])
}
runPluginVerifier {
ideVersions = ["IC-203.6682.168", "IC-222.3345.118", // 2020.3 - 2022.2
ideVersions = ["IC-203.6682.168", "IC-222.4345.14", // 2020.3 - 2022.2.3
"CL-203.8084.11", // 2020.3
"CL-211.7628.27", // 2021.1
"CL-212.5712.21", // 2021.2
"CL-213.7172.20", // 2021.3.4
"CL-221.5080.224", // 2022.1
"CL-222.3345.126"] // 2022.2
"CL-222.3345.126"] // 2022.2.4
downloadDir = System.getProperty("user.home") + "/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/verifier"
}
@ -65,6 +65,7 @@ patchPluginXml {
<ul>
<li>New: Added semantic highlighting. Currently available for data and address registers and local labels.
<li>Bugfix: addq/subq for address register stated it would affect the condition codes, which it in fact doesn't.
<li>New: Added simple custom navigation bar.
</ul>
<p>Full changelog available at <a href="https://github.com/chrisly42/mc68000-asm-plugin#changelog">Github project site</a>.</p>
""")

View File

@ -0,0 +1,75 @@
package de.platon42.intellij.plugins.m68k.navigation
import com.intellij.ide.navigationToolbar.AbstractNavBarModelExtension
import com.intellij.ide.ui.UISettings
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.project.IndexNotReadyException
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import de.platon42.intellij.plugins.m68k.M68kIcons
import de.platon42.intellij.plugins.m68k.MC68000Language
import de.platon42.intellij.plugins.m68k.psi.*
import de.platon42.intellij.plugins.m68k.psi.utils.M68kPsiWalkUtil.findStatementForElement
import org.jetbrains.annotations.Nullable
import javax.swing.Icon
class M68kStructureAwareNavbar : AbstractNavBarModelExtension() {
override fun getLeafElement(dataContext: DataContext): PsiElement? {
if (UISettings.getInstance().showMembersInNavigationBar) {
val psiFile = CommonDataKeys.PSI_FILE.getData(dataContext)
val editor = CommonDataKeys.EDITOR.getData(dataContext)
if (psiFile == null || !psiFile.isValid || editor == null) return null
val psiElement = psiFile.findElementAt(editor.caretModel.offset)
if (isAcceptableLanguage(psiElement)) {
try {
var statement = findStatementForElement(psiElement!!) ?: return null
do {
if (statement.localLabel != null) return statement.localLabel
if (statement.globalLabel != null) return statement.globalLabel
statement = PsiTreeUtil.getPrevSiblingOfType(statement, M68kStatement::class.java) ?: return null
} while (true)
} catch (ignored: IndexNotReadyException) {
}
}
}
return null
}
private fun isAcceptableLanguage(psiElement: @Nullable PsiElement?) = psiElement?.language == MC68000Language.INSTANCE
override fun getPresentableText(obj: Any?): String? {
return when (obj) {
is M68kFile -> obj.name
is M68kGlobalLabel -> obj.name
is M68kLocalLabel -> obj.name
is M68kSymbolDefinition -> obj.name
is M68kMacroDefinition -> obj.macroNameDefinition.text
else -> null
}
}
override fun getParent(psiElement: PsiElement): PsiElement? {
if (!isAcceptableLanguage(psiElement)) return null
var statement = findStatementForElement(psiElement) ?: return null
if (statement.localLabel != null) {
do {
if (statement.globalLabel != null) return statement.globalLabel
statement = PsiTreeUtil.getPrevSiblingOfType(statement, M68kStatement::class.java) ?: return null
} while (true)
}
return psiElement.containingFile
}
override fun getIcon(obj: Any?): Icon? {
return when (obj) {
is M68kFile -> M68kIcons.FILE
is M68kGlobalLabel -> M68kIcons.GLOBAL_LABEL
is M68kLocalLabel -> M68kIcons.LOCAL_LABEL
is M68kSymbolDefinition -> M68kIcons.SYMBOL_DEF
is M68kMacroDefinition -> M68kIcons.MACRO_DEF
else -> null
}
}
}

View File

@ -5,7 +5,9 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.SmartList
import com.intellij.util.containers.addIfNotNull
import de.platon42.intellij.plugins.m68k.psi.M68kFile
import de.platon42.intellij.plugins.m68k.psi.M68kMacroDefinition
import de.platon42.intellij.plugins.m68k.psi.M68kStatement
object M68kPsiWalkUtil {
@ -28,4 +30,12 @@ object M68kPsiWalkUtil {
return comments.reversed()
}
fun findStatementForElement(psiElement: PsiElement): M68kStatement? {
if (psiElement is M68kStatement) return psiElement
if (psiElement.parent is M68kFile) {
return PsiTreeUtil.getPrevSiblingOfType(psiElement, M68kStatement::class.java)
}
return PsiTreeUtil.getParentOfType(psiElement, M68kStatement::class.java);
}
}

View File

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